forked from Inve1951/BetterDiscordStuff
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtoggleYourStuff.plugin.js
More file actions
221 lines (204 loc) · 9.82 KB
/
toggleYourStuff.plugin.js
File metadata and controls
221 lines (204 loc) · 9.82 KB
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
//META{"name":"toggleYourStuff"}*//;
var toggleYourStuff;
toggleYourStuff = (function() {
var getSettings, listener, settings;
class toggleYourStuff {
getName() {
return "Toggle-Your-Stuff";
}
getDescription() {
return "Toggle your plugins and themes using hotkeys.";
}
getVersion() {
return "1.1.1";
}
getAuthor() {
return "square";
}
start() {
getSettings();
return document.body.addEventListener("keydown", listener, true);
}
stop() {
return document.body.removeEventListener("keydown", listener, true);
}
load() {}
getSettingsPanel() {
var alt, ctrl, headerstyle, hotkey, keycode, plugin, ref, ref1, settingsPanel, shift, theme, x;
getSettings();
headerstyle = "text-transform:" + ((function() {
switch (0 | 4 * Math.random()) {
case 0:
return "none";
case 1:
return "capitalize";
case 2:
return "uppercase";
case 3:
return "lowercase";
}
})()) + ";filter:drop-shadow(0 0 30px rgb(" + ((function() {
var j, results;
results = [];
for (x = j = 0; j < 3; x = ++j) {
results.push(0 | 256 * Math.random());
}
return results;
})()).join(",") + "));";
settingsPanel = "<div id=\"tys_settings\">\n <style>\n #tys_settings :not(input):not(button) {\n color: #b0b6b9;\n }\n #tys_settings div {\n margin-top: 10px !important;\n }\n #tys_settings span:first-of-type {\n font-size: 2em;\n text-decoration: none;\n margin-top: -30px;\n }\n #tys_settings span {\n display: block;\n width: 90%;\n margin: 0 auto;\n text-align: center;\n text-decoration: underline;\n line-height: 5em;\n }\n #tys_settings h2 {\n font-size: 1.1em;\n font-weight: bold;\n text-decoration: underline;\n }\n #tys_settings [id] > :-webkit-any(input, label) {\n margin-top: 3px;\n }\n #tys_settings input:not([value=\"\"]) {\n background: rgb(32,196,64);\n }\n #tys_settings > div {\n margin-bottom: 20px;\n }\n </style>";
settingsPanel += `<span style=\"${headerstyle}\">tOgGLe-yOuR-sTufF</span>`;
settingsPanel += `<label><input name=\"cancelDefault\" type=\"checkbox\" onchange=\"toggleYourStuff.updateSettings()\"${(settings.cancelDefault ? " checked" : "")}>Cancel default. Prevents any actions which use the same hotkey. (don't kill your ctrl+comma)</label><br><br>`;
settingsPanel += `<label><input name=\"dontSave\" type=\"checkbox\" onchange=\"toggleYourStuff.updateSettings()\"${(settings.dontSave ? " checked" : "")}>Don't have BD save enabled-state after toggling. This is wonky.</label><br><br>`;
settingsPanel += "<span>Numpad doesn't work with Shift key.</span>" + "<div id=\"tys-plugin-hotkeys\"><h2>Plugins:</h2>";
for (plugin in bdplugins) {
({hotkey, ctrl, shift, alt, keycode} = (ref = settings.plugins[plugin]) != null ? ref : {
hotkey: "",
ctrl: false,
shift: false,
alt: false,
keycode: ""
});
settingsPanel += `<div id=\"tys-${plugin}\">${plugin}<br>\n <input name=\"hotkey\" type=\"text\" placeholder=\"Hotkey\" onkeydown=\"if('Shift'!==event.key && 'Control'!==event.key && 'Alt'!==event.key){this.value = event.code; this.parentNode.children[5].value = event.keyCode; toggleYourStuff.updateSettings();} event.preventDefault(); event.stopImmediatePropagation(); return false;\" value=\"${hotkey}\"></input>\n <label><input name=\"ctrl\" type=\"checkbox\" onchange=\"toggleYourStuff.updateSettings()\"${(ctrl ? " checked" : "")}>Ctrl</label>\n <label><input name=\"shift\" type=\"checkbox\" onchange=\"toggleYourStuff.updateSettings()\"${(shift ? " checked" : "")}>Shift</label>\n <label><input name=\"alt\" type=\"checkbox\" onchange=\"toggleYourStuff.updateSettings()\"${(alt ? " checked" : "")}>Alt</label>\n <input name=\"keycode\" type=\"hidden\" value=\"${keycode}\">\n <button type=\"button\" onclick=\"this.parentNode.children[1].value = ''; toggleYourStuff.updateSettings()\">Clear</button>\n</div>`;
}
settingsPanel += "</div>" + "<div id=\"tys-theme-hotkeys\"><h2>Themes:</h2>";
for (theme in bdthemes) {
({hotkey, ctrl, shift, alt, keycode} = (ref1 = settings.themes[theme]) != null ? ref1 : {
hotkey: "",
ctrl: false,
shift: false,
alt: false,
keycode: ""
});
settingsPanel += `<div id=\"tys-${theme}\">${theme}<br>\n <input name=\"hotkey\" type=\"text\" placeholder=\"Hotkey\" onkeydown=\"if('Shift'!==event.key && 'Control'!==event.key && 'Alt'!==event.key){this.value = event.code; this.parentNode.children[5].value = event.keyCode; toggleYourStuff.updateSettings();} event.preventDefault(); event.stopImmediatePropagation(); return false;\" value=\"${hotkey}\"></input>\n <label><input name=\"ctrl\" type=\"checkbox\" onchange=\"toggleYourStuff.updateSettings()\"${(ctrl ? " checked" : "")}>Ctrl</label>\n <label><input name=\"shift\" type=\"checkbox\" onchange=\"toggleYourStuff.updateSettings()\"${(shift ? " checked" : "")}>Shift</label>\n <label><input name=\"alt\" type=\"checkbox\" onchange=\"toggleYourStuff.updateSettings()\"${(alt ? " checked" : "")}>Alt</label>\n <input name=\"keycode\" type=\"hidden\" value=\"${keycode}\">\n <button type=\"button\" onclick=\"this.parentNode.children[1].value = ''; toggleYourStuff.updateSettings()\">Clear</button>\n</div>`;
}
return settingsPanel += "</div>" + "</div>";
}
static updateSettings() {
var alt, ctrl, hotkey, html, i, id, j, keycode, l, len, len1, plugin, ref, ref1, shift, theme;
html = document.getElementById("tys_settings");
settings = {
plugins: {},
themes: {}
};
ref = html.querySelector("#tys-plugin-hotkeys").children;
for (i = j = 0, len = ref.length; j < len; i = ++j) {
plugin = ref[i];
if (!(i)) {
continue;
}
id = plugin.id.slice(4);
hotkey = plugin.querySelector("input[name=\"hotkey\"]").value;
if ("" === hotkey) {
delete settings.plugins[id];
continue;
}
ctrl = plugin.querySelector("input[name=\"ctrl\"]").checked;
shift = plugin.querySelector("input[name=\"shift\"]").checked;
alt = plugin.querySelector("input[name=\"alt\"]").checked;
keycode = 0 | plugin.querySelector("input[name=\"keycode\"]").value;
settings.plugins[id] = {hotkey, ctrl, shift, alt, keycode};
}
ref1 = html.querySelector("#tys-theme-hotkeys").children;
for (i = l = 0, len1 = ref1.length; l < len1; i = ++l) {
theme = ref1[i];
if (!(i)) {
continue;
}
id = theme.id.slice(4);
hotkey = theme.querySelector("input[name=\"hotkey\"]").value;
if ("" === hotkey) {
delete settings.plugins[id];
continue;
}
ctrl = theme.querySelector("input[name=\"ctrl\"]").checked;
shift = theme.querySelector("input[name=\"shift\"]").checked;
alt = theme.querySelector("input[name=\"alt\"]").checked;
keycode = 0 | theme.querySelector("input[name=\"keycode\"]").value;
settings.themes[id] = {hotkey, ctrl, shift, alt, keycode};
}
settings.cancelDefault = html.querySelector("input[name=\"cancelDefault\"]").checked;
settings.dontSave = html.querySelector("input[name=\"dontSave\"]").checked;
settings._note = "The plugin uses the keycodes for detecting a match. The hotkeys are for display in settings only.";
return bdPluginStorage.set("toggleYourStuff", "settings", settings);
}
};
listener = function(ev) {
var alt, css, ctrl, enabled, evalt, evctrl, evkeycode, evshift, handledP, handledT, k, keycode, n, name, plugin, ref, ref1, ref2, shift;
evkeycode = ev.keyCode;
evctrl = ev.ctrlKey;
evshift = ev.shiftKey;
evalt = ev.altKey;
handledP = handledT = false;
ref = settings.plugins;
for (k in ref) {
({keycode, ctrl, shift, alt} = ref[k]);
if (!((bdplugins[k] != null) && keycode === evkeycode && ctrl === evctrl && shift === evshift && evalt === alt)) {
continue;
}
({plugin} = bdplugins[k]);
if (enabled = pluginCookie[k]) {
try {
plugin.stop();
} catch (error) {}
} else {
try {
plugin.start();
} catch (error) {}
}
pluginCookie[k] = !enabled;
handledP = true;
}
ref1 = settings.themes;
for (k in ref1) {
({keycode, ctrl, shift, alt} = ref1[k]);
if (!((bdthemes[k] != null) && keycode === evkeycode && ctrl === evctrl && shift === evshift && evalt === alt)) {
continue;
}
({name, css} = bdthemes[k]);
if (enabled = themeCookie[k]) {
if ((ref2 = document.getElementById(`${k}`)) != null) {
ref2.remove();
}
} else {
n = document.createElement("style");
n.id = name;
n.innerHTML = unescape(css);
document.head.appendChild(n);
}
themeCookie[k] = !enabled;
handledT = true;
}
if (!settings.dontSave) {
if (handledP) {
pluginModule.savePluginData();
}
if (handledT) {
themeModule.saveThemeData();
}
}
if ((handledP || handledT) && settings.cancelDefault) {
ev.preventDefault();
ev.stopImmediatePropagation();
return false;
}
};
settings = {};
getSettings = function() {
var k, ref, ref1, v;
settings = (ref = bdPluginStorage.get("toggleYourStuff", "settings")) != null ? ref : {};
ref1 = {
cancelDefault: false,
dontSave: false,
plugins: {},
themes: {}
};
for (k in ref1) {
v = ref1[k];
if (settings[k] == null) {
settings[k] = v;
}
}
};
return toggleYourStuff;
})();
window.toggleYourStuff = toggleYourStuff;