//META{"name":"OldTitleBar"}*//
class OldTitleBar {
initConstructor () {
this.patched = false;
this.css = `
.hidden-by-OTB ${BDFDB.dotCN.titlebar},
.hidden-by-OTB ${BDFDB.dotCN.titlebar} + ${BDFDB.dotCNS.app + BDFDB.dotCN.splashbackground}:before {
display: none !important;
}
${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.maxButtonIsMaxMarkup =
``;
this.maxButtonIsMinMarkup =
``;
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."}
}
};
}
getName () {return "OldTitleBar";}
getDescription () {return "Reverts the title bar back to its former self.";}
getVersion () {return "1.4.9";}
getAuthor () {return "DevilBro";}
getSettingsPanel () {
if (!this.started || typeof BDFDB !== "object") return;
var settings = BDFDB.getAllData(this, "settings");
var settingshtml = `${this.getName()}
`;
for (let key in settings) {
settingshtml += `
`;
}
settingshtml += `
`;
var settingspanel = $(settingshtml)[0];
BDFDB.initElements(settingspanel);
$(settingspanel)
.on("click", BDFDB.dotCN.switchinner, (e) => {this.updateSettings(settingspanel, e.currentTarget.value);});
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);
this.window = require("electron").remote.getCurrentWindow();
var observer = null;
observer = new MutationObserver((changes, _) => {
changes.forEach(
(change, i) => {
if (change.addedNodes) {
change.addedNodes.forEach((node) => {
setImmediate(() => {
if (node.tagName && node.classList && node.classList.contains(BDFDB.disCN.loginscreen)) {
this.addSettingsTitleBar(node);
}
});
});
}
}
);
});
BDFDB.addObserver(this, BDFDB.dotCN.app, {name:"loginScreenObserver",instance:observer}, {childList:true});
observer = new MutationObserver((changes, _) => {
changes.forEach(
(change, i) => {
if (change.addedNodes) {
change.addedNodes.forEach((node) => {
setImmediate(() => {
if (node.tagName && node.getAttribute("layer-id") || node.querySelector(BDFDB.dotCN.standardsidebarview)) {
this.addSettingsTitleBar(node);
}
});
});
}
if (change.removedNodes) {
change.removedNodes.forEach((node) => {
if (node.tagName && node.getAttribute("layer-id") || node.querySelector(BDFDB.dotCN.standardsidebarview)) {
this.removeTitleBar();
this.addTitleBar();
}
});
}
}
);
});
BDFDB.addObserver(this, BDFDB.dotCN.layers, {name:"settingsWindowObserver",instance:observer}, {childList:true});
$(window).on("resize." + this.getName(), (e) => {
this.changeMaximizeButton();
});
this.addTitleBar();
this.patchMainScreen(BDFDB.getData("displayNative", this, "settings"));
$(document.body).addClass("hidden-by-OTB");
$(BDFDB.dotCN.titlebar).addClass("hidden-by-OTB");
var settingswindow = document.querySelector(BDFDB.dotCN.layer + "[layer-id]");
if (settingswindow) this.addSettingsTitleBar(settingswindow);
}
else {
console.error(this.getName() + ": Fatal Error: Could not load BD functions!");
}
}
stop () {
if (typeof BDFDB === "object") {
this.removeTitleBar();
$(".hidden-by-OTB").removeClass("hidden-by-OTB");
BDFDB.unloadMessage(this);
}
}
onSwitch () {
if (typeof BDFDB === "object") {
setImmediate(() => {this.addTitleBar();});
}
}
// begin of own functions
updateSettings (settingspanel, key) {
var settings = {};
for (var input of settingspanel.querySelectorAll(BDFDB.dotCN.switchinner)) {
settings[input.value] = input.checked;
}
BDFDB.saveAllData(settings, this, "settings");
if (key == "displayNative") {
if (this.patchMainScreen(settings[key])) {
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).on("click." + this.getName(), BDFDB.dotCN.noticebutton, (e) => {
this.doRelaunch();
});
}
}
}
}
addTitleBar () {
this.removeTitleBar();
var settings = BDFDB.getAllData(this, "settings");
if (!settings.addOldBar) return;
var container = $(BDFDB.dotCNS.channelheaderheaderbardrag + BDFDB.dotCN.flex + " > " + BDFDB.dotCN.channelheadericonmargin).parent();
if (settings.reloadButton) {
container
.append(this.dividerMarkup)
.append(this.reloadButtonMarkup)
.on("click." + this.getName(), ".reloadButtonOTB", () => {
this.doReload();
})
.on("mouseenter." + this.getName(), ".reloadButtonOTB", (e) => {
this.createReloadToolTip(e);
});
}
container
.append(this.dividerMarkup)
.append(this.minButtonMarkup)
.append(this.isMaximized() ? this.maxButtonIsMaxMarkup : this.maxButtonIsMinMarkup)
.append(this.closeButtonMarkup)
.on("click." + this.getName(), ".minButtonOTB", () => {
this.doMinimize();
})
.on("click." + this.getName(), ".maxButtonOTB", () => {
this.doMaximize();
})
.on("click." + this.getName(), ".closeButtonOTB", () => {
this.doClose();
});
}
addSettingsTitleBar (settingspane) {
var settings = BDFDB.getAllData(this, "settings");
if (settings.addToSettings && !settingspane.querySelector(".dividerOTB, .reloadButtonOTB, .minButtonOTB, .maxButtonOTB, .closeButtonOTB")) {
var settingsbar = $(``);
if (settings.reloadButton) {
settingsbar
.append(this.reloadButtonMarkup)
.on("click." + this.getName(), ".reloadButtonOTB", () => {
this.doReload();
})
.on("mouseenter." + this.getName(), ".reloadButtonOTB", (e) => {
this.createReloadToolTip(e);
});
}
settingsbar
.append(this.minButtonMarkup)
.append(this.isMaximized() ? this.maxButtonIsMaxMarkup : this.maxButtonIsMinMarkup)
.append(this.closeButtonMarkup)
.on("click." + this.getName(), ".minButtonOTB", () => {
this.doMinimize();
})
.on("click." + this.getName(), ".maxButtonOTB", () => {
this.doMaximize();
})
.on("click." + this.getName(), ".closeButtonOTB", () => {
this.doClose();
});
$(settingspane).append(settingsbar);
}
}
doReload () {
this.window.reload();
}
doMinimize () {
this.window.minimize();
}
doMaximize () {
if (this.isMaximized()) this.window.unmaximize();
else this.window.maximize();
this.changeMaximizeButton();
}
isMaximized () {
var pos = this.window.getPosition();
var size = this.window.getSize();
return (pos[0] == 0 && pos[1] == 0 && size[0] == global.window.screen.availWidth && size[1] == global.window.screen.availHeight);
}
doClose () {
this.window.close();
}
doRelaunch () {
var app = require("electron").remote.app;
app.relaunch();
app.quit();
}
changeMaximizeButton () {
var maxButtonHTML = this.isMaximized() ? this.maxButtonIsMaxMarkup : this.maxButtonIsMinMarkup;
document.querySelectorAll(".maxButtonOTB").forEach(maxButton => {
maxButton.outerHTML = maxButtonHTML;
});
}
removeTitleBar () {
$(".headerbarOTB, .settingsTitlebarOTB").remove();
var container = $(BDFDB.dotCNS.channelheaderheaderbardrag + BDFDB.dotCN.flex + " > " + BDFDB.dotCN.channelheadericonmargin).parent();
container
.off("click." + this.getName())
.off("mouseenter." + this.getName())
.find(".dividerOTB, .reloadButtonOTB, .minButtonOTB, .maxButtonOTB, .closeButtonOTB").remove();
}
createReloadToolTip (e) {
BDFDB.createTooltip("Reload", e.currentTarget, {type:"bottom",selector:"reload-button-tooltip"});
}
patchMainScreen (enable) {
if (BdApi.getWindowPreference("frame") != enable) {
BdApi.setWindowPreference("frame", enable);
return true;
}
return false;
}
}