diff --git a/Plugins/PluginRepo/PluginRepo.plugin.js b/Plugins/PluginRepo/PluginRepo.plugin.js index 3f57787b67..f903b7a099 100644 --- a/Plugins/PluginRepo/PluginRepo.plugin.js +++ b/Plugins/PluginRepo/PluginRepo.plugin.js @@ -48,7 +48,6 @@ var PluginRepo = (_ => { }; const pluginRepoIcon = ``; - const gitHubIcon = ``; const repoListComponent = class PluginList extends BdApi.React.Component { render() { @@ -70,7 +69,7 @@ var PluginRepo = (_ => { return class PluginRepo { getName () {return "PluginRepo";} - getVersion () {return "1.9.1";} + getVersion () {return "1.9.2";} getAuthor () {return "DevilBro";} @@ -78,7 +77,7 @@ var PluginRepo = (_ => { constructor () { this.changelog = { - "improved":[["New Library Structure & React","Restructured my Library and switched to React rendering instead of DOM manipulation"]] + "fixed":[["Fetching","Fixed an issue with some plugins while fetching"]] }; this.patchedModules = { @@ -515,7 +514,7 @@ var PluginRepo = (_ => { if (giturl) BDFDB.DiscordUtils.openLink(giturl, BDFDB.DataUtils.get(this, "settings", "useChromium")); }, children: BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SvgIcon, { - iconSVG: gitHubIcon + name: BDFDB.LibraryComponents.SvgIcon.Names.GITHUB }) }) }) @@ -559,7 +558,7 @@ var PluginRepo = (_ => { loadPlugins () { BDFDB.DOMUtils.remove("iframe.discordSandbox", ".pluginrepo-loadingicon"); let settings = BDFDB.DataUtils.load(this, "settings"); - let getPluginInfo, createFrame, runInFrame; + let getPluginInfo, extractConfigInfo, createFrame, runInFrame; let frame, framerunning = false, framequeue = [], outdated = 0, newentries = 0, i = 0; let tags = ["getName", "getVersion", "getAuthor", "getDescription"]; let seps = ["\"", "\'", "\`"]; @@ -681,31 +680,26 @@ var PluginRepo = (_ => { } else if (body && body.indexOf("404: Not Found") != 0 && response.statusCode == 200) { let plugin = {}; - let bodycopy = body; + let bodyCopy = body; if (body.length / body.split("\n").length > 1000) { /* code is minified -> add newlines */ - bodycopy = body.replace(/}/g, "}\n"); + bodyCopy = body.replace(/}/g, "}\n"); } - let configreg = /(module\.exports|config)\s*=\s*\{\n*\r*\t*["'`]*info["'`]*\s*:\s*/i.exec(bodycopy); + let bodyWithoutSpecial = bodyCopy.replace(/\n|\r|\t/g, ""); + let configreg = /(module\.exports|config)\s*=\s*\{["'`]*info["'`]*\s*:\s*/i.exec(bodyWithoutSpecial); if (url != "https://raw.githubusercontent.com/mwittrien/BetterDiscordAddons/master/Plugins/PluginRepo/PluginRepo.plugin.js" && configreg) { try { - let config = JSON.parse('{"info":' + bodycopy.substring(configreg.index).split(configreg[0])[1].split("};")[0] + '}'); - plugin.getName = config.info.name.charAt(0).toUpperCase() + config.info.name.slice(1); - plugin.getDescription = config.info.description.charAt(0).toUpperCase() + config.info.description.slice(1); - plugin.getVersion = config.info.version; - plugin.getAuthor = ""; - if (typeof config.info.author == "string") plugin.getAuthor = config.info.author.charAt(0).toUpperCase() + config.info.author.slice(1); - else if (typeof config.info.authors == "string") plugin.getAuthor = config.info.authors.charAt(0).toUpperCase() + config.info.authors.slice(1); - else if (Array.isArray(config.info.authors)) for (let author of config.info.authors) { - plugin.getAuthor += (plugin.getAuthor + (plugin.getAuthor ? ", " : "") + (typeof author == "string" ? author : author.name)); - } + extractConfigInfo(plugin, JSON.parse('{"info":' + bodyWithoutSpecial.substring(configreg.index).split(configreg[0])[1].split("};")[0] + '}')); + } + catch (err) { + try {extractConfigInfo(plugin, JSON.parse(('{"info":' + bodyWithoutSpecial.substring(configreg.index).split(configreg[0])[1].split("};")[0] + '}').replace(/,/g, ',"').replace(/:/g, '":').replace(/{/g, '{"').replace(/""/g, '"').replace(/" /g, ' ').replace(/,"{/g, ',{').replace(/,"\[/g, ',[').replace(/":\/\//g, ':\/\/')));} + catch (err2) {} } - catch (err) {} } else { for (let tag of tags) { - let result = new RegExp(tag + "[\\s|\\t|\\n|\\r|=|>|_|:|function|\(|\)|\{|return]*([\"|\'|\`]).*\\1","gi").exec(bodycopy); - if (!result) result = new RegExp("get " + tag.replace("get", "").toLowerCase() + "[\\s|\\t|\\n|\\r|=|>|_|:|function|\(|\)|\{|return]*([\"|\'|\`]).*\\1","gi").exec(bodycopy); + let result = new RegExp(tag + "[\\s|\\t|\\n|\\r|=|>|_|:|function|\(|\)|\{|return]*([\"|\'|\`]).*\\1","gi").exec(bodyCopy); + if (!result) result = new RegExp("get " + tag.replace("get", "").toLowerCase() + "[\\s|\\t|\\n|\\r|=|>|_|:|function|\(|\)|\{|return]*([\"|\'|\`]).*\\1","gi").exec(bodyCopy); if (result) { let separator = result[1]; result = result[0].replace(new RegExp("\\\\" + separator, "g"), separator).split(separator); @@ -739,7 +733,19 @@ var PluginRepo = (_ => { getPluginInfo(callback); }); - } + }; + + extractConfigInfo = (plugin, config) => { + plugin.getName = BDFDB.LibraryModules.StringUtils.upperCaseFirstChar(config.info.name); + plugin.getDescription = BDFDB.LibraryModules.StringUtils.upperCaseFirstChar(config.info.description); + plugin.getVersion = config.info.version; + plugin.getAuthor = ""; + if (typeof config.info.author == "string") plugin.getAuthor = BDFDB.LibraryModules.StringUtils.upperCaseFirstChar(config.info.author); + else if (typeof config.info.authors == "string") plugin.getAuthor = BDFDB.LibraryModules.StringUtils.upperCaseFirstChar(config.info.authors); + else if (Array.isArray(config.info.authors)) for (let author of config.info.authors) { + plugin.getAuthor += (plugin.getAuthor + (plugin.getAuthor ? ", " : "") + BDFDB.LibraryModules.StringUtils.upperCaseFirstChar(typeof author == "string" ? author : author.name || "")); + } + }; createFrame = _ => { return new Promise(callback => { @@ -801,7 +807,7 @@ var PluginRepo = (_ => { } }; window.addEventListener("message", evalResultReceived); - frame.contentWindow.postMessage({origin:"PluginRepo",reason:"Eval",jsstring:` + if (frame.contentWindow) frame.contentWindow.postMessage({origin:"PluginRepo",reason:"Eval",jsstring:` try { ${body} var p = new ${name}();