-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexec-code.js
102 lines (93 loc) · 2.73 KB
/
exec-code.js
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
//executes code from a url (useful so I don't have to constantly add things)
//some code from a notepad bookmarklet (can't find source)
if (confirm("direct code?")) {
function directCode() {
var parentID = 'a3q_parent1';
var dID = 'a3q_code';
var buttonID = 'a3q_close_button1';
var saveThrottleSpeed = 100;
var lastSave = Date.now();
var waitCallback;
function a3q_Save(force) {
force = force || false;
clearTimeout(waitCallback);
if (force || Date.now() - lastSave >= saveThrottleSpeed) {
lastSave = Date.now();
localStorage.setItem('note_code', a3q_GetContents());
} else {
waitCallback = setTimeout(function() {
a3q_Save();
}, saveThrottleSpeed - Date.now());
}
};
function a3q_Load() {
return localStorage.getItem('note_code') || '';
};
function a3q_GetContents() {
return document.getElementById(dID).innerHTML;
};
function a3q_Unload() {
var code = a3q_GetContents();
a3q_Save(true);
c.removeEventListener('onclick', c.onclick);
c.parentNode.removeChild(c);
d.removeEventListener('onkeyup', a3q_Save);
d.parentNode.removeChild(d);
while (code.replace("</div>", "<div>") != code) {
code = code.replace("</div>", "<div>");}
while (code.replace("<div>", "\n") != code) {
code = code.replace("<div>", "\n");}
while (code.replace("<br>", "\n") != code) {
code = code.replace("<br>", "\n");}
while (code.replace(" ", "\n") != code) {
code = code.replace(" ", "\n");}
eval(code);
};
var d = document.getElementById(dID);
var c = document.getElementById(buttonID);
if (d) {
a3q_Unload();
} else {
var d = document.createElement('textarea');
d.id = dID;
d.innerHTML = a3q_Load();
d.style.backgroundColor = '#333';
d.style.color = '#ccc';
d.style.border = '1px solid #ccc';
d.style.position = 'fixed';
d.style.width = '50%';
d.style.height = '50%';
d.style.right = '2%';
d.style.bottom = '2%';
d.style.padding = '2px';
d.style.zIndex = 10000;
d.contentEditable = true;
document.body.appendChild(d);
d.focus();
var lastRun = Date.now();
d.onkeyup = a3q_Save;
var c = document.createElement('button');
c.style.position = 'fixed';
c.id = buttonID;
c.style.zIndex = 10000;
c.style.bottom = '2%';
c.style.right = '2%';
c.innerHTML = 'Run';
c.style.backgroundColor = '#333';
c.style.color = '#ccc';
c.onclick = function() {
a3q_Unload();
};
document.body.appendChild(c);
}
}
directCode();
} else if (confirm("open from URL?")) {
toget = prompt("URL to get code from?");
fetch(toget).then(function(response) {
response.text().then(function(text) {
txt = text;
eval(txt);
})
})
}