This commit is contained in:
Mirco Wittrien 2020-04-10 22:20:09 +02:00
parent efc64b234d
commit f9b5b626d8
3 changed files with 170 additions and 166 deletions

View File

@ -3258,8 +3258,8 @@
catch (err) {template.innerHTML = html.replace(/>[\t\r\n]+<(?!pre)/g, "><");} catch (err) {template.innerHTML = html.replace(/>[\t\r\n]+<(?!pre)/g, "><");}
if (template.content.childNodes.length == 1) return template.content.firstElementChild; if (template.content.childNodes.length == 1) return template.content.firstElementChild;
else { else {
var wrapper = document.createElement("span"); let wrapper = document.createElement("span");
var nodes = Array.from(template.content.childNodes); let nodes = Array.from(template.content.childNodes);
while (nodes.length) wrapper.appendChild(nodes.shift()); while (nodes.length) wrapper.appendChild(nodes.shift());
return wrapper; return wrapper;
} }
@ -3352,29 +3352,31 @@
} }
return 0; return 0;
}; };
BDFDB.DOMUtils.appendWebScript = function (path, container) { BDFDB.DOMUtils.appendWebScript = function (url, container) {
if (!container && !document.head.querySelector("bd-head bd-scripts")) document.head.appendChild(BDFDB.DOMUtils.create(`<bd-head><bd-scripts></bd-scripts></bd-head>`)); if (!container && !document.head.querySelector("bd-head bd-scripts")) document.head.appendChild(BDFDB.DOMUtils.create(`<bd-head><bd-scripts></bd-scripts></bd-head>`));
container = container || document.head.querySelector("bd-head bd-scripts") || document.head; container = container || document.head.querySelector("bd-head bd-scripts") || document.head;
container = Node.prototype.isPrototypeOf(container) ? container : document.head; container = Node.prototype.isPrototypeOf(container) ? container : document.head;
BDFDB.DOMUtils.removeWebScript(path, container); BDFDB.DOMUtils.removeWebScript(url, container);
container.appendChild(BDFDB.DOMUtils.create(`<script src="${path}"></script>`)); let script = document.createElement("script");
script.src = url;
container.appendChild(script);
}; };
BDFDB.DOMUtils.removeWebScript = function (path, container) { BDFDB.DOMUtils.removeWebScript = function (url, container) {
container = container || document.head.querySelector("bd-head bd-scripts") || document.head; container = container || document.head.querySelector("bd-head bd-scripts") || document.head;
container = Node.prototype.isPrototypeOf(container) ? container : document.head; container = Node.prototype.isPrototypeOf(container) ? container : document.head;
BDFDB.DOMUtils.remove(container.querySelectorAll(`script[src="${path}"]`)); BDFDB.DOMUtils.remove(container.querySelectorAll(`script[src="${url}"]`));
}; };
BDFDB.DOMUtils.appendWebStyle = function (path, container) { BDFDB.DOMUtils.appendWebStyle = function (url, container) {
if (!container && !document.head.querySelector("bd-head bd-styles")) document.head.appendChild(BDFDB.DOMUtils.create(`<bd-head><bd-styles></bd-styles></bd-head>`)); if (!container && !document.head.querySelector("bd-head bd-styles")) document.head.appendChild(BDFDB.DOMUtils.create(`<bd-head><bd-styles></bd-styles></bd-head>`));
container = container || document.head.querySelector("bd-head bd-styles") || document.head; container = container || document.head.querySelector("bd-head bd-styles") || document.head;
container = Node.prototype.isPrototypeOf(container) ? container : document.head; container = Node.prototype.isPrototypeOf(container) ? container : document.head;
BDFDB.DOMUtils.removeWebStyle(path, container); BDFDB.DOMUtils.removeWebStyle(url, container);
container.appendChild(BDFDB.DOMUtils.create(`<link type="text/css" rel="Stylesheet" href="${path}"></link>`)); container.appendChild(BDFDB.DOMUtils.create(`<link type="text/css" rel="Stylesheet" href="${url}"></link>`));
}; };
BDFDB.DOMUtils.removeWebStyle = function (path, container) { BDFDB.DOMUtils.removeWebStyle = function (url, container) {
container = container || document.head.querySelector("bd-head bd-styles") || document.head; container = container || document.head.querySelector("bd-head bd-styles") || document.head;
container = Node.prototype.isPrototypeOf(container) ? container : document.head; container = Node.prototype.isPrototypeOf(container) ? container : document.head;
BDFDB.DOMUtils.remove(container.querySelectorAll(`link[href="${path}"]`)); BDFDB.DOMUtils.remove(container.querySelectorAll(`link[href="${url}"]`));
}; };
BDFDB.DOMUtils.appendLocalStyle = function (id, css, container) { BDFDB.DOMUtils.appendLocalStyle = function (id, css, container) {
if (!container && !document.head.querySelector("bd-head bd-styles")) document.head.appendChild(BDFDB.DOMUtils.create(`<bd-head><bd-styles></bd-styles></bd-head>`)); if (!container && !document.head.querySelector("bd-head bd-styles")) document.head.appendChild(BDFDB.DOMUtils.create(`<bd-head><bd-styles></bd-styles></bd-head>`));

File diff suppressed because one or more lines are too long

View File

@ -1,162 +1,164 @@
console.log("this is a test"); console.log("this is a test");
window.global = window; if (!window.BDFDB) {
window.global = window;
window.onload = function () { window.onload = function () {
window.parent.postMessage({origin:"DiscordPreview",reason:"OnLoad"},"*"); window.parent.postMessage({origin:"DiscordPreview",reason:"OnLoad"},"*");
}; };
window.onkeyup = function (e) { window.onkeyup = function (e) {
var which = e.which; let which = e.which;
window.parent.postMessage({origin:"DiscordPreview",reason:"KeyUp",which},"*"); window.parent.postMessage({origin:"DiscordPreview",reason:"KeyUp",which},"*");
}; };
window.onmessage = function (e) { window.onmessage = function (e) {
if (typeof e.data === "object" && (e.data.origin == "PluginRepo" || e.data.origin == "ThemeRepo")) { if (typeof e.data === "object" && (e.data.origin == "PluginRepo" || e.data.origin == "ThemeRepo")) {
switch (e.data.reason) { switch (e.data.reason) {
case "OnLoad": case "OnLoad":
document.body.innerHTML = document.body.innerHTML.replace(/\t|\n|\r/g, ""); document.body.innerHTML = document.body.innerHTML.replace(/\t|\n|\r/g, "");
if (e.data.username) { if (e.data.username) {
document.body.innerHTML = document.body.innerHTML.replace(/REPLACE_USERNAMESMALL/gi, e.data.username.toLowerCase()); document.body.innerHTML = document.body.innerHTML.replace(/REPLACE_USERNAMESMALL/gi, e.data.username.toLowerCase());
document.body.innerHTML = document.body.innerHTML.replace(/REPLACE_USERNAME/gi, e.data.username); document.body.innerHTML = document.body.innerHTML.replace(/REPLACE_USERNAME/gi, e.data.username);
} }
if (e.data.id) { if (e.data.id) {
window.userId = e.data.id; window.userId = e.data.id;
document.body.innerHTML = document.body.innerHTML.replace(/REPLACE_USERID/gi, e.data.id); document.body.innerHTML = document.body.innerHTML.replace(/REPLACE_USERID/gi, e.data.id);
} }
if (e.data.avatar) document.body.innerHTML = document.body.innerHTML.replace(/REPLACE_AVATAR/gi, e.data.avatar.split('"').join('') + "?size="); if (e.data.avatar) document.body.innerHTML = document.body.innerHTML.replace(/REPLACE_AVATAR/gi, e.data.avatar.split('"').join('') + "?size=");
if (e.data.discriminator) document.body.innerHTML = document.body.innerHTML.replace(/REPLACE_DISCRIMINATOR/gi, e.data.discriminator); if (e.data.discriminator) document.body.innerHTML = document.body.innerHTML.replace(/REPLACE_DISCRIMINATOR/gi, e.data.discriminator);
if (e.data.classes) window.DiscordClasses = JSON.parse(e.data.classes); if (e.data.classes) window.DiscordClasses = JSON.parse(e.data.classes);
if (e.data.classmodules) window.DiscordClassModules = JSON.parse(e.data.classmodules); if (e.data.classmodules) window.DiscordClassModules = JSON.parse(e.data.classmodules);
if (window.disCN != undefined && window.DiscordClasses != undefined && window.DiscordClassModules != undefined) { if (window.disCN != undefined && window.DiscordClasses != undefined && window.DiscordClassModules != undefined) {
var oldhtml = document.body.innerHTML.split("REPLACE_CLASS_"); var oldhtml = document.body.innerHTML.split("REPLACE_CLASS_");
var newhtml = oldhtml.shift();
for (let html of oldhtml) {
let reg = /([A-z0-9_]+)(.+)/.exec(html);
newhtml += window.disCN[reg[1]] + reg[2];
}
document.body.innerHTML = newhtml;
}
if (e.data.nativecss) {
var theme = document.createElement("link");
theme.classList.add(e.data.reason);
theme.rel = "stylesheet";
theme.href = e.data.nativecss;
document.head.appendChild(theme);
}
if (e.data.html) document.documentElement.className = e.data.html;
if (e.data.titlebar) document.querySelector(".preview-titlebar").outerHTML = e.data.titlebar;
document.body.firstElementChild.style.removeProperty("display");
document.documentElement.classList.add("mouse-mode");
break;
case "Eval":
window.evalResult = null;
if (e.data.jsstring) window.eval(`(_ => {${e.data.jsstring}})()`);
window.parent.postMessage({origin:"DiscordPreview",reason:"EvalResult",result:window.evalResult},"*");
break;
case "NewTheme":
case "CustomCSS":
case "ThemeFixer":
document.querySelectorAll("style." + e.data.reason).forEach(theme => theme.remove());
if (e.data.checked) {
var theme = document.createElement("style");
theme.classList.add(e.data.reason);
theme.innerText = e.data.css;
document.head.appendChild(theme);
}
break;
case "DarkLight":
if (e.data.checked) document.body.innerHTML = document.body.innerHTML.replace(new RegExp(window.disCN.themedark, "g"), window.disCN.themelight);
else document.body.innerHTML = document.body.innerHTML.replace(new RegExp(window.disCN.themelight, "g"), window.disCN.themedark);
break;
case "Normalize":
var oldhtml = document.body.innerHTML.split('class="');
var newhtml = oldhtml.shift(); var newhtml = oldhtml.shift();
for (let html of oldhtml) { for (let html of oldhtml) {
let reg = /([A-z0-9_]+)(.+)/.exec(html); html = html.split('"');
newhtml += window.disCN[reg[1]] + reg[2]; newhtml += 'class="' + (e.data.checked ? html[0].split(" ").map(n => n.replace(/([A-z0-9]+?)-([A-z0-9_-]{6})/g, "$1-$2 da-$1")).join(" ") : html[0].split(" ").filter(n => n.indexOf("da-") != 0).join(" ")) + '"' + html.slice(1).join('"');
} }
document.body.innerHTML = newhtml; document.body.innerHTML = newhtml;
} break;
if (e.data.nativecss) { }
var theme = document.createElement("link");
theme.classList.add(e.data.reason);
theme.rel = "stylesheet";
theme.href = e.data.nativecss;
document.head.appendChild(theme);
}
if (e.data.html) document.documentElement.className = e.data.html;
if (e.data.titlebar) document.querySelector(".preview-titlebar").outerHTML = e.data.titlebar;
document.body.firstElementChild.style.removeProperty("display");
document.documentElement.classList.add("mouse-mode");
break;
case "Eval":
window.evalResult = null;
if (e.data.jsstring) window.eval(`(_ => {${e.data.jsstring}})()`);
window.parent.postMessage({origin:"DiscordPreview",reason:"EvalResult",result:window.evalResult},"*");
break;
case "NewTheme":
case "CustomCSS":
case "ThemeFixer":
document.querySelectorAll("style." + e.data.reason).forEach(theme => theme.remove());
if (e.data.checked) {
var theme = document.createElement("style");
theme.classList.add(e.data.reason);
theme.innerText = e.data.css;
document.head.appendChild(theme);
}
break;
case "DarkLight":
if (e.data.checked) document.body.innerHTML = document.body.innerHTML.replace(new RegExp(window.disCN.themedark, "g"), window.disCN.themelight);
else document.body.innerHTML = document.body.innerHTML.replace(new RegExp(window.disCN.themelight, "g"), window.disCN.themedark);
break;
case "Normalize":
var oldhtml = document.body.innerHTML.split('class="');
var newhtml = oldhtml.shift();
for (let html of oldhtml) {
html = html.split('"');
newhtml += 'class="' + (e.data.checked ? html[0].split(" ").map(n => n.replace(/([A-z0-9]+?)-([A-z0-9_-]{6})/g, "$1-$2 da-$1")).join(" ") : html[0].split(" ").filter(n => n.indexOf("da-") != 0).join(" ")) + '"' + html.slice(1).join('"');
}
document.body.innerHTML = newhtml;
break;
} }
} };
}; window.require = function () {
window.require = function () { return _ => {};
return _ => {}; };
}; window.getString = function (obj) {
window.getString = function (obj) { var string = "";
var string = ""; if (typeof obj == "string") string = obj;
if (typeof obj == "string") string = obj; else if (obj && obj.props) {
else if (obj && obj.props) { if (typeof obj.props.children == "string") string = obj.props.children;
if (typeof obj.props.children == "string") string = obj.props.children; else if (Array.isArray(obj.props.children)) for (let c of obj.props.children) string += typeof c == "string" ? c : getString(c);
else if (Array.isArray(obj.props.children)) for (let c of obj.props.children) string += typeof c == "string" ? c : getString(c);
}
return string;
};
window.webpackJsonp = function () {
return {default:{m:{},c:{}}};
};
window.WebModulesFind = function (filter) {
const id = "PluginRepo-WebModules";
const req = typeof(window.webpackJsonp) == "function" ? window.webpackJsonp([], {[id]: (module, exports, req) => exports.default = req}, [id]).default : window.webpackJsonp.push([[], {[id]: (module, exports, req) => module.exports = req}, [[id]]]);
delete req.m[id];
delete req.c[id];
for (let m in req.c) {
if (req.c.hasOwnProperty(m)) {
var module = req.c[m].exports;
if (module && module.__esModule && module.default && filter(module.default)) return module.default;
if (module && filter(module)) return module;
} }
} return string;
}; };
window.WebModulesFindByProperties = function (properties) { window.webpackJsonp = function () {
properties = Array.isArray(properties) ? properties : Array.from(arguments); return {default:{m:{},c:{}}};
var module = WebModulesFind(module => properties.every(prop => module[prop] !== undefined)); };
if (!module) { window.WebModulesFind = function (filter) {
module = {}; const id = "PluginRepo-WebModules";
for (let property of properties) module[property] = property; const req = typeof(window.webpackJsonp) == "function" ? window.webpackJsonp([], {[id]: (module, exports, req) => exports.default = req}, [id]).default : window.webpackJsonp.push([[], {[id]: (module, exports, req) => module.exports = req}, [[id]]]);
} delete req.m[id];
return module; delete req.c[id];
}; for (let m in req.c) {
window.WebModulesFindByName = function (name) { if (req.c.hasOwnProperty(m)) {
return WebModulesFind(module => module.displayName === name) || ""; var module = req.c[m].exports;
}; if (module && module.__esModule && module.default && filter(module.default)) return module.default;
window.disCN = new Proxy({}, { if (module && filter(module)) return module;
get: function (list, item) { }
return window.getDiscordClass(item).replace('#', ''); }
} };
}); window.WebModulesFindByProperties = function (properties) {
window.getDiscordClass = function (item) { properties = Array.isArray(properties) ? properties : Array.from(arguments);
var classname = "Preview_undefined"; var module = WebModulesFind(module => properties.every(prop => module[prop] !== undefined));
if (window.DiscordClasses === undefined || window.DiscordClassModules === undefined) return classname; if (!module) {
else if (window.DiscordClasses[item] === undefined) { module = {};
if (window.userId == "278543574059057154") console.warn(`%c[Preview]%c`, 'color:#3a71c1; font-weight:700;', '', item + ' not found in window.DiscordClasses'); for (let property of properties) module[property] = property;
return classname; }
} return module;
else if (!Array.isArray(window.DiscordClasses[item]) || window.DiscordClasses[item].length != 2) { };
if (window.userId == "278543574059057154") console.warn(`%c[Preview]%c`, 'color:#3a71c1; font-weight:700;', '', item + ' is not an Array of Length 2 in window.DiscordClasses'); window.WebModulesFindByName = function (name) {
return classname; return WebModulesFind(module => module.displayName === name) || "";
} };
else if (window.DiscordClassModules[window.DiscordClasses[item][0]] === undefined) { window.disCN = new Proxy({}, {
if (window.userId == "278543574059057154") console.warn(`%c[Preview]%c`, 'color:#3a71c1; font-weight:700;', '', window.DiscordClasses[item][0] + ' not found in DiscordClassModules'); get: function (list, item) {
return classname; return window.getDiscordClass(item).replace('#', '');
} }
else if (window.DiscordClassModules[window.DiscordClasses[item][0]][window.DiscordClasses[item][1]] === undefined) { });
if (window.userId == "278543574059057154") console.warn(`%c[Preview]%c`, 'color:#3a71c1; font-weight:700;', '', window.DiscordClasses[item][1] + ' not found in ' + window.DiscordClasses[item][0] + ' in DiscordClassModules'); window.getDiscordClass = function (item) {
return classname; var classname = "Preview_undefined";
} if (window.DiscordClasses === undefined || window.DiscordClassModules === undefined) return classname;
else return classname = window.DiscordClassModules[window.DiscordClasses[item][0]][window.DiscordClasses[item][1]]; else if (window.DiscordClasses[item] === undefined) {
}; if (window.userId == "278543574059057154") console.warn(`%c[Preview]%c`, 'color:#3a71c1; font-weight:700;', '', item + ' not found in window.DiscordClasses');
window.BDV2 = {}; return classname;
window.BDV2.react = window.React; }
window.BDV2.reactDom = window.ReactDOM; else if (!Array.isArray(window.DiscordClasses[item]) || window.DiscordClasses[item].length != 2) {
window.BDV2.WebpackModules = {}; if (window.userId == "278543574059057154") console.warn(`%c[Preview]%c`, 'color:#3a71c1; font-weight:700;', '', item + ' is not an Array of Length 2 in window.DiscordClasses');
window.BDV2.WebpackModules.find = window.WebModulesFind; return classname;
window.BDV2.WebpackModules.findByUniqueProperties = window.WebModulesFindByProperties; }
window.BDV2.WebpackModules.findByDisplayName = window.WebModulesFindByName; else if (window.DiscordClassModules[window.DiscordClasses[item][0]] === undefined) {
window.BdApi = {}; if (window.userId == "278543574059057154") console.warn(`%c[Preview]%c`, 'color:#3a71c1; font-weight:700;', '', window.DiscordClasses[item][0] + ' not found in DiscordClassModules');
window.BdApi.getData = _ => {return {};}; return classname;
window.BdApi.loadData = _ => {return {};}; }
window.BdApi.saveData = _ => {}; else if (window.DiscordClassModules[window.DiscordClasses[item][0]][window.DiscordClasses[item][1]] === undefined) {
window.BdApi.React = window.React; if (window.userId == "278543574059057154") console.warn(`%c[Preview]%c`, 'color:#3a71c1; font-weight:700;', '', window.DiscordClasses[item][1] + ' not found in ' + window.DiscordClasses[item][0] + ' in DiscordClassModules');
window.BdApi.ReactDOM = window.ReactDOM; return classname;
window.BdApi.findModule = window.WebModulesFind; }
window.BdApi.findModuleByProps = window.WebModulesFindByProperties; else return classname = window.DiscordClassModules[window.DiscordClasses[item][0]][window.DiscordClasses[item][1]];
};
window.BDV2 = {};
window.BDV2.react = window.React;
window.BDV2.reactDom = window.ReactDOM;
window.BDV2.WebpackModules = {};
window.BDV2.WebpackModules.find = window.WebModulesFind;
window.BDV2.WebpackModules.findByUniqueProperties = window.WebModulesFindByProperties;
window.BDV2.WebpackModules.findByDisplayName = window.WebModulesFindByName;
window.BdApi = {};
window.BdApi.getData = _ => {return {};};
window.BdApi.loadData = _ => {return {};};
window.BdApi.saveData = _ => {};
window.BdApi.React = window.React;
window.BdApi.ReactDOM = window.ReactDOM;
window.BdApi.findModule = window.WebModulesFind;
window.BdApi.findModuleByProps = window.WebModulesFindByProperties;
}