diff --git a/Library/0BDFDB.plugin.js b/Library/0BDFDB.plugin.js index 39fc7ed8f2..e687514081 100644 --- a/Library/0BDFDB.plugin.js +++ b/Library/0BDFDB.plugin.js @@ -16,13 +16,13 @@ module.exports = (_ => { "info": { "name": "BDFDB", "author": "DevilBro", - "version": "1.1.1", + "version": "1.1.2", "description": "Give other plugins utility functions" }, "rawUrl": "https://mwittrien.github.io/BetterDiscordAddons/Library/0BDFDB.plugin.js", "changeLog": { "fixed": { - "Crash on Canary": "Fixed the crash issue that occured one some plugins on canary" + "BD Beta": "Fixed some issues with the BD Beta" } } }; diff --git a/Plugins/NotificationSounds/NotificationSounds.plugin.js b/Plugins/NotificationSounds/NotificationSounds.plugin.js index 8cd2089e20..509b863d1c 100644 --- a/Plugins/NotificationSounds/NotificationSounds.plugin.js +++ b/Plugins/NotificationSounds/NotificationSounds.plugin.js @@ -14,13 +14,16 @@ module.exports = (_ => { "info": { "name": "NotificationSounds", "author": "DevilBro", - "version": "3.5.2", + "version": "3.5.3", "description": "Allow you to replace the native sounds of Discord with your own" }, "changeLog": { "added": { "Halloween": "Added discord's halloween call sound to the choices", "Global Volume": "Added global volume slider affecting all sounds" + }, + "fixed": { + "Removed Default Category": "Removed the category 'Default' since the audio files no longer exist on the webpage" } } }; @@ -107,15 +110,6 @@ module.exports = (_ => { "---": { "---": null }, - "Default": { - "Communication Channel": "https://notificationsounds.com/soundfiles/63538fe6ef330c13a05a3ed7e599d5f7/file-sounds-917-communication-channel.wav", - "Isn't it": "https://notificationsounds.com/soundfiles/ba2fd310dcaa8781a9a652a31baf3c68/file-sounds-969-isnt-it.wav", - "Job Done": "https://notificationsounds.com/soundfiles/5b69b9cb83065d403869739ae7f0995e/file-sounds-937-job-done.wav", - "Served": "https://notificationsounds.com/soundfiles/b337e84de8752b27eda3a12363109e80/file-sounds-913-served.wav", - "Solemn": "https://notificationsounds.com/soundfiles/53fde96fcc4b4ce72d7739202324cd49/file-sounds-882-solemn.wav", - "System Fault": "https://notificationsounds.com/soundfiles/ebd9629fc3ae5e9f6611e2ee05a31cef/file-sounds-990-system-fault.wav", - "You wouldn't believe": "https://notificationsounds.com/soundfiles/087408522c31eeb1f982bc0eaf81d35f/file-sounds-949-you-wouldnt-believe.wav" - }, "Discord": {} }; @@ -654,8 +648,8 @@ module.exports = (_ => { } loadAudios () { - audios = Object.assign({}, defaultAudios, BDFDB.DataUtils.load(this, "audios")); - BDFDB.DataUtils.save(audios, this, "audios"); + audios = Object.assign({}, BDFDB.DataUtils.load(this, "audios"), defaultAudios); + BDFDB.DataUtils.save(BDFDB.ObjectUtils.exclude(audios, Object.keys(defaultAudios)), this, "audios"); } loadChoices () { diff --git a/Plugins/PluginRepo/PluginRepo.plugin.js b/Plugins/PluginRepo/PluginRepo.plugin.js index c9bb2c5290..5664454406 100644 --- a/Plugins/PluginRepo/PluginRepo.plugin.js +++ b/Plugins/PluginRepo/PluginRepo.plugin.js @@ -14,7 +14,7 @@ module.exports = (_ => { "info": { "name": "PluginRepo", "author": "DevilBro", - "version": "2.0.9", + "version": "2.1.0", "description": "Allow you to look at all plugins from the plugin repo and download them on the fly" }, "changeLog": { @@ -51,6 +51,7 @@ module.exports = (_ => { start() {this.load();} stop() {} } : (([Plugin, BDFDB]) => { + const isBeta = !(window.BdApi && !Array.isArray(BdApi.settings)); var _this; var loading, cachedPlugins, grabbedPlugins, foundPlugins, loadedPlugins, updateInterval; var list, header, searchTimeout, forcedSort, forcedOrder, showOnlyOutdated; @@ -65,16 +66,19 @@ module.exports = (_ => { UPDATED: { colorClass: "GREEN", backgroundColor: "STATUS_GREEN", + icon: "CHECKMARK", text: "Updated" }, OUTDATED: { colorClass: "RED", backgroundColor: "STATUS_RED", + icon: "CLOSE", text: "Outdated" }, DOWNLOADABLE: { colorClass: "BRAND", backgroundColor: "BRAND", + icon: "DOWNLOAD", text: "Download" } }; @@ -100,7 +104,7 @@ module.exports = (_ => { DESC: "descending" }; - const pluginRepoIcon = ``; + const pluginRepoIcon = ``; const RepoListComponent = class PluginList extends BdApi.React.Component { componentDidMount() { @@ -134,12 +138,7 @@ module.exports = (_ => { if (!this.props.downloadable) plugins = plugins.filter(plugin => plugin.state != pluginStates.DOWNLOADABLE); if (this.props.searchString) { let searchString = this.props.searchString.toUpperCase(); - plugins = plugins.filter(plugin => plugin.search.indexOf(searchString) > -1).map(plugin => Object.assign({}, plugin, { - name: BDFDB.ReactUtils.elementToReact(BDFDB.DOMUtils.create(BDFDB.StringUtils.highlight(plugin.name, searchString))) || plugin.name, - version: BDFDB.ReactUtils.elementToReact(BDFDB.DOMUtils.create(BDFDB.StringUtils.highlight(plugin.version, searchString))) || plugin.version, - author: BDFDB.ReactUtils.elementToReact(BDFDB.DOMUtils.create(BDFDB.StringUtils.highlight(plugin.author, searchString))) || plugin.author, - description: BDFDB.ReactUtils.elementToReact(BDFDB.DOMUtils.create(BDFDB.StringUtils.highlight(plugin.description, searchString))) || plugin.description - })); + plugins = plugins.filter(plugin => plugin.search.indexOf(searchString) > -1); } BDFDB.ArrayUtils.keySort(plugins, (!this.props.sortKey || this.props.sortKey == "NEW" && !plugins.some(plugin => plugin.new == newStates.NEW) ? Object.keys(sortKeys)[0] : this.props.sortKey).toLowerCase()); @@ -226,6 +225,11 @@ module.exports = (_ => { render() { let buttonConfig = buttonData[(Object.entries(pluginStates).find(n => n[1] == this.props.plugin.state) || [])[0]]; return buttonConfig && BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.AddonCard, { + icon: BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SvgIcon, { + className: BDFDB.disCN._repoicon, + nativeClass: true, + iconSVG: `` + }), data: this.props.plugin, controls: [ this.props.plugin.new == newStates.NEW && BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.Badges.TextBadge, { @@ -246,7 +250,7 @@ module.exports = (_ => { BDFDB.DataUtils.save(favorites, _this, "favorites"); } }), - BDFDB.ReactUtils.createElement("div", { + !isBeta && BDFDB.ReactUtils.createElement("div", { className: BDFDB.disCN._repocontrolsbutton, children: BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.TooltipContainer, { text: "Go to Source", @@ -267,9 +271,72 @@ module.exports = (_ => { } }) }) - }), + }) ], - buttons: [ + links: isBeta && [{ + label: "Source", + icon: BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SvgIcon, { + name: BDFDB.LibraryComponents.SvgIcon.Names.GITHUB, + nativeClass: true, + width: 18, + height: 18 + }), + onClick: _ => { + let gitUrl = null; + if (this.props.plugin.url.indexOf("https://raw.githubusercontent.com") == 0) { + let temp = this.props.plugin.url.replace("//raw.githubusercontent", "//github").split("/"); + temp.splice(5, 0, "blob"); + gitUrl = temp.join("/"); + } + else if (this.props.plugin.url.indexOf("https://gist.githubusercontent.com/") == 0) { + gitUrl = this.props.plugin.url.replace("//gist.githubusercontent", "//gist.github").split("/raw/")[0]; + } + if (gitUrl) BDFDB.DiscordUtils.openLink(gitUrl, settings.useChromium); + } + }], + buttons: isBeta ? [ + this.props.plugin.state != pluginStates.DOWNLOADABLE && BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.TooltipContainer, { + text: BDFDB.LanguageUtils.LanguageStrings.DELETE, + children: BDFDB.ReactUtils.createElement("div", { + className: BDFDB.disCNS._repobutton + BDFDB.disCNS._repocontrolsbutton + BDFDB.disCN._repobuttondanger, + onClick: _ => { + _this.stopPlugin(this.props.plugin); + _this.deletePluginFile(this.props.plugin); + this.props.plugin.state = pluginStates.DOWNLOADABLE; + BDFDB.ReactUtils.forceUpdate(this); + }, + children: BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SvgIcon, { + name: BDFDB.LibraryComponents.SvgIcon.Names.TRASH, + nativeClass: true, + color: "#FFFFFF", + width: 20, + height: 20 + }) + }) + }), + BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.TooltipContainer, { + text: buttonConfig.text, + children: BDFDB.ReactUtils.createElement("div", { + className: BDFDB.disCNS._repobutton + BDFDB.disCN._repocontrolsbutton, + style: {backgroundColor: BDFDB.DiscordConstants.Colors[buttonConfig.backgroundColor]}, + onClick: _ => { + _this.downloadPlugin(this.props.plugin); + if (list && list.props.rnmStart) BDFDB.TimeUtils.timeout(_ => { + if (this.props.plugin.state == pluginStates.UPDATED) _this.startPlugin(this.props.plugin); + }, 3000); + this.props.plugin.state = pluginStates.UPDATED; + BDFDB.ReactUtils.forceUpdate(this); + }, + children: BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SvgIcon, { + name: BDFDB.LibraryComponents.SvgIcon.Names[buttonConfig.icon], + nativeClass: true, + color: "#FFFFFF", + width: 20, + height: 20 + }) + }) + }) + ] : [ this.props.plugin.state != pluginStates.DOWNLOADABLE && BDFDB.ReactUtils.createElement("div", { className: BDFDB.disCN._repocontrolsbutton, children: BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.TooltipContainer, { @@ -579,8 +646,7 @@ module.exports = (_ => { if (BDFDB.ArrayUtils.is(e.instance.props.sections) && e.instance.props.sections[0] && e.instance.props.sections[0].label == BDFDB.LanguageUtils.LanguageStrings.USER_SETTINGS) { e.instance.props.sections = e.instance.props.sections.filter(n => n.section != "pluginrepo"); let oldSettings = !e.instance.props.sections.find(n => n.section == "plugins"); - let search = oldSettings ? n => n.section == BDFDB.DiscordConstants.UserSettingsSections.DEVELOPER_OPTIONS : n => n.section == BDFDB.DiscordConstants.UserSettingsSections.CHANGE_LOG || n.section == "changelog" - let index = e.instance.props.sections.indexOf(e.instance.props.sections.find(search)); + let index = e.instance.props.sections.indexOf(e.instance.props.sections.find(oldSettings ? n => n.section == BDFDB.DiscordConstants.UserSettingsSections.DEVELOPER_OPTIONS : n => n.section == BDFDB.DiscordConstants.UserSettingsSections.CHANGE_LOG || n.section == "changelog")); if (index > -1) { e.instance.props.sections.splice(oldSettings ? index + 1 : index - 1, 0, { label: "Plugin Repo", @@ -644,7 +710,7 @@ module.exports = (_ => { if (loading.is && loading.amount < 4) BDFDB.TimeUtils.timeout(_ => {this.loadPlugins();},10000); loading = {is: false, timeout:null, amount:loading.amount}; } - },1200000), amount:loading.amount+1}; + }, 1200000), amount:loading.amount+1}; let loadingIcon = BDFDB.DOMUtils.create(pluginRepoIcon); BDFDB.DOMUtils.addClass(loadingIcon, "pluginrepo-loadingicon"); @@ -683,7 +749,7 @@ module.exports = (_ => { type: "danger", btn: "PluginRepo", selector: "pluginrepo-notice pluginrepo-outdate-notice", - customicon: pluginRepoIcon.replace(/#7289da/gi, "#FFF").replace(/#7f8186/gi, "#B9BBBE") + customicon: pluginRepoIcon.replace(/#7289da/gi, "#FFF").replace(/#72767d/gi, "#B9BBBE") }); bar.querySelector(BDFDB.dotCN.noticebutton).addEventListener("click", _ => { showOnlyOutdated = true; @@ -700,7 +766,7 @@ module.exports = (_ => { type: "success", btn: "PluginRepo", selector: "pluginrepo-notice pluginrepo-newentries-notice", - customicon: pluginRepoIcon.replace(/#7289da/gi, "#FFF").replace(/#7f8186/gi, "#B9BBBE") + customicon: pluginRepoIcon.replace(/#7289da/gi, "#FFF").replace(/#72767d/gi, "#B9BBBE") }); bar.querySelector(BDFDB.dotCN.noticebutton).addEventListener("click", _ => { forcedSort = "NEW"; @@ -718,7 +784,7 @@ module.exports = (_ => { type: "danger", btn: "List", selector: "pluginrepo-notice pluginrepo-fail-notice", - customicon: pluginRepoIcon.replace(/#7289da/gi, "#FFF").replace(/#7f8186/gi, "#B9BBBE") + customicon: pluginRepoIcon.replace(/#7289da/gi, "#FFF").replace(/#72767d/gi, "#B9BBBE") }); bar.querySelector(BDFDB.dotCN.noticebutton).addEventListener("click", e => { let toast = BDFDB.NotificationUtils.toast(wrongUrls.join("\n"), {type: "error"}); @@ -785,7 +851,7 @@ module.exports = (_ => { 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(/\\n/g, "
").replace(/\\/g, ""); + result = result.slice(1, -1).join(separator).replace(/\\n/g, "\n").replace(/\\/g, ""); result = tag != "getVersion" ? result.charAt(0).toUpperCase() + result.slice(1) : result; plugin[tag] = result ? result.trim() : result; } diff --git a/Plugins/ThemeRepo/ThemeRepo.plugin.js b/Plugins/ThemeRepo/ThemeRepo.plugin.js index 4cd2a825b3..4728e4d997 100644 --- a/Plugins/ThemeRepo/ThemeRepo.plugin.js +++ b/Plugins/ThemeRepo/ThemeRepo.plugin.js @@ -14,7 +14,7 @@ module.exports = (_ => { "info": { "name": "ThemeRepo", "author": "DevilBro", - "version": "2.0.9", + "version": "2.1.0", "description": "Allow you to preview all themes from the theme repo and download them on the fly" }, "changeLog": { @@ -51,6 +51,7 @@ module.exports = (_ => { start() {this.load();} stop() {} } : (([Plugin, BDFDB]) => { + const isBeta = !(window.BdApi && !Array.isArray(BdApi.settings)); var _this; var loading, cachedThemes, grabbedThemes, foundThemes, loadedThemes, generatorThemes, updateInterval; var list, header, preview, searchTimeout, updateGeneratorTimeout, forceRerenderGenerator, nativeCSS, nativeCSSvars, forcedSort, forcedOrder, showOnlyOutdated; @@ -65,16 +66,19 @@ module.exports = (_ => { UPDATED: { colorClass: "GREEN", backgroundColor: "STATUS_GREEN", + icon: "CHECKMARK", text: "Updated" }, OUTDATED: { colorClass: "RED", backgroundColor: "STATUS_RED", + icon: "CLOSE", text: "Outdated" }, DOWNLOADABLE: { colorClass: "BRAND", backgroundColor: "BRAND", + icon: "DOWNLOAD", text: "Download" } }; @@ -100,7 +104,7 @@ module.exports = (_ => { DESC: "descending" }; - const themeRepoIcon = ``; + const themeRepoIcon = ``; const RepoListComponent = class ThemeList extends BdApi.React.Component { componentDidMount() { @@ -125,7 +129,6 @@ module.exports = (_ => { else theme.state = themeStates.DOWNLOADABLE; return { url: theme.url, - requestUrl: theme.requestUrl, search: (theme.name + " " + theme.version + " " + theme.author + " " + theme.description).toUpperCase(), name: theme.name, version: theme.version, @@ -143,12 +146,7 @@ module.exports = (_ => { if (!this.props.downloadable) themes = themes.filter(theme => theme.state != themeStates.DOWNLOADABLE); if (this.props.searchString) { let searchString = this.props.searchString.toUpperCase(); - themes = themes.filter(theme => theme.search.indexOf(searchString) > -1).map(theme => Object.assign({}, theme, { - name: BDFDB.ReactUtils.elementToReact(BDFDB.DOMUtils.create(BDFDB.StringUtils.highlight(theme.name, searchString))) || theme.name, - version: BDFDB.ReactUtils.elementToReact(BDFDB.DOMUtils.create(BDFDB.StringUtils.highlight(theme.version, searchString))) || theme.version, - author: BDFDB.ReactUtils.elementToReact(BDFDB.DOMUtils.create(BDFDB.StringUtils.highlight(theme.author, searchString))) || theme.author, - description: BDFDB.ReactUtils.elementToReact(BDFDB.DOMUtils.create(BDFDB.StringUtils.highlight(theme.description, searchString))) || theme.description - })); + themes = themes.filter(theme => theme.search.indexOf(searchString) > -1); } BDFDB.ArrayUtils.keySort(themes, (!this.props.sortKey || this.props.sortKey == "NEW" && !themes.some(theme => theme.new == newStates.NEW) ? Object.keys(sortKeys)[0] : this.props.sortKey).toLowerCase()); @@ -495,6 +493,11 @@ module.exports = (_ => { render() { let buttonConfig = buttonData[(Object.entries(themeStates).find(n => n[1] == this.props.theme.state) || [])[0]]; return buttonConfig && BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.AddonCard, { + icon: BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SvgIcon, { + className: BDFDB.disCN._repoicon, + nativeClass: true, + iconSVG: `` + }), data: this.props.theme, controls: [ this.props.theme.new == newStates.NEW && BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.Badges.TextBadge, { @@ -515,7 +518,7 @@ module.exports = (_ => { BDFDB.DataUtils.save(favorites, _this, "favorites"); } }), - BDFDB.ReactUtils.createElement("div", { + !isBeta && BDFDB.ReactUtils.createElement("div", { className: BDFDB.disCN._repocontrolsbutton, children: BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.TooltipContainer, { text: "Go to Source", @@ -561,7 +564,70 @@ module.exports = (_ => { } }) ], - buttons: [ + links: isBeta && [{ + label: "Source", + icon: BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SvgIcon, { + name: BDFDB.LibraryComponents.SvgIcon.Names.GITHUB, + nativeClass: true, + width: 18, + height: 18 + }), + onClick: _ => { + let gitUrl = null; + if (this.props.theme.url.indexOf("https://raw.githubusercontent.com") == 0) { + let temp = this.props.theme.url.replace("//raw.githubusercontent", "//github").split("/"); + temp.splice(5, 0, "blob"); + gitUrl = temp.join("/"); + } + else if (this.props.theme.url.indexOf("https://gist.githubusercontent.com/") == 0) { + gitUrl = this.props.theme.url.replace("//gist.githubusercontent", "//gist.github").split("/raw/")[0]; + } + if (gitUrl) BDFDB.DiscordUtils.openLink(gitUrl, settings.useChromium); + } + }], + buttons: isBeta ? [ + this.props.theme.state != themeStates.DOWNLOADABLE && BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.TooltipContainer, { + text: BDFDB.LanguageUtils.LanguageStrings.DELETE, + children: BDFDB.ReactUtils.createElement("div", { + className: BDFDB.disCNS._repobutton + BDFDB.disCNS._repocontrolsbutton + BDFDB.disCN._repobuttondanger, + onClick: _ => { + _this.removeTheme(this.props.theme); + _this.deleteThemeFile(this.props.theme); + this.props.theme.state = themeStates.DOWNLOADABLE; + BDFDB.ReactUtils.forceUpdate(this); + }, + children: BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SvgIcon, { + name: BDFDB.LibraryComponents.SvgIcon.Names.TRASH, + nativeClass: true, + color: "#FFFFFF", + width: 20, + height: 20 + }) + }) + }), + BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.TooltipContainer, { + text: buttonConfig.text, + children: BDFDB.ReactUtils.createElement("div", { + className: BDFDB.disCNS._repobutton + BDFDB.disCN._repocontrolsbutton, + style: {backgroundColor: BDFDB.DiscordConstants.Colors[buttonConfig.backgroundColor]}, + onClick: _ => { + _this.downloadTheme(this.props.theme); + if (list && list.props.rnmStart) BDFDB.TimeUtils.timeout(_ => { + if (this.props.theme.state == themeStates.UPDATED) _this.applyTheme(this.props.theme); + }, 3000); + this.props.theme.state = themeStates.UPDATED; + BDFDB.ReactUtils.forceUpdate(this); + }, + children: BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SvgIcon, { + name: BDFDB.LibraryComponents.SvgIcon.Names[buttonConfig.icon], + nativeClass: true, + color: "#FFFFFF", + width: 20, + height: 20 + }) + }) + }) + ] : [ this.props.theme.state != themeStates.DOWNLOADABLE && BDFDB.ReactUtils.createElement("div", { className: BDFDB.disCN._repocontrolsbutton, children: BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.TooltipContainer, { @@ -869,11 +935,11 @@ module.exports = (_ => { } processSettingsView (e) { - if (BDFDB.ArrayUtils.is(e.instance.props.sections) && e.instance.props.sections[0] && e.instance.props.sections[0].label == BDFDB.LanguageUtils.LanguageStrings.USER_SETTINGS && !e.instance.props.sections.find(n => n.section == "themerepo")) { + if (BDFDB.ArrayUtils.is(e.instance.props.sections) && e.instance.props.sections[0] && e.instance.props.sections[0].label == BDFDB.LanguageUtils.LanguageStrings.USER_SETTINGS) { + e.instance.props.sections = e.instance.props.sections.filter(n => n.section != "themerepo"); let oldSettings = !e.instance.props.sections.find(n => n.section == "themes"); let isPRinjected = oldSettings && e.instance.props.sections.find(n => n.section == "pluginrepo"); - let search = oldSettings ? (isPRinjected ? n => n.section == "pluginrepo" : n => n.section == BDFDB.DiscordConstants.UserSettingsSections.DEVELOPER_OPTIONS) : n => n.section == BDFDB.DiscordConstants.UserSettingsSections.CHANGE_LOG || n.section == "changelog" - let index = e.instance.props.sections.indexOf(e.instance.props.sections.find(search)); + let index = e.instance.props.sections.indexOf(e.instance.props.sections.find(oldSettings ? (isPRinjected ? n => n.section == "pluginrepo" : n => n.section == BDFDB.DiscordConstants.UserSettingsSections.DEVELOPER_OPTIONS) : n => n.section == BDFDB.DiscordConstants.UserSettingsSections.CHANGE_LOG || n.section == "changelog")); if (index > -1) { e.instance.props.sections.splice(oldSettings ? index + 1 : index - 1, 0, { label: "Theme Repo", @@ -940,7 +1006,7 @@ module.exports = (_ => { loadThemes () { BDFDB.DOMUtils.remove(".themerepo-loadingicon"); - let getThemeInfo, outdated = 0, newEntries = 0, i = 0, NFLDreplace = null; + let getThemeInfo, outdated = 0, newEntries = 0, i = 0; let tags = ["name", "description", "author", "version"]; let newEntriesData = BDFDB.DataUtils.load(this, "newentriesdata"); cachedThemes = (newEntriesData.urlbase64 ? atob(newEntriesData.urlbase64).split("\n") : []).concat(customList); @@ -948,112 +1014,107 @@ module.exports = (_ => { if (!error && body) { body = body.replace(/[\r\t]/g, ""); BDFDB.DataUtils.save(btoa(body), this, "newentriesdata", "urlbase64"); + loadedThemes = {}; grabbedThemes = body.split("\n").filter(n => n); - BDFDB.LibraryRequires.request("https://github.com/NFLD99/Better-Discord", (error2, response2, body2) => { - if (!error2 && body2) { - NFLDreplace = /\/NFLD99\/Better-Discord\/tree\/master\/Themes_[^"]+">([^<]+)/i.exec(body2); - NFLDreplace = NFLDreplace && NFLDreplace.length > 1 ? NFLDreplace[1] : null; + foundThemes = grabbedThemes.concat(customList); + + loading = {is:true, timeout:BDFDB.TimeUtils.timeout(_ => { + BDFDB.TimeUtils.clear(loading.timeout); + if (this.started) { + if (loading.is && loading.amount < 4) BDFDB.TimeUtils.timeout(_ => {this.loadThemes();}, 10000); + loading = {is: false, timeout:null, amount:loading.amount}; } - foundThemes = grabbedThemes.concat(customList); - - loading = {is:true, timeout:BDFDB.TimeUtils.timeout(_ => { - BDFDB.TimeUtils.clear(loading.timeout); - if (this.started) { - if (loading.is && loading.amount < 4) BDFDB.TimeUtils.timeout(_ => {this.loadThemes();}, 10000); - loading = {is: false, timeout:null, amount:loading.amount}; - } - },1200000), amount:loading.amount+1}; - - let loadingicon = BDFDB.DOMUtils.create(themeRepoIcon); - BDFDB.DOMUtils.addClass(loadingicon, "themerepo-loadingicon"); - loadingicon.addEventListener("mouseenter", _ => { - BDFDB.TooltipUtils.create(loadingicon, this.getLoadingTooltipText(), { - type: "left", - delay: 500, - style: "max-width: unset;", - selector: "themerepo-loading-tooltip" - }); + }, 1200000), amount:loading.amount+1}; + + let loadingIcon = BDFDB.DOMUtils.create(themeRepoIcon); + BDFDB.DOMUtils.addClass(loadingIcon, "themerepo-loadingicon"); + loadingIcon.addEventListener("mouseenter", _ => { + BDFDB.TooltipUtils.create(loadingIcon, this.getLoadingTooltipText(), { + type: "left", + delay: 500, + style: "max-width: unset;", + selector: "themerepo-loading-tooltip" }); - BDFDB.PluginUtils.addLoadingIcon(loadingicon); + }); + BDFDB.PluginUtils.addLoadingIcon(loadingIcon); - getThemeInfo(_ => { - if (!this.started) { - BDFDB.TimeUtils.clear(loading.timeout); - return; - } + getThemeInfo(_ => { + if (!this.started) { BDFDB.TimeUtils.clear(loading.timeout); - BDFDB.DOMUtils.remove(loadingicon, ".themerepo-loadingicon"); - loading = {is:false, timeout:null, amount:loading.amount}; - - BDFDB.LogUtils.log("Finished fetching Themes", this.name); - if (list) BDFDB.ReactUtils.forceUpdate(list); - - if ((settings.notifyOutdated || settings.notifyOutdated == undefined) && outdated > 0) { - let oldBarButton = document.querySelector(".themerepo-outdate-notice " + BDFDB.dotCN.noticedismiss); - if (oldBarButton) oldBarButton.click(); - let bar = BDFDB.NotificationUtils.notice(`${outdated} of your Themes ${outdated == 1 ? "is" : "are"} outdated. Check:`, { + return; + } + BDFDB.TimeUtils.clear(loading.timeout); + BDFDB.DOMUtils.remove(loadingIcon, ".themerepo-loadingicon"); + loading = {is:false, timeout:null, amount:loading.amount}; + + BDFDB.LogUtils.log("Finished fetching Themes", this.name); + if (list) BDFDB.ReactUtils.forceUpdate(list); + + if ((settings.notifyOutdated || settings.notifyOutdated == undefined) && outdated > 0) { + let oldBarButton = document.querySelector(".themerepo-outdate-notice " + BDFDB.dotCN.noticedismiss); + if (oldBarButton) oldBarButton.click(); + let bar = BDFDB.NotificationUtils.notice(`${outdated} of your Themes ${outdated == 1 ? "is" : "are"} outdated. Check:`, { + type: "danger", + btn: "ThemeRepo", + selector: "themerepo-notice themerepo-outdate-notice", + customicon: themeRepoIcon.replace(/#7289da/gi, "#FFF").replace(/#72767d/gi, "#B9BBBE") + }); + bar.querySelector(BDFDB.dotCN.noticebutton).addEventListener("click", _ => { + showOnlyOutdated = true; + BDFDB.LibraryModules.UserSettingsUtils.open("themerepo"); + bar.querySelector(BDFDB.dotCN.noticedismiss).click(); + }); + } + + if (settings.notifyNewEntries && newEntries > 0) { + let oldBarButton = document.querySelector(".themerepo-newentries-notice " + BDFDB.dotCN.noticedismiss); + if (oldBarButton) oldBarButton.click(); + let single = newEntries == 1; + let bar = BDFDB.NotificationUtils.notice(`There ${single ? "is" : "are"} ${newEntries} new Theme${single ? "" : "s"} in the Repo. Check:`, { + type: "success", + btn: "ThemeRepo", + selector: "themerepo-notice themerepo-newentries-notice", + customicon: themeRepoIcon.replace(/#7289da/gi, "#FFF").replace(/#72767d/gi, "#B9BBBE") + }); + bar.querySelector(BDFDB.dotCN.noticebutton).addEventListener("click", _ => { + forcedSort = "NEW"; + forcedOrder = "ASC"; + BDFDB.LibraryModules.UserSettingsUtils.open("themerepo"); + bar.querySelector(BDFDB.dotCN.noticedismiss).click(); + }); + } + + if (BDFDB.UserUtils.me.id == "278543574059057154") { + let wrongUrls = []; + for (let url of foundThemes) if (url && !loadedThemes[url] && !wrongUrls.includes(url)) wrongUrls.push(url); + if (wrongUrls.length) { + let bar = BDFDB.NotificationUtils.notice(`ThemeRepo: ${wrongUrls.length} Theme${wrongUrls.length > 1 ? "s" : ""} could not be loaded.`, { type: "danger", - btn: "ThemeRepo", - selector: "themerepo-notice themerepo-outdate-notice", - customicon: themeRepoIcon.replace(/#7289da/gi, "#FFF").replace(/#7f8186/gi, "#B9BBBE") + btn: "List", + selector: "themerepo-notice themerepo-fail-notice", + customicon: themeRepoIcon.replace(/#7289da/gi, "#FFF").replace(/#72767d/gi, "#B9BBBE") }); - bar.querySelector(BDFDB.dotCN.noticebutton).addEventListener("click", _ => { - showOnlyOutdated = true; - BDFDB.LibraryModules.UserSettingsUtils.open("themerepo"); - bar.querySelector(BDFDB.dotCN.noticedismiss).click(); + bar.querySelector(BDFDB.dotCN.noticebutton).addEventListener("click", e => { + let toast = BDFDB.NotificationUtils.toast(wrongUrls.join("\n"), {type: "error"}); + toast.style.setProperty("overflow", "hidden"); + for (let url of wrongUrls) console.log(url); }); } - - if (settings.notifyNewEntries && newEntries > 0) { - let oldBarButton = document.querySelector(".themerepo-newentries-notice " + BDFDB.dotCN.noticedismiss); - if (oldBarButton) oldBarButton.click(); - let single = newEntries == 1; - let bar = BDFDB.NotificationUtils.notice(`There ${single ? "is" : "are"} ${newEntries} new Theme${single ? "" : "s"} in the Repo. Check:`, { - type: "success", - btn: "ThemeRepo", - selector: "themerepo-notice themerepo-newentries-notice", - customicon: themeRepoIcon.replace(/#7289da/gi, "#FFF").replace(/#7f8186/gi, "#B9BBBE") - }); - bar.querySelector(BDFDB.dotCN.noticebutton).addEventListener("click", _ => { - forcedSort = "NEW"; - forcedOrder = "ASC"; - BDFDB.LibraryModules.UserSettingsUtils.open("themerepo"); - bar.querySelector(BDFDB.dotCN.noticedismiss).click(); - }); + } + + BDFDB.LibraryRequires.request("https://mwittrien.github.io/BetterDiscordAddons/Plugins/ThemeRepo/_res/GeneratorList.txt", (error3, response3, body3) => { + if (!error3 && body3) for (let url of body3.replace(/[\r\t]/g, "").split("\n").filter(n => n)) if (loadedThemes[url]) generatorThemes.push(url); + }); + + BDFDB.LibraryRequires.request(document.querySelector("head link[rel='stylesheet'][integrity]").href, (error3, response3, body3) => { + if (!error3 && body3) { + nativeCSS = body3; + let theme = BDFDB.DiscordUtils.getTheme(); + let vars = (nativeCSS.split(`.${theme}{`)[1] || "").split("}")[0]; + nativeCSSvars = vars ? `.theme-dark, .theme-light {${vars}}` : ""; } - - if (BDFDB.UserUtils.me.id == "278543574059057154") { - let wrongUrls = []; - for (let url of foundThemes) if (url && !loadedThemes[url] && !wrongUrls.includes(url)) wrongUrls.push(url); - if (wrongUrls.length) { - let bar = BDFDB.NotificationUtils.notice(`ThemeRepo: ${wrongUrls.length} Theme${wrongUrls.length > 1 ? "s" : ""} could not be loaded.`, { - type: "danger", - btn: "List", - selector: "themerepo-notice themerepo-fail-notice", - customicon: themeRepoIcon.replace(/#7289da/gi, "#FFF").replace(/#7f8186/gi, "#B9BBBE") - }); - bar.querySelector(BDFDB.dotCN.noticebutton).addEventListener("click", e => { - let toast = BDFDB.NotificationUtils.toast(wrongUrls.join("\n"), {type: "error"}); - toast.style.setProperty("overflow", "hidden"); - for (let url of wrongUrls) console.log(url); - }); - } - } - - BDFDB.LibraryRequires.request("https://mwittrien.github.io/BetterDiscordAddons/Plugins/ThemeRepo/_res/GeneratorList.txt", (error3, response3, body3) => { - if (!error3 && body3) for (let url of body3.replace(/[\r\t]/g, "").split("\n").filter(n => n)) if (loadedThemes[url]) generatorThemes.push(url); - }); - - BDFDB.LibraryRequires.request(document.querySelector("head link[rel='stylesheet'][integrity]").href, (error3, response3, body3) => { - if (!error3 && body3) { - nativeCSS = body3; - let theme = BDFDB.DiscordUtils.getTheme(); - let vars = (nativeCSS.split(`.${theme}{`)[1] || "").split("}")[0]; - nativeCSSvars = vars ? `.theme-dark, .theme-light {${vars}}` : ""; - } - else nativeCSS = nativeCSSvars = ""; - }); + else nativeCSS = nativeCSSvars = ""; }); }); } @@ -1065,8 +1126,7 @@ module.exports = (_ => { return; } let url = foundThemes[i]; - let requestUrl = NFLDreplace && url.includes("NFLD99/Better-Discord/master/Themes") ? url.replace("master/Themes", "master/" + NFLDreplace) : url; - BDFDB.LibraryRequires.request(requestUrl, (error, response, body) => { + BDFDB.LibraryRequires.request(url, (error, response, body) => { if (!response) { if (url && BDFDB.ArrayUtils.getAllIndexes(foundThemes, url).length < 2) foundThemes.push(url); } @@ -1102,7 +1162,6 @@ module.exports = (_ => { theme.fullCSS = text; theme.css = hasMETAline < 20 && hasMETAline > -1 ? text.split("\n").slice(1).join("\n").replace(/[\r|\n|\t]/g, "") : text.replace(/[\r|\n|\t]/g, ""); theme.url = url; - theme.requestUrl = requestUrl; loadedThemes[url] = theme; let instTheme = BDFDB.BDUtils.getTheme(theme.name); if (instTheme && instTheme.author && instTheme.author.toUpperCase() == theme.author.toUpperCase() && instTheme.version != theme.version) outdated++; @@ -1134,9 +1193,9 @@ module.exports = (_ => { } downloadTheme (data) { - BDFDB.LibraryRequires.request(data.requestUrl, (error, response, body) => { + BDFDB.LibraryRequires.request(data.url, (error, response, body) => { if (error) BDFDB.NotificationUtils.toast(`Unable to download Theme "${data.name}".`, {type:"danger"}); - else this.createThemeFile(data.requestUrl.split("/").pop(), body); + else this.createThemeFile(data.url.split("/").pop(), body); }); } @@ -1157,7 +1216,7 @@ module.exports = (_ => { } deleteThemeFile (data) { - let filename = data.requestUrl.split("/").pop(); + let filename = data.url.split("/").pop(); BDFDB.LibraryRequires.fs.unlink(BDFDB.LibraryRequires.path.join(BDFDB.BDUtils.getThemesFolder(), filename), (error) => { if (error) BDFDB.NotificationUtils.toast(`Unable to delete Theme "${filename}".`, {type:"danger"}); else BDFDB.NotificationUtils.toast(`Successfully deleted Theme "${filename}".`);