Patch DOMTokenList methods to use the correct (not normalised) classes
rauenzi/BetterDiscordApp#159, rauenzi/BetterDiscordApp#161
This commit is contained in:
parent
3eb9105daa
commit
2b0d3eb268
|
@ -12,12 +12,14 @@ import { Module, Reflection } from 'modules';
|
|||
|
||||
const normalizedPrefix = 'da';
|
||||
const randClass = new RegExp(`^(?!${normalizedPrefix}-)((?:[A-Za-z]|[0-9]|-)+)-(?:[A-Za-z]|[0-9]|-|_){6}$`);
|
||||
const normalisedClass = /^(([a-zA-Z0-9]+)-[^\s]{6}) da-([a-zA-Z0-9]+)$/;
|
||||
|
||||
export default class ClassNormaliser extends Module {
|
||||
|
||||
init() {
|
||||
this.patchClassModules(Reflection.module.getModule(this.moduleFilter.bind(this), false));
|
||||
this.normalizeElement(document.querySelector('#app-mount'));
|
||||
this.patchDOMMethods();
|
||||
}
|
||||
|
||||
patchClassModules(modules) {
|
||||
|
@ -26,6 +28,36 @@ export default class ClassNormaliser extends Module {
|
|||
}
|
||||
}
|
||||
|
||||
patchDOMMethods() {
|
||||
const add = DOMTokenList.prototype.add;
|
||||
|
||||
DOMTokenList.prototype.add = function(...tokens) {
|
||||
for (const token of tokens) {
|
||||
let match;
|
||||
if (typeof token === 'string' && (match = token.match(normalisedClass)) && match[2] === match[3]) return add.call(this, match[1]);
|
||||
return add.call(this, token);
|
||||
}
|
||||
};
|
||||
|
||||
const remove = DOMTokenList.prototype.remove;
|
||||
|
||||
DOMTokenList.prototype.remove = function(...tokens) {
|
||||
for (const token of tokens) {
|
||||
let match;
|
||||
if (typeof token === 'string' && (match = token.match(normalisedClass)) && match[2] === match[3]) return remove.call(this, match[1]);
|
||||
return remove.call(this, token);
|
||||
}
|
||||
};
|
||||
|
||||
const contains = DOMTokenList.prototype.contains;
|
||||
|
||||
DOMTokenList.prototype.contains = function(token) {
|
||||
let match;
|
||||
if (typeof token === 'string' && (match = token.match(normalisedClass)) && match[2] === match[3]) return contains.call(this, match[1]);
|
||||
return contains.call(this, token);
|
||||
};
|
||||
}
|
||||
|
||||
shouldIgnore(value) {
|
||||
if (!isNaN(value)) return true;
|
||||
if (value.endsWith('px') || value.endsWith('ch') || value.endsWith('em') || value.endsWith('ms')) return true;
|
||||
|
|
Loading…
Reference in New Issue