Remove class normalizer
This commit is contained in:
parent
a223806060
commit
b739fc6f38
|
@ -21,10 +21,6 @@
|
|||
"name": "Verbindung zum Sprachchat trennen",
|
||||
"note": "Trennt beim Schließen von Discord die Verbindung zum Sprachchat."
|
||||
},
|
||||
"classNormalizer": {
|
||||
"name": "Normalisierte klassen",
|
||||
"note": "Fügt stetige Klassen zu Elementen hinzu (z.B. .da-channels zu .channels-Ie2l6A)"
|
||||
},
|
||||
"showToasts": {
|
||||
"name": "Benachrichtigungen anzeigen",
|
||||
"note": "Zeigt kleine Benachrichtigung für wichtige informationen an."
|
||||
|
|
|
@ -21,10 +21,6 @@
|
|||
"name": "Voice Disconnect",
|
||||
"note": "Disconnect from voice server when closing Discord"
|
||||
},
|
||||
"classNormalizer": {
|
||||
"name": "Normalize Classes",
|
||||
"note": "Adds stable classes to elements to help themes. (e.g. adds .da-channels to .channels-Ie2l6A)"
|
||||
},
|
||||
"showToasts": {
|
||||
"name": "Show Toasts",
|
||||
"note": "Shows a small notification for important information"
|
||||
|
@ -43,6 +39,14 @@
|
|||
"coloredText": {
|
||||
"name": "Colored Text",
|
||||
"note": "Make text colour the same as role color"
|
||||
},
|
||||
"hideGIFButton": {
|
||||
"name": "Hide GIF Button",
|
||||
"note": "Hides the GIF picker button in the textarea"
|
||||
},
|
||||
"hideGiftButton": {
|
||||
"name": "Hide Gift Button",
|
||||
"note": "Hides the Nitro Gift button in the textarea"
|
||||
}
|
||||
},
|
||||
"addons": {
|
||||
|
@ -51,10 +55,6 @@
|
|||
"name": "Show Addon Errors",
|
||||
"note": "Shows a modal with plugin/theme errors"
|
||||
},
|
||||
"autoScroll": {
|
||||
"name": "Scroll To Settings",
|
||||
"note": "Auto-scrolls to a plugin's settings when the button is clicked (only if out of view)"
|
||||
},
|
||||
"autoReload": {
|
||||
"name": "Automatic Loading",
|
||||
"note": "Automatically loads, reloads, and unloads plugins and themes"
|
||||
|
@ -102,13 +102,13 @@
|
|||
"name": "Debugger Hotkey",
|
||||
"note": "Allows activating debugger when pressing F8"
|
||||
},
|
||||
"copySelector": {
|
||||
"name": "Copy Selector",
|
||||
"note": "Adds a \"Copy Selector\" option to context menus when developer mode is active"
|
||||
},
|
||||
"reactDevTools": {
|
||||
"name": "React Developer Tools",
|
||||
"note": "Injects your local installation of React Developer Tools into Discord"
|
||||
},
|
||||
"inspectElement": {
|
||||
"name": "Inspect Element Hotkey",
|
||||
"note": "Enables the inspect element hotkey (ctrl + shift + c) that is common in most browsers"
|
||||
}
|
||||
},
|
||||
"window": {
|
||||
|
@ -150,6 +150,10 @@
|
|||
"animateOnHover": {
|
||||
"name": "Animate On Hover",
|
||||
"note": "Only animate the emote modifiers on hover"
|
||||
},
|
||||
"mediaKeys": {
|
||||
"name": "Disable Media Keys",
|
||||
"note": "Prevents Discord from hijacking your media keys after playing a video."
|
||||
}
|
||||
},
|
||||
"categories": {
|
||||
|
@ -175,6 +179,7 @@
|
|||
},
|
||||
"Addons": {
|
||||
"title": "{{name}} v{{version}} by {{author}}",
|
||||
"byline": "by {{author}}",
|
||||
"openFolder": "Open {{type}} Folder",
|
||||
"reload": "Reload",
|
||||
"addonSettings": "Settings",
|
||||
|
@ -199,6 +204,7 @@
|
|||
"couldNotDisable": "{{name}} could not be disabled.",
|
||||
"couldNotStart": "{{name}} could not be started.",
|
||||
"couldNotStop": "{{name}} could not be stopped.",
|
||||
"settingsError": "Could not open settings for {{name}}",
|
||||
"methodError": "{{method}} could not be fired.",
|
||||
"unknownAuthor": "Unknown Author",
|
||||
"noDescription": "Description not provided.",
|
||||
|
@ -208,7 +214,9 @@
|
|||
"missingNameData": "META missing name data.",
|
||||
"metaNotFound": "META was not found.",
|
||||
"compileError": "Could not be compiled.",
|
||||
"wasUnloaded": "{{name}} was unloaded."
|
||||
"wasUnloaded": "{{name}} was unloaded.",
|
||||
"blankSlateHeader": "You don't have any {{type}}s!",
|
||||
"blankSlateMessage": "Grab some from [this website]({{link}}) and add them to your {{type}} folder."
|
||||
},
|
||||
"CustomCSS": {
|
||||
"confirmationText": "You have unsaved changes to your Custom CSS. Closing this window will lose all those changes.",
|
||||
|
@ -219,9 +227,6 @@
|
|||
"settings": "Editor Settings",
|
||||
"editorTitle": "Custom CSS Editor"
|
||||
},
|
||||
"Developer": {
|
||||
"copySelector": "Copy Selector"
|
||||
},
|
||||
"Emotes": {
|
||||
"loading": "Loading emotes in the background do not reload.",
|
||||
"loaded": "All emotes successfully loaded.",
|
||||
|
@ -235,11 +240,16 @@
|
|||
"joined": "Joined",
|
||||
"loading": "Loading",
|
||||
"loadMore": "Load More",
|
||||
"notConnected": "Not connected to DiscordServers.com!",
|
||||
"notConnected": "Not Connected",
|
||||
"connectionRequired": "You must connect your account in order to join servers.",
|
||||
"connectionError": "Connection Error",
|
||||
"connectionErrorMessage": "There was an error connecting to DiscordServers.com, it's possible their website/api is down. Please try again later.",
|
||||
"pagination": "Page {{page}} of {{count}}",
|
||||
"search": "Search",
|
||||
"connect": "Connect",
|
||||
"reconnect": "Reconnect",
|
||||
"categories": "Categories",
|
||||
"keywords": "Keywords",
|
||||
"connection": "Connected as: {{username}}#{{discriminator}}",
|
||||
"results": "Showing {{start}}-{{end}} of {{total}} results in {{category}}",
|
||||
"query": "for {{query}}"
|
||||
|
@ -247,7 +257,9 @@
|
|||
"Modals": {
|
||||
"confirmAction": "Are You Sure?",
|
||||
"okay": "Okay",
|
||||
"done": "Done",
|
||||
"cancel": "Cancel",
|
||||
"nevermind": "Nevermind",
|
||||
"close": "Close",
|
||||
"name": "Name",
|
||||
"message": "Message",
|
||||
|
@ -256,7 +268,8 @@
|
|||
"restartRequired": "Restart Required",
|
||||
"restartNow": "Restart Now",
|
||||
"restartLater": "Restart Later",
|
||||
"additionalInfo": "Additional Info"
|
||||
"additionalInfo": "Additional Info",
|
||||
"restartPrompt": "In order to take effect, Discord needs to be restarted. Do you want to restart now?"
|
||||
},
|
||||
"ReactDevTools": {
|
||||
"notFound": "Extension Not Found",
|
||||
|
|
|
@ -21,10 +21,6 @@
|
|||
"name": "ボイスチャンネル自動切断",
|
||||
"note": "Discordを終了する際、自動的にボイスチャンネルから切断します。"
|
||||
},
|
||||
"classNormalizer": {
|
||||
"name": "クラス標準化",
|
||||
"note": "値が変動しないCSSクラスを追加します。"
|
||||
},
|
||||
"showToasts": {
|
||||
"name": "トースト表示",
|
||||
"note": "重要な情報を小さな通知として表示します。"
|
||||
|
|
|
@ -21,10 +21,6 @@
|
|||
"name": "Lämna Röst",
|
||||
"note": "Lämna röstsamtal när Discord stängs ner"
|
||||
},
|
||||
"classNormalizer": {
|
||||
"name": "Normalisera Klasser",
|
||||
"note": "Lägger till statiska klasser för att underlätta teman (ex. lägger till .da-channels på .channels-Ie2l6A)"
|
||||
},
|
||||
"showToasts": {
|
||||
"name": "Visa Toasts",
|
||||
"note": "Visar en liten notification för viktig information"
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
export {default as CustomCSS} from "./customcss";
|
||||
export {default as WindowPrefs} from "./windowprefs";
|
||||
|
||||
export {default as ClassNormalizer} from "./general/classnormalizer";
|
||||
export {default as PublicServers} from "./general/publicservers";
|
||||
export {default as VoiceDisconnect} from "./general/voicedisconnect";
|
||||
export {default as MediaKeys} from "./general/mediakeys";
|
||||
|
|
|
@ -1,140 +0,0 @@
|
|||
import Builtin from "../../structs/builtin";
|
||||
import {WebpackModules} from "modules";
|
||||
|
||||
const normalizedPrefix = "da";
|
||||
const randClass = new RegExp(`^(?!${normalizedPrefix}-)((?:[A-Za-z]|[0-9]|-)+)-(?:[A-Za-z]|[0-9]|-|_){6}$`);
|
||||
|
||||
export default new class ClassNormalizer extends Builtin {
|
||||
get id() {return "classNormalizer";}
|
||||
get category() {return "general";}
|
||||
get name() {return "ClassNormalizer";}
|
||||
|
||||
enabled() {
|
||||
if (this.hasPatched) return;
|
||||
this.patchClassModules(WebpackModules.getModules(this.moduleFilter.bind(this)));
|
||||
this.normalizeElement(document.querySelector("#app-mount"));
|
||||
this.hasPatched = true;
|
||||
this.patchDOMMethods();
|
||||
}
|
||||
|
||||
disabled() {
|
||||
if (!this.hasPatched) return;
|
||||
this.unpatchClassModules(WebpackModules.getModules(this.moduleFilter.bind(this)));
|
||||
this.revertElement(document.querySelector("#app-mount"));
|
||||
this.hasPatched = false;
|
||||
}
|
||||
|
||||
patchClassModules(modules) {
|
||||
for (const module of modules) {
|
||||
this.patchClassModule(normalizedPrefix, module);
|
||||
}
|
||||
}
|
||||
|
||||
unpatchClassModules(modules) {
|
||||
for (const module of modules) {
|
||||
this.unpatchClassModule(normalizedPrefix, module);
|
||||
}
|
||||
}
|
||||
|
||||
shouldIgnore(value) {
|
||||
if (!isNaN(value)) return true;
|
||||
if (value.endsWith("px") || value.endsWith("ch") || value.endsWith("em") || value.endsWith("ms")) return true;
|
||||
if (value.startsWith("layerContainer-")) return true;
|
||||
if (value.startsWith("#") && (value.length == 7 || value.length == 4)) return true;
|
||||
if (value.includes("calc(") || value.includes("rgba")) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
moduleFilter(module) {
|
||||
if (typeof module !== "object" || Array.isArray(module)) return false;
|
||||
if (module.__esModule) return false;
|
||||
if (!Object.keys(module).length) return false;
|
||||
for (const baseClassName in module) {
|
||||
const value = module[baseClassName];
|
||||
if (typeof value !== "string") return false;
|
||||
if (this.shouldIgnore(value)) continue;
|
||||
if (value.split("-").length === 1) return false;
|
||||
if (!randClass.test(value.split(" ")[0])) return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
patchClassModule(componentName, classNames) {
|
||||
for (const baseClassName in classNames) {
|
||||
const value = classNames[baseClassName];
|
||||
if (this.shouldIgnore(value)) continue;
|
||||
const classList = value.split(" ");
|
||||
for (const normalClass of classList) {
|
||||
const match = normalClass.match(randClass);
|
||||
if (!match || !match.length || match.length < 2) continue; // Shouldn't ever happen since they passed the moduleFilter, but you never know
|
||||
const camelCase = match[1].split("-").map((s, i) => i ? s[0].toUpperCase() + s.slice(1) : s).join("");
|
||||
classNames[baseClassName] += ` ${componentName}-${camelCase}`;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
unpatchClassModule(componentName, classNames) {
|
||||
for (const baseClassName in classNames) {
|
||||
const value = classNames[baseClassName];
|
||||
if (this.shouldIgnore(value)) continue;
|
||||
let newString = "";
|
||||
const classList = value.split(" ");
|
||||
for (const normalClass of classList) {
|
||||
if (normalClass.startsWith(`${componentName}-`)) continue;
|
||||
newString += ` ${normalClass}`;
|
||||
}
|
||||
classNames[baseClassName] = newString.trim();
|
||||
}
|
||||
}
|
||||
|
||||
normalizeElement(element) {
|
||||
if (!(element instanceof Element)) return;
|
||||
const classes = element.classList;
|
||||
for (let c = 0, clen = classes.length; c < clen; c++) {
|
||||
if (!randClass.test(classes[c])) continue;
|
||||
const match = classes[c].match(randClass)[1];
|
||||
const newClass = match.split("-").map((s, i) => i ? s[0].toUpperCase() + s.slice(1) : s).join("");
|
||||
element.classList.add(`${normalizedPrefix}-${newClass}`);
|
||||
}
|
||||
for (const child of element.children) this.normalizeElement(child);
|
||||
}
|
||||
|
||||
revertElement(element) {
|
||||
if (!(element instanceof Element)) return;
|
||||
if (element.children && element.children.length) this.revertElement(element.children[0]);
|
||||
if (element.nextElementSibling) this.revertElement(element.nextElementSibling);
|
||||
const classes = element.classList;
|
||||
const toRemove = [];
|
||||
for (let c = 0; c < classes.length; c++) {
|
||||
if (classes[c].startsWith(`${normalizedPrefix}-`)) toRemove.push(classes[c]);
|
||||
}
|
||||
element.classList.remove(...toRemove);
|
||||
}
|
||||
|
||||
patchDOMMethods() {
|
||||
const contains = DOMTokenList.prototype.contains;
|
||||
DOMTokenList.prototype.contains = function(token) {
|
||||
// const tokens = token.split(" ");
|
||||
return Reflect.apply(contains, this, [token.split(" ")[0]]);
|
||||
// return tokens.every(t => contains.call(this, t));
|
||||
};
|
||||
|
||||
const add = DOMTokenList.prototype.add;
|
||||
DOMTokenList.prototype.add = function(...tokens) {
|
||||
for (let t = 0; t < tokens.length; t++) {
|
||||
tokens[t] = tokens[t].split(" ")[0];
|
||||
}
|
||||
return Reflect.apply(add, this, tokens);
|
||||
};
|
||||
|
||||
const remove = DOMTokenList.prototype.remove;
|
||||
DOMTokenList.prototype.remove = function(...tokens) {
|
||||
for (let t = 0; t < tokens.length; t++) {
|
||||
tokens[t] = tokens[t].split(" ")[0];
|
||||
}
|
||||
return Reflect.apply(remove, this, tokens);
|
||||
};
|
||||
}
|
||||
|
||||
};
|
|
@ -7,7 +7,6 @@ export default [
|
|||
{type: "switch", id: "emotes", value: true},
|
||||
{type: "switch", id: "publicServers", value: true},
|
||||
{type: "switch", id: "voiceDisconnect", value: false},
|
||||
{type: "switch", id: "classNormalizer", value: false},
|
||||
{type: "switch", id: "showToasts", value: true},
|
||||
{type: "switch", id: "mediaKeys", value: false}
|
||||
]
|
||||
|
|
|
@ -21,10 +21,6 @@ export default {
|
|||
name: "Voice Disconnect",
|
||||
note: "Disconnect from voice server when closing Discord"
|
||||
},
|
||||
classNormalizer: {
|
||||
name: "Normalize Classes",
|
||||
note: "Adds stable classes to elements to help themes. (e.g. adds .da-channels to .channels-Ie2l6A)"
|
||||
},
|
||||
showToasts: {
|
||||
name: "Show Toasts",
|
||||
note: "Shows a small notification for important information"
|
||||
|
|
|
@ -68,7 +68,7 @@ export default new class DataStore {
|
|||
if (!channelData || !channelData.settings) continue;
|
||||
const oldSettings = channelData.settings;
|
||||
const newSettings = {
|
||||
general: {publicServers: oldSettings["bda-gs-1"], voiceDisconnect: oldSettings["bda-dc-0"], classNormalizer: oldSettings["fork-ps-4"], showToasts: oldSettings["fork-ps-2"]},
|
||||
general: {publicServers: oldSettings["bda-gs-1"], voiceDisconnect: oldSettings["bda-dc-0"], showToasts: oldSettings["fork-ps-2"]},
|
||||
appearance: {twentyFourHour: oldSettings["bda-gs-6"], minimalMode: oldSettings["bda-gs-2"], coloredText: oldSettings["bda-gs-7"]},
|
||||
addons: {addonErrors: oldSettings["fork-ps-1"], autoReload: oldSettings["fork-ps-5"]},
|
||||
developer: {debuggerHotkey: oldSettings["bda-gs-8"], reactDevTools: oldSettings.reactDevTools}
|
||||
|
@ -86,7 +86,7 @@ export default new class DataStore {
|
|||
setChannelData(channel, "misc", {favoriteEmotes}); // favorite emotes
|
||||
fs.writeFileSync(path.resolve(this.baseFolder, channel, "custom.css"), customcss); // customcss
|
||||
}
|
||||
|
||||
|
||||
this.initialize(); // Reinitialize data store with the converted data
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue