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,15 +1,16 @@
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":
@ -78,11 +79,11 @@ window.onmessage = function (e) {
break; 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) {
@ -90,11 +91,11 @@ window.getString = function (obj) {
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; return string;
}; };
window.webpackJsonp = function () { window.webpackJsonp = function () {
return {default:{m:{},c:{}}}; return {default:{m:{},c:{}}};
}; };
window.WebModulesFind = function (filter) { window.WebModulesFind = function (filter) {
const id = "PluginRepo-WebModules"; 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]]]); 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.m[id];
@ -106,8 +107,8 @@ window.WebModulesFind = function (filter) {
if (module && filter(module)) return module; if (module && filter(module)) return module;
} }
} }
}; };
window.WebModulesFindByProperties = function (properties) { window.WebModulesFindByProperties = function (properties) {
properties = Array.isArray(properties) ? properties : Array.from(arguments); properties = Array.isArray(properties) ? properties : Array.from(arguments);
var module = WebModulesFind(module => properties.every(prop => module[prop] !== undefined)); var module = WebModulesFind(module => properties.every(prop => module[prop] !== undefined));
if (!module) { if (!module) {
@ -115,16 +116,16 @@ window.WebModulesFindByProperties = function (properties) {
for (let property of properties) module[property] = property; for (let property of properties) module[property] = property;
} }
return module; return module;
}; };
window.WebModulesFindByName = function (name) { window.WebModulesFindByName = function (name) {
return WebModulesFind(module => module.displayName === name) || ""; return WebModulesFind(module => module.displayName === name) || "";
}; };
window.disCN = new Proxy({}, { window.disCN = new Proxy({}, {
get: function (list, item) { get: function (list, item) {
return window.getDiscordClass(item).replace('#', ''); return window.getDiscordClass(item).replace('#', '');
} }
}); });
window.getDiscordClass = function (item) { window.getDiscordClass = function (item) {
var classname = "Preview_undefined"; var classname = "Preview_undefined";
if (window.DiscordClasses === undefined || window.DiscordClassModules === undefined) return classname; if (window.DiscordClasses === undefined || window.DiscordClassModules === undefined) return classname;
else if (window.DiscordClasses[item] === undefined) { else if (window.DiscordClasses[item] === undefined) {
@ -144,19 +145,20 @@ window.getDiscordClass = function (item) {
return classname; return classname;
} }
else return classname = window.DiscordClassModules[window.DiscordClasses[item][0]][window.DiscordClasses[item][1]]; else return classname = window.DiscordClassModules[window.DiscordClasses[item][0]][window.DiscordClasses[item][1]];
}; };
window.BDV2 = {}; window.BDV2 = {};
window.BDV2.react = window.React; window.BDV2.react = window.React;
window.BDV2.reactDom = window.ReactDOM; window.BDV2.reactDom = window.ReactDOM;
window.BDV2.WebpackModules = {}; window.BDV2.WebpackModules = {};
window.BDV2.WebpackModules.find = window.WebModulesFind; window.BDV2.WebpackModules.find = window.WebModulesFind;
window.BDV2.WebpackModules.findByUniqueProperties = window.WebModulesFindByProperties; window.BDV2.WebpackModules.findByUniqueProperties = window.WebModulesFindByProperties;
window.BDV2.WebpackModules.findByDisplayName = window.WebModulesFindByName; window.BDV2.WebpackModules.findByDisplayName = window.WebModulesFindByName;
window.BdApi = {}; window.BdApi = {};
window.BdApi.getData = _ => {return {};}; window.BdApi.getData = _ => {return {};};
window.BdApi.loadData = _ => {return {};}; window.BdApi.loadData = _ => {return {};};
window.BdApi.saveData = _ => {}; window.BdApi.saveData = _ => {};
window.BdApi.React = window.React; window.BdApi.React = window.React;
window.BdApi.ReactDOM = window.ReactDOM; window.BdApi.ReactDOM = window.ReactDOM;
window.BdApi.findModule = window.WebModulesFind; window.BdApi.findModule = window.WebModulesFind;
window.BdApi.findModuleByProps = window.WebModulesFindByProperties; window.BdApi.findModuleByProps = window.WebModulesFindByProperties;
}