-
Notifications
You must be signed in to change notification settings - Fork 357
/
CustomizableAvatarDPI.plugin.js
118 lines (82 loc) · 3.79 KB
/
CustomizableAvatarDPI.plugin.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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
//META{"name":"CustomizableAvatarDPI","website":"https://github.com/Metalloriff/BetterDiscordPlugins/blob/master/README.md","source":"https://github.com/Metalloriff/BetterDiscordPlugins/blob/master/CustomizableAvatarDPI.plugin.js"}*//
class CustomizableAvatarDPI {
getName() { return "Customizable Avatar DPI"; }
getDescription() { return "Allows you to change the DPI of user avatars, to reduce bluriness with themes that increase the size of them."; }
getVersion() { return "1.0.6"; }
getAuthor() { return "Metalloriff"; }
getChanges() {
return {
"1.0.6":
`
Just temporary fix until Metalloriff hopefully rewrites this plugin aroung christmas time
`
}
}
load() {}
start() {
let libLoadedEvent = () => {
try{ this.onLibLoaded(); }
catch(err) { console.error(this.getName(), "fatal error, plugin could not be started!", err); try { this.stop(); } catch(err) { console.error(this.getName() + ".stop()", err); } }
};
let lib = document.getElementById("NeatoBurritoLibrary");
if(!lib) {
lib = document.createElement("script");
lib.id = "NeatoBurritoLibrary";
lib.type = "text/javascript";
lib.src = "https://rawgit.com/Metalloriff/BetterDiscordPlugins/master/Lib/NeatoBurritoLibrary.js";
document.head.appendChild(lib);
}
this.forceLoadTimeout = setTimeout(libLoadedEvent, 30000);
if(typeof window.NeatoLib !== "undefined") libLoadedEvent();
else lib.addEventListener("load", libLoadedEvent);
}
saveSettings() {
NeatoLib.Settings.save(this);
}
getSettingsPanel() {
setTimeout(() => {
NeatoLib.Settings.pushElement(NeatoLib.Settings.Elements.createNewTextField("Popout avatar size", this.settings.popoutAvatarSize, e => {
this.settings.popoutAvatarSize = e.target.value;
this.saveSettings();
}), this.getName(), { tooltip : "User popouts" });
NeatoLib.Settings.pushElement(NeatoLib.Settings.Elements.createNewTextField("Other avatar size", this.settings.otherAvatarSize, e => {
this.settings.otherAvatarSize = e.target.value;
this.saveSettings();
}), this.getName(), { tooltip : "Everything else" });
NeatoLib.Settings.pushChangelogElements(this);
}, 0);
return NeatoLib.Settings.Elements.pluginNameLabel(this.getName());
}
onLibLoaded(){
NeatoLib.Updates.check(this);
this.settings = NeatoLib.Settings.load(this, {
popoutAvatarSize : 1024,
otherAvatarSize : 256,
displayUpdateNotes : true
});
this.appObserver = new MutationObserver(m => {
for(let i = 0; i < m.length; i++) {
if(!m[i].addedNodes.length) continue;
for(let a = 0; a < m[i].addedNodes.length; a++) {
let added = m[i].addedNodes[a];
if(!(added instanceof Element)) continue;
let imgs = added.getElementsByClassName(NeatoLib.getClass(["avatar", "mask", "pointer", "status"], "avatar"));
for(let img of imgs)
if(img) img.src = img.src.split("?size=")[0] + "?size=" + this.settings.otherAvatarSize;
let popouts = added.classList.contains(NeatoLib.getClass(["body", "footer", "popout", "title"], "popout")) ? [added] : added.getElementsByClassName(NeatoLib.getClass(["body", "footer", "popout", "title"], "popout"));
for(let popout of popouts){
let imgs = popout.getElementsByClassName(NeatoLib.getClass(["avatar", "mask", "pointer", "status"], "avatar"));
for(let img of imgs)
if(img) img.src = img.src.split("?size=")[0] + "?size=" + this.settings.popoutAvatarSize;
}
}
}
});
this.appObserver.observe(document.getElementById("app-mount"), { childList : true, subtree : true });
NeatoLib.Events.onPluginLoaded(this);
NeatoLib.Changelog.compareVersions(this.getName(), this.getChanges());
}
stop() {
this.appObserver.disconnect();
}
}