//META{"name":"PluginRepo"}*// class PluginRepo { initConstructor () { this.sortings = { sort: { name: "Name", author: "Author", version: "Version", description: "Description", state: "Update State", fav: "Favorites" }, order: { asc: "Ascending", desc: "Descending" } }; this.loading = false; this.grabbedPlugins = []; this.foundPlugins = []; this.loadedPlugins = {}; this.updateInterval; this.pluginRepoButtonMarkup = ``; this.settingsContextEntryMarkup = `
Plugin Repo
`; this.pluginEntryMarkup = `
  • v by
  • `; this.pluginRepoModalMarkup = `

    Plugin Repository

    Plugins
    Settings
    Sort by:
    ${this.sortings.sort[Object.keys(this.sortings.sort)[0]]}
    Order:
    ${this.sortings.order[Object.keys(this.sortings.order)[0]]}

      To expierence PluginRepo in the best way. I would recommend you to enable BD intern reload function, that way all downloaded files are loaded into Discord without the need to reload.

      Hide updated Plugins.

      Hide outdated Plugins.

      Hide downloadable Plugins.

      Start Plugin after Download (Restart-No-More needed)

      `; this.sortPopoutMarkup = `
      ${Object.keys(this.sortings.sort).map((key, i) => `
      ${this.sortings.sort[key]}
      `).join("")}
      `; this.orderPopoutMarkup = `
      ${Object.keys(this.sortings.order).map((key, i) => `
      ${this.sortings.order[key]}
      `).join("")}
      `; this.css = ` .pluginrepo-modal ${BDFDB.dotCN.modalinner} { min-height: 100%; } .pluginrepo-modal .pluginEntry { overflow: visible !important; } .pluginrepo-modal .pluginEntry .gitIcon, .pluginrepo-modal .pluginEntry .favIcon, .pluginrepo-modal .pluginEntry .trashIcon { margin-right: 5px; cursor: pointer; } .pluginrepo-modal .pluginEntry .trashIcon, .pluginrepo-modal .pluginEntry .favIcon { margin-left: auto; } .pluginrepo-modal .pluginEntry .btn-download { margin-left: 0 !important; } .pluginrepo-modal .pluginEntry .favIcon path { stroke: yellow; fill: none; } .pluginrepo-modal .pluginEntry .favIcon.favorized path { stroke: yellow; fill: yellow; } .pluginrepo-modal .pluginEntry.downloadable .trashIcon { display: none; } .pluginrepo-modal .pluginEntry.downloadable .btn-download { background-color: rgb(114, 137, 218) !important; margin-left: auto !important; } .pluginrepo-modal .pluginEntry.outdated .btn-download { background-color: rgb(240, 71, 71) !important; margin-left: 0 !important; } .pluginrepo-modal .pluginEntry.updated .btn-download { background-color: rgb(67, 181, 129) !important; margin-left: 0 !important; } .pluginrepo-trashicon-tooltip{ z-index: 3500!important; } .pluginrepo-modal .pluginEntry.jiiks .bda-right { flex: 1 1 auto; } .pluginrepo-modal .pluginEntry.jiiks .bda-header, .pluginrepo-modal .pluginEntry.jiiks .bda-footer { display: flex; align-items: center; margin: 0 !important; } .pluginrepo-modal .pluginEntry.jiiks .bda-footer { margin-top: 33% !important; }`; } getName () {return "PluginRepo";} getDescription () {return "Allows you to look at all plugins from the plugin repo and download them on the fly. Repo button is in the plugins settings.";} getVersion () {return "1.5.5";} getAuthor () {return "DevilBro";} getSettingsPanel () { if (!this.started || typeof BDFDB !== "object") return; var settingshtml = `
      ${this.getName()}
      `; settingshtml += `

      Add Plugin:

      `; settingshtml += `

      Your additional Plugin List:

      `; var ownlist = BDFDB.loadData("ownlist", this, "ownlist") || []; for (let url of ownlist) { settingshtml += `
      ${url}
      `; } settingshtml += `
      `; settingshtml += `

      Force all Plugins to be fetched again.

      `; settingshtml += `

      Remove all added Plugins from your own list.

      `; settingshtml += `
      `; var settingspanel = $(settingshtml)[0]; BDFDB.initElements(settingspanel); $(settingspanel) .on("click", ".btn-addplugin", () => {this.addPluginToOwnList(settingspanel);}) .on("keyup", "#input-pluginurl", (e) => {if (e.which == 13) this.addPluginToOwnList(settingspanel);}) .on("click", ".remove-plugin", (e) => {this.removePluginFromOwnList(e);}) .on("click", ".remove-all", () => {this.removeAllFromOwnList(settingspanel);}) .on("click", ".refresh-button", () => {this.loadPlugins();}); return settingspanel; } //legacy load () {} start () { var libraryScript = null; if (typeof BDFDB !== "object" || typeof BDFDB.isLibraryOutdated !== "function" || BDFDB.isLibraryOutdated()) { libraryScript = document.querySelector('head script[src="https://mwittrien.github.io/BetterDiscordAddons/Plugins/BDFDB.js"]'); if (libraryScript) libraryScript.remove(); libraryScript = document.createElement("script"); libraryScript.setAttribute("type", "text/javascript"); libraryScript.setAttribute("src", "https://mwittrien.github.io/BetterDiscordAddons/Plugins/BDFDB.js"); document.head.appendChild(libraryScript); } this.startTimeout = setTimeout(() => {this.initialize();}, 30000); if (typeof BDFDB === "object" && typeof BDFDB.isLibraryOutdated === "function") this.initialize(); else libraryScript.addEventListener("load", () => {this.initialize();}); } initialize () { if (typeof BDFDB === "object") { BDFDB.loadMessage(this); var observer = null; observer = new MutationObserver((changes, _) => { changes.forEach( (change, j) => { if (change.addedNodes) { change.addedNodes.forEach((node) => { this.checkIfPluginsPage(node); }); } } ); }); BDFDB.addObserver(this, BDFDB.dotCN.layer + "[layer-id='user-settings']", {name:"innerSettingsWindowObserver",instance:observer}, {childList:true,subtree:true}); observer = new MutationObserver((changes, _) => { changes.forEach( (change, i) => { if (change.addedNodes) { change.addedNodes.forEach((node) => { setImmediate(() => { if (node && node.tagName && node.getAttribute("layer-id") == "user-settings") { BDFDB.addObserver(this, node, {name:"innerSettingsWindowObserver"}, {childList:true,subtree:true}); this.checkIfPluginsPage(node); } }); }); } } ); }); BDFDB.addObserver(this, BDFDB.dotCN.layers, {name:"settingsWindowObserver",instance:observer}, {childList:true}); observer = new MutationObserver((changes, _) => { changes.forEach( (change, i) => { if (change.addedNodes) { change.addedNodes.forEach((node) => { if (node && node.nodeType == 1 && node.className.includes(BDFDB.disCN.contextmenu)) { this.onContextMenu(node); } }); } } ); }); BDFDB.addObserver(this, BDFDB.dotCN.appmount, {name:"settingsContextObserver",instance:observer}, {childList: true}); var settingswindow = document.querySelector(BDFDB.dotCN.layer + "[layer-id='user-settings']"); if (settingswindow) this.checkIfPluginsPage(settingswindow); this.loadPlugins(); this.updateInterval = setInterval(() => {this.checkForNewPlugins();},1000*60*30); } else { console.error(this.getName() + ": Fatal Error: Could not load BD functions!"); } } stop () { if (typeof BDFDB === "object") { clearInterval(this.updateInterval); $(".pluginrepo-modal, .bd-pluginrepobutton, webview[webview-PluginRepo]").remove(); BDFDB.unloadMessage(this); } } // begin of own functions onContextMenu (context) { if (!context || !context.tagName || !context.parentElement) return; for (let entry of context.querySelectorAll(BDFDB.dotCN.contextmenuitem)) { if (entry.textContent == "BetterDiscord") { let innerObserver = new MutationObserver((changes, _) => { changes.forEach( (change, i) => { if (change.addedNodes) { change.addedNodes.forEach((node) => { if (node && node.nodeType == 1 && node.className.includes(BDFDB.disCN.contextmenu) && !node.querySelector(".pluginrepo-item")) { for (let innerEntry of node.querySelectorAll(BDFDB.dotCN.contextmenuitem)) { if (innerEntry.textContent == "Themes") { $(this.settingsContextEntryMarkup) .on("click", () => { if (!this.loading) $(context).hide(); this.openPluginRepoModal(); }) .insertAfter(innerEntry); $(node).css("top", $(context).css("top").replace("px","") - $(node).outerHeight() + $(context).outerHeight()); break; } } } }); } } ); }); innerObserver.observe(entry, {childList: true}); break; } } } addPluginToOwnList (settingspanel) { var pluginUrlInput = settingspanel.querySelector("#input-pluginurl"); var pluginList = settingspanel.querySelector(".plugin-list"); if (pluginUrlInput && pluginList) { var url = pluginUrlInput.value; pluginUrlInput.value = null; var ownlist = BDFDB.loadData("ownlist", this, "ownlist") || []; if (!ownlist.includes(url)) { ownlist.push(url); BDFDB.saveData("ownlist", ownlist, this, "ownlist"); $(`
      ${url}
      `).appendTo(pluginList); } } } removePluginFromOwnList (e) { var entry = e.currentTarget.parentElement; var url = entry.querySelector(".entryurl").textContent; entry.remove(); var ownlist = BDFDB.loadData("ownlist", this, "ownlist") || []; BDFDB.removeFromArray(ownlist, url); BDFDB.saveData("ownlist", ownlist, this, "ownlist"); } removeAllFromOwnList (settingspanel) { if (confirm("Are you sure you want to remove all added Plugins from your own list?")) { BDFDB.saveData("ownlist", [], this, "ownlist"); settingspanel.querySelectorAll(BDFDB.dotCN.hovercard).forEach(ele => {ele.remove();}); } } checkIfPluginsPage (container) { if (container && container.tagName) { var folderbutton = container.querySelector(".bd-pfbtn"); if (folderbutton) { var buttonbar = folderbutton.parentElement; if (buttonbar && buttonbar.tagName) { var header = buttonbar.querySelector("h2"); if (header && header.innerText.toUpperCase() === "PLUGINS") { this.addPluginRepoButton(buttonbar); } } } } } addPluginRepoButton (container) { if (container && !container.querySelector(".bd-pluginrepobutton")) { $(container).find(".bda-description").css("display", "block"); $(this.pluginRepoButtonMarkup) .insertAfter(container.querySelector(".bd-pfbtn")) .on("click", () => { this.openPluginRepoModal() }) .on("mouseenter", (e) => { BDFDB.createTooltip("Open Plugin Repo", e.currentTarget, {type:"top",selector:"pluginrepo-button-tooltip"}); }); } } openPluginRepoModal (showOnlyOutdated = false) { if (this.loading) { BDFDB.showToast(`Plugins are still being fetched. Try again in some seconds.`, {type:"danger"}); return; } var pluginRepoModal = $(this.pluginRepoModalMarkup); pluginRepoModal.updateModal = true; pluginRepoModal.enableSearch = false; var hiddenSettings = BDFDB.loadAllData(this, "hidden"); pluginRepoModal.find("#input-hideupdated").prop("checked", hiddenSettings.updated || showOnlyOutdated); pluginRepoModal.find("#input-hideoutdated").prop("checked", hiddenSettings.outdated && !showOnlyOutdated); pluginRepoModal.find("#input-hidedownloadable").prop("checked", hiddenSettings.downloadable || showOnlyOutdated); if (!BDFDB.isRestartNoMoreEnabled()) pluginRepoModal.find("#RNMoption").remove(); else pluginRepoModal.find("#input-rnmstart").prop("checked", BDFDB.loadData("RNMstart", this, "settings")); pluginRepoModal .on("keyup." + this.getName(), BDFDB.dotCN.searchbarinput, () => { clearTimeout(pluginRepoModal.searchTimeout); pluginRepoModal.searchTimeout = setTimeout(() => {this.addPluginEntries(pluginRepoModal);},1000); }) .on("click." + this.getName(), BDFDB.dotCN.searchbarclear + BDFDB.dotCN.searchbarvisible, () => { clearTimeout(pluginRepoModal.searchTimeout); pluginRepoModal.searchTimeout = setTimeout(() => {this.addPluginEntries(pluginRepoModal);},1000); }) .on("change." + this.getName(), ".hide-checkbox", (e) => { var hideButton = $(e.currentTarget); hiddenSettings[hideButton.val()] = hideButton.prop("checked"); BDFDB.saveAllData(hiddenSettings, this, "hidden"); }) .on("change." + this.getName(), "#input-rnmstart", (e) => { BDFDB.saveData("RNMstart", $(e.currentTarget).prop("checked"), this, "settings"); }) .on("click." + this.getName(), ".sort-filter", (e) => { this.openSortPopout(e, this.sortPopoutMarkup, pluginRepoModal); }) .on("click." + this.getName(), ".order-filter", (e) => { this.openSortPopout(e, this.orderPopoutMarkup, pluginRepoModal); }) .on("click." + this.getName(), ".tab[tab=plugins]:not(.selected)", (e) => { this.addPluginEntries(pluginRepoModal); }); this.createPluginEntries(pluginRepoModal); BDFDB.appendModal(pluginRepoModal); } openSortPopout (e, markup, modal) { var wrapper = e.currentTarget; if (wrapper.classList.contains("popout-open")) return; wrapper.classList.add("popout-open"); var value = $(wrapper).find(BDFDB.dotCN.quickselectvalue); var popout = $(markup); $(BDFDB.dotCN.popouts).append(popout) .off("click", BDFDB.dotCN.contextmenuitem) .on("click", BDFDB.dotCN.contextmenuitem, (e2) => { value.text($(e2.currentTarget).text()); value.attr("option", $(e2.currentTarget).attr("option")); $(document).off("mousedown.sortpopout" + this.getName()); popout.remove(); this.addPluginEntries(modal); setTimeout(() => {wrapper.classList.remove("popout-open");},300); }); popout .css("left", $(wrapper).offset().left + $(wrapper).outerWidth() + "px") .css("top", $(wrapper).offset().top + value.outerHeight() + "px") .find(BDFDB.dotCN.contextmenu).addClass(BDFDB.getDiscordTheme()); $(document).on("mousedown.sortpopout" + this.getName(), (e2) => { if (popout.has(e2.target).length == 0) { $(document).off("mousedown.sortpopout" + this.getName()); popout.remove(); setTimeout(() => {wrapper.classList.remove("popout-open");},300); } }); } createPluginEntries (modal) { var favorites = BDFDB.loadAllData(this, "favorites"); modal.entries = []; for (let url in this.loadedPlugins) { let plugin = this.loadedPlugins[url]; let div = $(this.pluginEntryMarkup); var installedPlugin = window.bdplugins[plugin.getName] ? window.bdplugins[plugin.getName].plugin : null; if (installedPlugin && installedPlugin.getAuthor().toUpperCase() == plugin.getAuthor.toUpperCase()) { if (installedPlugin.getVersion() != plugin.getVersion) { plugin.getState = 1; div.addClass("outdated") .find(".btn-download").text("Outdated"); } else { plugin.getState = 0; div.addClass("updated") .find(".btn-download").text("Updated"); } } else { plugin.getState = 2; div.addClass("downloadable") .find(".btn-download").text("Download"); } if (favorites[url]) { plugin.getFav = 0; div.find(".favIcon")[0].classList.add("favorized"); } else { plugin.getFav = 1; div.find(".favIcon")[0].classList.remove("favorized"); } modal.entries.push({ div: div, url: plugin.url, search: (plugin.getName + " " + plugin.getVersion + " " + plugin.getAuthor + " " + plugin.getDescription).toUpperCase(), name: plugin.getName, version: plugin.getVersion, author: plugin.getAuthor, description: plugin.getDescription ? plugin.getDescription : "No Description found.", fav: plugin.getFav, state: plugin.getState }); } this.addPluginEntries(modal); } addPluginEntries (modal) { if (typeof modal.entries != "object") return; modal.find(".pluginEntry").remove(); var searchstring = modal.find(BDFDB.dotCN.searchbarinput).val().replace(/[<|>]/g, "").toUpperCase(); var entries = modal.entries; if (modal.find("#input-hideupdated").prop("checked")) entries = entries.filter((entry) => {return entry.state != 0 ? entry : null;}); if (modal.find("#input-hideoutdated").prop("checked")) entries = entries.filter((entry) => {return entry.state != 1 ? entry : null;}); if (modal.find("#input-hidedownloadable").prop("checked")) entries = entries.filter((entry) => {return entry.state != 2 ? entry : null;}); entries = entries.filter((entry) => {return entry.search.indexOf(searchstring) > -1 ? entry : null;}); BDFDB.sortArrayByKey(entries, modal.find(".sort-filter " + BDFDB.dotCN.quickselectvalue).attr("option")); if (modal.find(".order-filter " + BDFDB.dotCN.quickselectvalue).attr("option") == "desc") entries.reverse(); modal.find(".pluginAmount").text("Plugin Repository " + entries.length + "/" + Object.keys(this.loadedPlugins).length + " Plugins"); var container = modal.find(".plugins"); entries.forEach((entry) => { var div = entry.div; var values = [entry.name, entry.version, entry.author, entry.description]; if (searchstring.length > 0) { for (let i in values) values[i] = BDFDB.highlightText(values[i], searchstring); } div.find(".bda-name").html(values[0]); div.find(".bda-version").html(values[1]); div.find(".bda-author").html(values[2]); div.find(".bda-description").html(values[3]); div .on("click." + this.getName(), ".favIcon", (e) => { e.currentTarget.classList.toggle("favorized"); if (e.currentTarget.classList.contains("favorized")) { entry.fav = 0; BDFDB.saveData(entry.url, true, this, "favorites"); } else { entry.fav = 1; BDFDB.removeData(entry.url, this, "favorites"); } }) .on("click." + this.getName(), ".gitIcon", (e) => { var giturl = null; if (entry.url.indexOf("https://raw.githubusercontent.com") == 0) { var temp = entry.url.replace("//raw.githubusercontent", "//github").split("/"); temp.splice(5, 0, "blob"); giturl = temp.join("/"); } else if (entry.url.indexOf("https://gist.githubusercontent.com/") == 0) { giturl = entry.url.replace("//gist.githubusercontent", "//gist.github").split("/raw/")[0]; } if (giturl) { window.open(giturl, "_blank"); } }) .on("click." + this.getName(), ".trashIcon", () => { if (div.hasClass("outdated") || div.hasClass("updated")) { entry.state = 2; div.removeClass("outdated").removeClass("updated").addClass("downloadable") .find(".btn-download").text("Download"); this.deletePluginFile(entry); if (!BDFDB.isRestartNoMoreEnabled()) this.stopPlugin(entry); } }) .on("click." + this.getName(), ".btn-download", () => { entry.state = 0; div.removeClass("downloadable").removeClass("outdated").addClass("updated") .find(".btn-download").text("Updated"); this.downloadPlugin(entry); if (modal.find("#input-rnmstart").prop("checked")) setTimeout(() => {this.startPlugin(entry);},3000); }) .on("mouseenter." + this.getName(), ".favIcon", (e) => { BDFDB.createTooltip("Favorize", e.currentTarget, {type:"top",selector:"pluginrepo-favicon-tooltip"}); }) .on("mouseenter." + this.getName(), ".gitIcon", (e) => { BDFDB.createTooltip("Go to Git", e.currentTarget, {type:"top",selector:"pluginrepo-giticon-tooltip"}); }) .on("mouseenter." + this.getName(), ".trashIcon", (e) => { BDFDB.createTooltip("Delete Pluginfile", e.currentTarget, {type:"top",selector:"pluginrepo-trashicon-tooltip"}); }); container.append(div); }); } loadPlugins () { var getPluginInfo, outdated = 0, i = 0; var tags = ["getName", "getVersion", "getAuthor", "getDescription"]; var seps = ["\"", "\'", "\`"]; let request = require("request"); request("https://mwittrien.github.io/BetterDiscordAddons/Plugins/PluginRepo/res/PluginList.txt", (error, response, result) => { if (response) { this.loadedPlugins = {}; this.grabbedPlugins = result.split("\n"); this.foundPlugins = this.grabbedPlugins.concat(BDFDB.loadData("ownlist", this, "ownlist") || []); this.loading = true; createWebview().then((webview) => { getPluginInfo(webview, () => { this.loading = false; console.log("PluginRepo: Finished fetching Plugins."); if (document.querySelector(".bd-pluginrepobutton")) BDFDB.showToast(`Finished fetching Plugins.`, {type:"success"}); if (outdated > 0) { var text = `${outdated} of your Plugins ${outdated == 1 ? "is" : "are"} outdated. Check:`; var bar = BDFDB.createNotificationsBar(text,{type:"danger",btn:"PluginRepo",selector:"pluginrepo-notice"}); $(bar).on("click." + this.getName(), BDFDB.dotCN.noticebutton, (e) => { this.openPluginRepoModal(true); e.delegateTarget.querySelector(BDFDB.dotCN.noticedismiss).click(); }); } setTimeout(() => {webview.remove();},10000); if (BDFDB.myData.id == "278543574059057154") { let wrongUrls = []; for (let url of this.foundPlugins) if (url && !this.loadedPlugins[url] && !wrongUrls.includes(url)) wrongUrls.push(url); if (wrongUrls.length > 0) { var bar = BDFDB.createNotificationsBar(`PluginRepo: ${wrongUrls.length} Plugin${wrongUrls.length > 1 ? "s" : ""} could not be loaded.`, {type:"danger",btn:"List"}); $(bar).on("click." + this.getName(), BDFDB.dotCN.noticebutton, (e) => { var toast = BDFDB.showToast(wrongUrls.join("\n"),{type:"error"}); toast.style.overflow = "hidden"; console.log(wrongUrls.length == 1 ? wrongUrls[0] : wrongUrls); }); } } }); }); } }); getPluginInfo = (webview, callback) => { if (i >= this.foundPlugins.length) { callback(); return; } let url = this.foundPlugins[i].replace(new RegExp("[\\r|\\n|\\t]", "g"), ""); this.foundPlugins[i] = url; request(url, (error, response, body) => { if (!response) { if (url && BDFDB.getAllIndexes(this.foundPlugins, url).length < 2) this.foundPlugins.push(url); } else { let plugin = {}; let bodycopy = body; if (body.length / body.split("\n").length > 1000) { /* code is minified -> add newlines */ bodycopy = body.replace(new RegExp("}", "g"), "}\n"); } for (let tag of tags) { let result = new RegExp(tag + "[\\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); if (result.length > 2) { result = result.slice(1, -1).join(separator).replace(new RegExp("\\\\n", "g"), "
      ").replace(new RegExp("\\\\", "g"), ""); plugin[tag] = tag != "getVersion" ? result.charAt(0).toUpperCase() + result.slice(1) : result; } } } let valid = true; for (let tag of tags) { if (!plugin[tag] || plugin[tag].length > 10000) valid = false; } if (valid) { plugin.url = url; this.loadedPlugins[url] = plugin; var installedPlugin = window.bdplugins[plugin.getName] ? window.bdplugins[plugin.getName].plugin : null; if (installedPlugin && installedPlugin.getAuthor().toUpperCase() == plugin.getAuthor.toUpperCase() && installedPlugin.getVersion() != plugin.getVersion) { if (PluginUpdates && PluginUpdates.plugins && !PluginUpdates.plugins[url]) outdated++; } } else { let name = body.replace(new RegExp("\\s*\:\\s*", "g"), ":").split('"name":"'); if (name.length > 1 && webview) { name = name[1].split('"')[0]; webview.getWebContents().executeJavaScript(body).then(() => { webview.getWebContents().executeJavaScript(` var p = new ` + name + `(); var data = { "getName":p.getName(), "getAuthor":p.getAuthor(), "getVersion":p.getVersion(), "getDescription":p.getDescription() }; Promise.resolve(data);` ).then((plugin) => { plugin.url = url; this.loadedPlugins[url] = plugin; var installedPlugin = window.bdplugins[plugin.getName] ? window.bdplugins[plugin.getName].plugin : null; if (installedPlugin && installedPlugin.getAuthor().toUpperCase() == plugin.getAuthor.toUpperCase() && installedPlugin.getVersion() != plugin.getVersion) outdated++; }); }); } } } i++; getPluginInfo(webview, callback); }); } function createWebview () { return new Promise(function(callback) { var webview; webview = document.createElement("webview"); webview.src = "https://discordapp.com/"; webview.setAttribute("webview-PluginRepo", null); webview.style.setProperty("visibility", "hidden"); webview.addEventListener("dom-ready", () => { callback(webview); }); document.body.appendChild(webview); }); } } checkForNewPlugins () { let request = require("request"); request("https://mwittrien.github.io/BetterDiscordAddons/Plugins/PluginRepo/res/PluginList.txt", (error, response, result) => { if (response && !BDFDB.equals(result.split("\n"), this.grabbedPlugins)) this.loadPlugins(); }); } downloadPlugin (entry) { let request = require("request"); request(entry.url, (error, response, body) => { if (error) { BDFDB.showToast(`Unable to download Plugin "${plugin.getName}".`, {type:"danger"}); } else { let filename = entry.url.split("/"); this.createPluginFile(filename[filename.length - 1], body); } }); } createPluginFile (filename, content) { let fileSystem = require("fs"); let path = require("path"); var file = path.join(BDFDB.getPluginsFolder(), filename); fileSystem.writeFile(file, content, (error) => { if (error) { BDFDB.showToast(`Unable to save Plugin "${filename}".`, {type:"danger"}); } else { BDFDB.showToast(`Successfully saved Plugin "${filename}".`, {type:"success"}); } }); } startPlugin (entry) { var name = entry.name; if (BDFDB.isPluginEnabled(name) == false) { bdplugins[name].plugin.start(); pluginCookie[name] = true; pluginModule.savePluginData(); console.log("PluginRepo: started Plugin " + name); } } deletePluginFile (entry) { let fileSystem = require("fs"); let path = require("path"); let filename = entry.url.split("/"); filename = filename[filename.length - 1]; var file = path.join(BDFDB.getPluginsFolder(), filename); fileSystem.unlink(file, (error) => { if (error) { BDFDB.showToast(`Unable to delete Plugin "${filename}".`, {type:"danger"}); } else { BDFDB.showToast(`Successfully deleted Plugin "${filename}".`, {type:"success"}); } }); } stopPlugin (entry) { var name = entry.name; if (BDFDB.isPluginEnabled(name) == true) { bdplugins[name].plugin.stop(); pluginCookie[name] = false; delete bdplugins[name]; pluginModule.savePluginData(); console.log("PluginRepo: stopped Plugin " + name); } } }