This commit is contained in:
Mirco Wittrien 2019-04-16 10:34:07 +02:00
parent 829620251d
commit 0427261358
2 changed files with 13 additions and 12 deletions

View File

@ -604,7 +604,7 @@ class PluginRepo {
BDFDB.removeEles("iframe.discordSandbox",".pluginrepo-loadingicon");
var settings = BDFDB.loadAllData(this, "settings");
var getPluginInfo, createFrame, runInFrame;
var frame, framerunning = false, framequeue = [], outdated = 0, newentries = 0, i = 0;
var frame, framekey = Math.round(Math.random()*10000000000000000), framerunning = false, framequeue = [], outdated = 0, newentries = 0, i = 0;
var tags = ["getName", "getVersion", "getAuthor", "getDescription"];
var seps = ["\"", "\'", "\`"];
var newentriesdata = BDFDB.loadAllData(this, "newentriesdata"), ownlist = BDFDB.loadData("ownlist", this, "ownlist") || [];
@ -763,10 +763,10 @@ class PluginRepo {
callback();
},600000);
frame.messageReceived = e => {
if (typeof e.data === "object" && e.data.origin == "DiscordPreview") {
if (typeof e.data === "object" && e.data.origin == "DiscordPreview" && e.data.framekey == framekey) {
switch (e.data.reason) {
case "OnLoad":
frame.contentWindow.postMessage({origin:"PluginRepo",reason:"OnLoad"},"*");
frame.contentWindow.postMessage({origin:"PluginRepo",reason:"OnLoad",framekey},"*");
callback();
break;
}
@ -799,7 +799,7 @@ class PluginRepo {
runInFrame();
};
var evalResultReceived = e => {
if (typeof e.data === "object" && e.data.origin == "DiscordPreview") {
if (typeof e.data === "object" && e.data.origin == "DiscordPreview" && e.data.framekey == framekey) {
switch (e.data.reason) {
case "EvalResult":
window.removeEventListener("message", evalResultReceived);
@ -809,7 +809,7 @@ class PluginRepo {
}
};
window.addEventListener("message", evalResultReceived);
frame.contentWindow.postMessage({origin:"PluginRepo",reason:"Eval",jsstring:`
frame.contentWindow.postMessage({origin:"PluginRepo",reason:"Eval",framekey,jsstring:`
try {
${body}
var p = new ${name}();

View File

@ -484,9 +484,9 @@ class ThemeRepo {
var avatar = BDFDB.getUserAvatar();
var nativecss = document.querySelector("head link[rel='stylesheet'][integrity]");
nativecss = nativecss && nativecss.href ? nativecss.href : null;
frame.contentWindow.postMessage({origin:"ThemeRepo",reason:"OnLoad",username,id,discriminator,avatar,nativecss},"*");
frame.contentWindow.postMessage({origin:"ThemeRepo",reason:"DarkLight",checked:darklightinput.checked,light:BDFDB.disCN.themelight,dark:BDFDB.disCN.themedark},"*");
frame.contentWindow.postMessage({origin:"ThemeRepo",reason:"Normalize",checked:normalizeinput.checked},"*");
frame.contentWindow.postMessage({origin:"ThemeRepo",reason:"OnLoad",framekey,username,id,discriminator,avatar,nativecss},"*");
frame.contentWindow.postMessage({origin:"ThemeRepo",reason:"DarkLight",framekey,checked:darklightinput.checked,light:BDFDB.disCN.themelight,dark:BDFDB.disCN.themedark},"*");
frame.contentWindow.postMessage({origin:"ThemeRepo",reason:"Normalize",framekey,checked:normalizeinput.checked},"*");
break;
case "KeyUp":
keyPressed(e.data);
@ -499,6 +499,7 @@ class ThemeRepo {
window.addEventListener("message", messageReceived);
var frame = BDFDB.htmlToElement(this.frameMarkup);
var framekey = Math.round(Math.random()*10000000000000000);
var themeRepoModal = BDFDB.htmlToElement(this.themeRepoModalMarkup);
var hiddenSettings = BDFDB.loadAllData(this, "hidden");
var darklightinput = themeRepoModal.querySelector("#input-darklight");
@ -527,17 +528,17 @@ class ThemeRepo {
}
darklightinput.addEventListener("change", e => {
frame.contentWindow.postMessage({origin:"ThemeRepo",reason:"DarkLight",checked:darklightinput.checked,light:BDFDB.disCN.themelight,dark:BDFDB.disCN.themedark},"*");
frame.contentWindow.postMessage({origin:"ThemeRepo",reason:"DarkLight",framekey,checked:darklightinput.checked,light:BDFDB.disCN.themelight,dark:BDFDB.disCN.themedark},"*");
});
normalizeinput.addEventListener("change", e => {
frame.contentWindow.postMessage({origin:"ThemeRepo",reason:"Normalize",checked:normalizeinput.checked},"*");
frame.contentWindow.postMessage({origin:"ThemeRepo",reason:"Normalize",framekey,checked:normalizeinput.checked},"*");
});
customcssinput.addEventListener("change", e => {
var customCSS = document.querySelector("style#customcss");
if (customCSS && customCSS.innerText.length > 0) frame.contentWindow.postMessage({origin:"ThemeRepo",reason:"CustomCSS",checked:customcssinput.checked,css:customCSS.innerText},"*");
if (customCSS && customCSS.innerText.length > 0) frame.contentWindow.postMessage({origin:"ThemeRepo",reason:"CustomCSS",framekey,checked:customcssinput.checked,css:customCSS.innerText},"*");
});
themefixerinput.addEventListener("change", e => {
frame.contentWindow.postMessage({origin:"ThemeRepo",reason:"ThemeFixer",checked:themefixerinput.checked,css:this.themeFixerCSS},"*");
frame.contentWindow.postMessage({origin:"ThemeRepo",reason:"ThemeFixer",framekey,checked:themefixerinput.checked,css:this.themeFixerCSS},"*");
});
themeRepoModal.querySelector("#download-themefixer").addEventListener("click", e => {
this.createThemeFile("ThemeFixer.theme.css", `//META{"name":"ThemeFixer","description":"ThemeFixerCSS for transparent themes","author":"DevilBro","version":"1.0.1"}*//\n\n` + this.themeFixerCSS);