This repository was archived by the owner on Dec 7, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 345
/
Copy pathde4js_helper.user.js
88 lines (75 loc) · 2.3 KB
/
de4js_helper.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
---
---
// ==UserScript==
// @name de4js helper
// @namespace https://baivong.github.io/de4js/
// @description Enable Unreadable option in de4js
// @version {{ site.version }}
// @icon https://i.imgur.com/CJ5MfxV.png
// @author {{ site.author }}
// @license {{ site.license }}
// @match {{ site.url }}/de4js/
// @include http://127.0.0.1:4000/de4js/
// @include http://localhost:4000/de4js/
// @require https://greasemonkey.github.io/gm4-polyfill/gm4-polyfill.js?v=a834d46
// @noframes
// @connect jsnice.org
// @supportURL https://github.com/lelinhtinh/de4js/issues
// @run-at document-idle
// @grant GM_xmlhttpRequest
// @grant GM.xmlHttpRequest
// ==/UserScript==
'use strict';
const nicify = document.getElementById('nicify'),
label = nicify.nextSibling.nextSibling.textContent,
none = document.getElementById('none'),
input = document.getElementById('input'),
output = document.getElementById('readable'),
view = document.getElementById('view');
function jsnice() {
if (!isOnine()) return;
const txt = view.textContent.trim() || input.value.trim();
if (!txt) return;
view.classList.add('waiting');
GM.xmlHttpRequest({
method: 'POST',
url: 'http://jsnice.org/beautify?pretty=0&rename=1&types=0&packers=0&transpile=0&suggest=0',
responseType: 'json',
data: txt,
onload: (response) => {
let source;
if (response.response && response.response.js) {
source = response.response.js;
}
nicify.checked = false;
none.checked = true;
if (!source) {
view.textContent = 'Unknown error';
} else {
output.value = source;
output.onchange();
}
},
onerror: (err) => {
console.error(err); // eslint-disable-line no-console
},
});
}
function isOnine() {
nicify.disabled = !navigator.onLine;
return navigator.onLine;
}
nicify.disabled = false;
nicify.nextSibling.nextSibling.textContent = label;
input.addEventListener('input', () => {
if (nicify.checked) jsnice();
});
nicify.addEventListener('click', () => {
if (nicify.checked) jsnice();
});
nicify.addEventListener('onchange', () => {
if (nicify.checked) jsnice();
});
window.addEventListener('online', isOnine);
window.addEventListener('offline', isOnine);
isOnine();