This commit is contained in:
Mirco Wittrien 2020-09-19 20:31:49 +02:00
parent 96c3244402
commit b614303e41
1 changed files with 1090 additions and 1124 deletions

View File

@ -1,6 +1,36 @@
//META{"name":"ThemeRepo","authorId":"278543574059057154","invite":"Jx3TjNS","donate":"https://www.paypal.me/MircoWittrien","patreon":"https://www.patreon.com/MircoWittrien","website":"https://github.com/mwittrien/BetterDiscordAddons/tree/master/Plugins/ThemeRepo","source":"https://raw.githubusercontent.com/mwittrien/BetterDiscordAddons/master/Plugins/ThemeRepo/ThemeRepo.plugin.js"}*// //META{"name":"ThemeRepo","authorId":"278543574059057154","invite":"Jx3TjNS","donate":"https://www.paypal.me/MircoWittrien","patreon":"https://www.patreon.com/MircoWittrien","website":"https://github.com/mwittrien/BetterDiscordAddons/tree/master/Plugins/ThemeRepo","source":"https://raw.githubusercontent.com/mwittrien/BetterDiscordAddons/master/Plugins/ThemeRepo/ThemeRepo.plugin.js"}*//
var ThemeRepo = (_ => { module.exports = (_ => {
const config = {
"info": {
"name": "ThemeRepo",
"author": "DevilBro",
"version": "2.0.7",
"description": "Allows you to preview all themes from the theme repo and download them on the fly. Repo button is in the theme settings."
}
};
return !window.BDFDB_Global || (!window.BDFDB_Global.loaded && !window.BDFDB_Global.started) ? class {
getName () {return config.info.name;}
getAuthor () {return config.info.author;}
getVersion () {return config.info.version;}
getDescription () {return config.info.description;}
load() {
if (!window.BDFDB_Global || !Array.isArray(window.BDFDB_Global.pluginQueue)) window.BDFDB_Global = Object.assign({}, window.BDFDB_Global, {pluginQueue:[]});
if (!window.BDFDB_Global.downloadModal) {
window.BDFDB_Global.downloadModal = true;
BdApi.showConfirmationModal("Library Missing", `The library plugin needed for ${config.info.name} is missing. Please click "Download Now" to install it.`, {
confirmText: "Download Now",
cancelText: "Cancel",
onCancel: _ => {delete window.BDFDB_Global.downloadModal;},
onConfirm: _ => {delete window.BDFDB_Global.downloadModal;require("request").get("https://mwittrien.github.io/BetterDiscordAddons/Library/0BDFDB.plugin.js", (error, response, body) => {require("fs").writeFile(require("path").join(BdApi.Plugins.folder, "0BDFDB.plugin.js"), body, _ => {});});}
});
}
if (!window.BDFDB_Global.pluginQueue.includes(config.info.name)) window.BDFDB_Global.pluginQueue.push(config.info.name);
}
start() {}
stop() {}
} : (([Plugin, BDFDB]) => {
var _this; var _this;
var loading, cachedThemes, grabbedThemes, foundThemes, loadedThemes, generatorThemes, updateInterval; var loading, cachedThemes, grabbedThemes, foundThemes, loadedThemes, generatorThemes, updateInterval;
var list, header, preview, searchTimeout, updateGeneratorTimeout, forceRerenderGenerator, nativeCSS, nativeCSSvars, forcedSort, forcedOrder, showOnlyOutdated; var list, header, preview, searchTimeout, updateGeneratorTimeout, forceRerenderGenerator, nativeCSS, nativeCSSvars, forcedSort, forcedOrder, showOnlyOutdated;
@ -82,7 +112,7 @@ var ThemeRepo = (_ => {
author: theme.author, author: theme.author,
description: theme.description || "No Description found.", description: theme.description || "No Description found.",
fav: favorites.includes(url) ? favStates.FAVORIZED : favStates.NOT_FAVORIZED, fav: favorites.includes(url) ? favStates.FAVORIZED : favStates.NOT_FAVORIZED,
new: !cachedThemes.includes(url) ? newStates.NEW : newStates.NOT_NEW, new: theme.state == themeStates.DOWNLOADABLE && !cachedThemes.includes(url) ? newStates.NEW : newStates.NOT_NEW,
state: theme.state, state: theme.state,
css: theme.css, css: theme.css,
fullCSS: theme.fullCSS fullCSS: theme.fullCSS
@ -113,7 +143,6 @@ var ThemeRepo = (_ => {
onLoad: _ => { onLoad: _ => {
let titleBar = document.querySelector(BDFDB.dotCN.titlebar); let titleBar = document.querySelector(BDFDB.dotCN.titlebar);
preview.executeJavaScriptSafe(`window.onmessage({ preview.executeJavaScriptSafe(`window.onmessage({
location: document.location.origin,
origin: "ThemeRepo", origin: "ThemeRepo",
reason: "OnLoad", reason: "OnLoad",
username: ${JSON.stringify(BDFDB.UserUtils.me.username || "")}, username: ${JSON.stringify(BDFDB.UserUtils.me.username || "")},
@ -122,7 +151,7 @@ var ThemeRepo = (_ => {
avatar: ${JSON.stringify(BDFDB.UserUtils.getAvatar() || "")}, avatar: ${JSON.stringify(BDFDB.UserUtils.getAvatar() || "")},
classes: ${JSON.stringify(JSON.stringify(BDFDB.DiscordClasses))}, classes: ${JSON.stringify(JSON.stringify(BDFDB.DiscordClasses))},
classModules: ${JSON.stringify(JSON.stringify(BDFDB.DiscordClassModules))}, classModules: ${JSON.stringify(JSON.stringify(BDFDB.DiscordClassModules))},
nativeCSS: ${JSON.stringify(nativeCSS || "")}, nativeCSS: ${JSON.stringify((nativeCSS || "").replace(/\/assets\//g, document.location.origin + "/assets/").replace(/[\t\r\n]/g, ""))},
htmlClassName: ${JSON.stringify(document.documentElement.className || "")}, htmlClassName: ${JSON.stringify(document.documentElement.className || "")},
titleBar: ${JSON.stringify(titleBar && titleBar.outerHTML || "")} titleBar: ${JSON.stringify(titleBar && titleBar.outerHTML || "")}
})`); })`);
@ -638,28 +667,8 @@ var ThemeRepo = (_ => {
}); });
} }
}; };
return class ThemeRepo extends Plugin {
return class ThemeRepo { onLoad() {
getName () {return "ThemeRepo";}
getVersion () {return "2.0.7";}
getAuthor () {return "DevilBro";}
getDescription () {return "Allows you to preview all themes from the theme repo and download them on the fly. Repo button is in the theme settings.";}
constructor () {
this.patchedModules = {
before: {
SettingsView: "render"
},
after: {
StandardSidebarView: "render"
}
};
}
initConstructor () {
_this = this; _this = this;
loading = {is:false, timeout:null, amount:0}; loading = {is:false, timeout:null, amount:0};
@ -685,17 +694,34 @@ var ThemeRepo = (_ => {
} }
}; };
this.css = ` this.patchedModules = {
.${this.name}-modal.repo-modal { before: {
max-width: 800px; SettingsView: "render"
min-height: 90vh; },
max-height: 90vh; after: {
StandardSidebarView: "render"
} }
`; };
}
onStart() {
this.forceUpdateAll();
this.loadThemes();
updateInterval = BDFDB.TimeUtils.interval(_ => {this.checkForNewThemes();}, 1000*60*30);
}
onStop() {
BDFDB.TimeUtils.clear(updateInterval);
BDFDB.TimeUtils.clear(loading.timeout);
this.forceUpdateAll();
BDFDB.DOMUtils.remove(".bd-themerepobutton", ".themerepo-notice", ".themerepo-loadingicon");
} }
getSettingsPanel (collapseStates = {}) { getSettingsPanel (collapseStates = {}) {
if (!window.BDFDB || typeof BDFDB != "object" || !BDFDB.loaded || !this.started) return;
let customUrl = ""; let customUrl = "";
let settingsPanel, settingsItems = []; let settingsPanel, settingsItems = [];
@ -786,65 +812,13 @@ var ThemeRepo = (_ => {
return settingsPanel = BDFDB.PluginUtils.createSettingsPanel(this, settingsItems); return settingsPanel = BDFDB.PluginUtils.createSettingsPanel(this, settingsItems);
} }
// Legacy onSettingsClosed () {
load () { if (this.SettingsUpdated) {
if (window.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) BDFDB.PluginUtils.load(this); delete this.SettingsUpdated;
}
start () {
if (!window.BDFDB) window.BDFDB = {myPlugins:{}};
if (window.BDFDB && window.BDFDB.myPlugins && typeof window.BDFDB.myPlugins == "object") window.BDFDB.myPlugins[this.getName()] = this;
let libraryScript = document.querySelector("head script#BDFDBLibraryScript");
if (!libraryScript || (performance.now() - libraryScript.getAttribute("date")) > 600000) {
if (libraryScript) libraryScript.remove();
libraryScript = document.createElement("script");
libraryScript.setAttribute("id", "BDFDBLibraryScript");
libraryScript.setAttribute("type", "text/javascript");
libraryScript.setAttribute("src", "https://mwittrien.github.io/BetterDiscordAddons/Plugins/BDFDB.min.js");
libraryScript.setAttribute("date", performance.now());
libraryScript.addEventListener("load", _ => {this.initialize();});
document.head.appendChild(libraryScript);
}
else if (window.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) this.initialize();
this.startTimeout = setTimeout(_ => {
try {return this.initialize();}
catch (err) {console.error(`%c[${this.getName()}]%c`, "color: #3a71c1; font-weight: 700;", "", "Fatal Error: Could not initiate plugin! " + err);}
}, 30000);
}
initialize () {
if (window.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) {
if (this.started) return;
BDFDB.PluginUtils.init(this);
this.forceUpdateAll(); this.forceUpdateAll();
this.loadThemes();
updateInterval = BDFDB.TimeUtils.interval(_ => {this.checkForNewThemes();}, 1000*60*30);
}
else console.error(`%c[${this.getName()}]%c`, "color: #3a71c1; font-weight: 700;", "", "Fatal Error: Could not load BD functions!");
}
stop () {
if (window.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) {
this.stopping = true;
BDFDB.TimeUtils.clear(updateInterval);
BDFDB.TimeUtils.clear(loading.timeout);
this.forceUpdateAll();
BDFDB.DOMUtils.remove(".bd-themerepobutton", ".themerepo-notice", ".themerepo-loadingicon");
BDFDB.PluginUtils.clear(this);
} }
} }
// Begin of own functions
forceUpdateAll () { forceUpdateAll () {
settings = BDFDB.DataUtils.get(this, "settings"); settings = BDFDB.DataUtils.get(this, "settings");
modalSettings = BDFDB.DataUtils.get(this, "modalSettings"); modalSettings = BDFDB.DataUtils.get(this, "modalSettings");
@ -856,13 +830,6 @@ var ThemeRepo = (_ => {
BDFDB.PatchUtils.forceAllUpdates(this); BDFDB.PatchUtils.forceAllUpdates(this);
} }
onSettingsClosed () {
if (this.SettingsUpdated) {
delete this.SettingsUpdated;
this.forceUpdateAll();
}
}
onUserSettingsCogContextMenu (e) { onUserSettingsCogContextMenu (e) {
BDFDB.TimeUtils.timeout(_ => { BDFDB.TimeUtils.timeout(_ => {
let [children, index] = BDFDB.ReactUtils.findParent(e.returnvalue, {props: [["label", "BandagedBD"]]}); let [children, index] = BDFDB.ReactUtils.findParent(e.returnvalue, {props: [["label", "BandagedBD"]]});
@ -1177,7 +1144,6 @@ var ThemeRepo = (_ => {
BDFDB.LogUtils.log(`Removed Theme ${data.name}.`, this.name); BDFDB.LogUtils.log(`Removed Theme ${data.name}.`, this.name);
} }
} }
} };
})(window.BDFDB_Global.PluginUtils.buildPlugin(config));
})(); })();
module.exports = ThemeRepo;