-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathuserscript.user.js
67 lines (56 loc) · 1.99 KB
/
userscript.user.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
// ==UserScript==
// @name Krunker Editor+
// @version 4.13.2
// @author Jakob#8686
// @description Custom features for the Krunker Map Editor
// @match *://*.krunker.io/editor.html*
// @run-at document-start
// @grant GM_setValue
// @grant GM_getValue
// @iconURL https://i.imgur.com/WdYKPAE.png
// @icon64URL https://i.imgur.com/ZNkUU6K.png
// @downloadURL /~https://github.com/j4k0xb/Krunker-Editor-Plus/raw/master/userscript.user.js
// @updateURL /~https://github.com/j4k0xb/Krunker-Editor-Plus/raw/master/userscript.meta.js
// ==/UserScript==
const bundle = loadBundle();
let script;
document.addEventListener('DOMContentLoaded', async () => {
eval(await bundle); // eslint-disable-line
dispatchEvent(
new CustomEvent('editor-plus-init', { detail: script.textContent })
);
});
const observer = new MutationObserver(mutations => {
for (const { addedNodes } of mutations) {
for (const node of addedNodes) {
if (
node.nodeType === Node.TEXT_NODE &&
node.textContent.includes('Krunker.io')
) {
observer.disconnect();
script = node.parentElement;
script.type = 'text/blocked';
}
}
}
});
observer.observe(document, { childList: true, subtree: true });
async function loadBundle() {
const commitURL =
'https://api.github.com/repos/j4k0xb/Krunker-Editor-Plus/commits?per_page=1';
const lastModified = GM_getValue('lastModified') || 0;
const commit = (
await (await fetch(commitURL, { cache: 'no-store' })).json()
)[0].commit;
const commitDate = Date.parse(commit.committer.date);
if (commitDate !== lastModified) return updateBundle(commitDate);
return GM_getValue('bundle');
}
async function updateBundle(date) {
const bundleURL =
'https://raw.githubusercontent.com/j4k0xb/Krunker-Editor-Plus/master/bundle.js';
const bundle = await (await fetch(bundleURL, { cache: 'no-store' })).text();
GM_setValue('bundle', bundle);
GM_setValue('lastModified', date);
return bundle;
}