|
| 1 | +/* Add an edit in repl link to code blocks */ |
| 2 | + |
| 3 | +function checkForReplLinks() { |
| 4 | + // const replCode = document.querySelectorAll('pre'); |
| 5 | + // [...replCode].forEach(pre => { |
| 6 | + // console.log(pre); |
| 7 | + // const text = encodeURI(pre.innerText); |
| 8 | + // const link = document.createElement('a'); |
| 9 | + // link.title = 'Run this code in the REPL'; |
| 10 | + // link.innerText = 'Run this code in the REPL'; |
| 11 | + // link.href = '/repl/?code=' + text; |
| 12 | + // const paragraph = document.createElement('p'); |
| 13 | + // paragraph.appendChild(link); |
| 14 | + // const wrapper = document.createElement('div'); |
| 15 | + // pre.parentNode.insertBefore(wrapper, pre); |
| 16 | + // wrapper.appendChild(pre); |
| 17 | + // wrapper.appendChild(paragraph); |
| 18 | + // }); |
| 19 | + const replCode = document.querySelectorAll('.repl-code'); |
| 20 | + [...replCode].forEach(code => { |
| 21 | + const codeText = encodeURI(code.innerText); |
| 22 | + const link = document.createElement('a'); |
| 23 | + link.title = 'Run this code in the REPL'; |
| 24 | + link.innerText = 'Run this code in the REPL'; |
| 25 | + link.href = '/repl/?code=' + codeText; |
| 26 | + const paragraph = document.createElement('p'); |
| 27 | + paragraph.appendChild(link); |
| 28 | + code.appendChild(paragraph); |
| 29 | + }); |
| 30 | +} |
| 31 | + |
1 | 32 | window.addEventListener('DOMContentLoaded', event => { |
2 | 33 | if (window.localStorage) { |
3 | 34 | window.topicsCompleted = getTopicsFromLocalStorage(); |
4 | 35 | updateUI(); |
5 | 36 | } |
| 37 | + checkForReplLinks(); |
6 | 38 | }); |
7 | 39 |
|
8 | 40 | function updateUI() { |
|
0 commit comments