module.exports = (Plugin, Api, Vendor) => { if (!global.BDFDB || typeof BDFDB != "object") global.BDFDB = {myPlugins:{}, BDv2Api: Api}; return class extends Plugin { initConstructor () { this.patchModules = { "HeaderBar":["componentDidMount","componentDidUpdate"], "StandardSidebarView":["componentDidMount","componentWillUnmount"], "AuthWrapper":["componentDidMount","componentWillUnmount"] }; this.patched = false; this.css = ` body.hidden-by-OTB .bd-settings-button, body.hidden-by-OTB .bd-settings { top: 0 !important; } .hidden-by-OTB ${BDFDB.dotCN.titlebar}, .hidden-by-OTB ${BDFDB.dotCN.titlebar} + ${BDFDB.dotCNS.app + BDFDB.dotCN.splashbackground}:before { display: none !important; } body:not(.settingsTitlebarOTB-added) ${BDFDB.dotCN.channelheaderheaderbardrag} { -webkit-app-region: drag !important; } ${BDFDB.dotCN.channelheaderheaderbardrag} *, ${BDFDB.dotCN.contextmenu} * { -webkit-app-region: no-drag !important; } .settingsTitlebarOTB { position: relative; z-index: 1000; text-align: right; padding: 10px; -webkit-app-region: drag; }`; this.dividerMarkup = `
`; this.reloadButtonMarkup = ` `; this.minButtonMarkup = ` `; this.maxButtonMarkup = ` `; this.maxButtonInnerMin = ``; this.maxButtonInnerMax = ``; this.closeButtonMarkup = ` `; this.defaults = { settings: { displayNative: {value:!!document.querySelector(".platform-linux"), description:"Displays the native Title Bar."}, addOldBar: {value:true, description:"Displays the Title Bar in the old fashion."}, addToSettings: {value:true, description:"Adds a Title Bar to Settings Windows."}, reloadButton: {value:false, description:"Adds a Reload Button to the Title Bar."} } }; } onStart () { if (global.BDFDB && global.BDFDB.myPlugins && typeof global.BDFDB.myPlugins == "object") global.BDFDB.myPlugins[this.name] = this; var libraryScript = document.querySelector('head script[src="https://mwittrien.github.io/BetterDiscordAddons/Plugins/BDFDB.js"]'); if (!global.BDFDB || typeof BDFDB != "object" || performance.now() - BDFDB.creationTime > 600000) { if (libraryScript) libraryScript.remove(); libraryScript = document.createElement("script"); libraryScript.setAttribute("type", "text/javascript"); libraryScript.setAttribute("src", "https://mwittrien.github.io/BetterDiscordAddons/Plugins/BDFDB.js"); libraryScript.setAttribute("date", performance.now()); libraryScript.addEventListener("load", () => {if (global.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) this.initialize();}); document.head.appendChild(libraryScript); } else if (global.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) this.initialize(); this.startTimeout = setTimeout(() => {this.initialize();}, 30000); } initialize () { if (global.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) { if (this.started) return true; BDFDB.loadMessage(this); BDFDB.addEventListener(this, window, "resize", e => {this.changeMaximizeButtons();}); this.window = require("electron").remote.getCurrentWindow(); this.patchMainScreen(BDFDB.getData("displayNative", this, "settings")); BDFDB.addClass([document.body,document.querySelector(BDFDB.dotCN.titlebar)], "hidden-by-OTB"); BDFDB.WebModules.forceAllUpdates(this); return true; } else { console.error(`%c[${this.name}]%c`, 'color: #3a71c1; font-weight: 700;', '', 'Fatal Error: Could not load BD functions!'); return false; } } onStop () { if (global.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) { BDFDB.removeEles(".headerbarOTB", ".settingsTitlebarOTB"); BDFDB.removeClasses("hidden-by-OTB", "settingsTitlebarOTB-added"); BDFDB.unloadMessage(this); return true; } else { return false; } } // begin of own functions processHeaderBar (instance, wrapper) { this.addTitleBar(); } processStandardSidebarView (instance, wrapper, methodnames) { this.processAuthWrapper(instance, wrapper, methodnames); } processAuthWrapper (instance, wrapper, methodnames) { if (methodnames.includes("componentDidMount")) { this.addSettingsTitleBar(wrapper); } else if (methodnames.includes("componentWillUnmount")) { BDFDB.removeEles(".settingsTitlebarOTB"); BDFDB.removeClass(document.body, "settingsTitlebarOTB-added"); this.addTitleBar(); } } addTitleBar () { BDFDB.removeEles(".headerbarOTB"); var settings = BDFDB.getAllData(this, "settings"); if (BDFDB.getData("addOldBar", this, "settings")) { var headerbar = BDFDB.htmlToElement(``); this.createButtons(headerbar); let headerbaricon = document.querySelector(BDFDB.dotCNS.channelheaderheaderbardrag + BDFDB.dotCN.flex + " > " + BDFDB.dotCN.channelheadericonmargin); if (headerbaricon) headerbaricon.parentElement.appendChild(headerbar); this.changeMaximizeButtons(); } } addSettingsTitleBar (settingspane) { BDFDB.removeEles(".settingsTitlebarOTB"); if (BDFDB.getData("addToSettings", this, "settings")) { BDFDB.addClass(document.body, "settingsTitlebarOTB-added"); var settingsbar = BDFDB.htmlToElement(`
`); this.createButtons(settingsbar); settingspane.parentElement.appendChild(settingsbar); this.changeMaximizeButtons(); } } createButtons (bar) { var settings = BDFDB.containsClass(bar, "settingsTitlebarOTB"); if (BDFDB.getData("reloadButton", this, "settings")) { if (!settings) bar.appendChild(BDFDB.htmlToElement(this.dividerMarkup)); var reloadbutton = BDFDB.htmlToElement(this.reloadButtonMarkup); bar.appendChild(reloadbutton); var reloadbuttonicon = reloadbutton.querySelector(BDFDB.dotCN.channelheadericon); reloadbuttonicon.addEventListener("click", () => {this.window.reload();}); reloadbuttonicon.addEventListener("mouseenter", e => { BDFDB.createTooltip("Reload", reloadbuttonicon, {type:"bottom",selector:"reload-button-tooltip"}); }); } if (!settings) bar.appendChild(BDFDB.htmlToElement(this.dividerMarkup)); var minbutton = BDFDB.htmlToElement(this.minButtonMarkup); bar.appendChild(minbutton); minbutton.querySelector(BDFDB.dotCN.channelheadericon).addEventListener("click", () => {this.window.minimize();}); var maxbutton = BDFDB.htmlToElement(this.maxButtonMarkup); bar.appendChild(maxbutton); maxbutton.querySelector(BDFDB.dotCN.channelheadericon).addEventListener("click", () => { if (this.window.isMaximized()) this.window.unmaximize(); else this.window.maximize(); this.changeMaximizeButtons(); }); var closebutton = BDFDB.htmlToElement(this.closeButtonMarkup); bar.appendChild(closebutton); closebutton.querySelector(BDFDB.dotCN.channelheadericon).addEventListener("click", () => {this.window.close();}); } changeMaximizeButtons () { var innerHTML = this.window.isMaximized() ? this.maxButtonInnerMax : this.maxButtonInnerMin; document.querySelectorAll(".maxButtonOTB g").forEach(g => {g.innerHTML = innerHTML;}); } patchMainScreen (enable) { if (BdApi.getWindowPreference("frame") != enable) { BdApi.setWindowPreference("frame", enable); return true; } return false; } getSettingsPanel () { if (!global.BDFDB || typeof BDFDB != "object" || !BDFDB.loaded || !this.started) return; var settings = BDFDB.getAllData(this, "settings"); var settingshtml = `
${this.name}
`; for (let key in settings) { settingshtml += `

${this.defaults.settings[key].description}

`; } settingshtml += `
`; let settingspanel = BDFDB.htmlToElement(settingshtml); BDFDB.initElements(settingspanel, this); BDFDB.addEventListener(this, settingspanel, "click", ".nativetitlebar-switch", e => { if (this.patchMainScreen(e.currentTarget.checked)) { this.patched = !this.patched; let notifybar = document.querySelector("#OldTitleBarNotifyBar"); if (notifybar) notifybar.querySelector(BDFDB.dotCN.noticedismiss).click(); if (this.patched) { notifybar = BDFDB.createNotificationsBar("Changed nativebar settings, relaunch to see changes:", {type:"danger",btn:"Relaunch",id:"OldTitleBarNotifyBar"}); notifybar.querySelector(BDFDB.dotCN.noticebutton).addEventListener("click", () => { let app = require("electron").remote.app; app.relaunch(); app.quit(); }); } } }); return settingspanel; } onSettingsClosed () { if (this.SettingsUpdated) { delete this.SettingsUpdated; this.addTitleBar(); } } } };