-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshow-source.js
16 lines (16 loc) · 919 Bytes
/
show-source.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
/// https://arkenidar.com/web/show-source.js
/*
Add show-source.js for displaying source code from a specified URL
( or current URL if not specified ) .
<script src="show-source.js"></script>
<script src="show-source.js" data-href="MathCalculator.ts"></script>
<script src="show-source.js" data-href="MathCalculator.js"></script>
*/
(function show_source_code() {
var url = document.currentScript.dataset.href; if (!url) url = ""
var text = `<div class="show_source_code"><b><a href="${url}">ORIGIN: ${url}</a></b><pre contenteditable="true" class="show_source"
style=" overflow-y: scroll; border:1px solid black; padding: 1em; " spellcheck="false" translate="no"></pre></div>`
document.currentScript.insertAdjacentHTML("afterend", text)
var code = document.currentScript.nextSibling.firstChild.nextSibling
fetch(url).then(res => res.text()).then(res => code.textContent = res)
})()