-
Notifications
You must be signed in to change notification settings - Fork 0
/
replmark.html
52 lines (52 loc) · 1.71 KB
/
replmark.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<!doctype html>
<html><head><title>REPLmark</title></head><body>
<button onclick="replize()">Try Me</button>
<p>Bookmark the following:</p>
<script>
function replize() {
window.REPLmark = window.REPLmark || (function (eval) {
var d = document,
c = d.createElement.bind(d),
overlay = c('div'),
hist = c('div'),
form = c('form'),
input = c('input'),
clear = c('span'),
close = c('span');
overlay.style.cssText = 'display:none;width:100vw;height:100vh;position:fixed;top:0;left:0;z-index:2147483647;opacity:0.8;background-color:#fff';
clear.textContent = '\u232b';
close.textContent = '\u2303';
form.onsubmit = function(e) {
e.preventDefault();
e.stopPropagation();
var x = c('div');
try {
x.textContent = eval(input.value);
} catch(err) {
x.textContent = err;
x.style.backgroundColor = '#fdd';
}
hist.appendChild(x);
input.value = '';
};
clear.onclick = function() {
for(var x;x = hist.firstChild;hist.removeChild(x));
};
close.onclick = function() {
overlay.style.display = 'none';
};
overlay.appendChild(hist);
form.appendChild(input); form.appendChild(clear); form.appendChild(close);
overlay.appendChild(form);
d.body.appendChild(overlay);
return function() { overlay.style.display = 'block' }
})(function(s) { return eval(s) });
window.REPLmark()
}
var marklet = document.createElement('pre');
var text = replize.toString();
text = text.slice(text.indexOf('{') + 1, text.lastIndexOf('}')).trim().replace(/\s+/m, ' ').replace(/ (?!\w)/,'').replace(/(\W) /,function($0,$1){return $1});
marklet.textContent = 'javascript:' + encodeURIComponent(text);
document.body.appendChild(marklet);
</script>
</body></html>