From 32b76bde6cd5841874215a3c6513e8e7bf9db289 Mon Sep 17 00:00:00 2001 From: Mirco Wittrien Date: Thu, 22 Aug 2019 16:17:21 +0200 Subject: [PATCH] new FriendNotifications --- .../FriendNotifications.plugin.js | 372 ++++++++++----- Plugins/FriendNotifications/README.md | 2 +- Plugins/README.md | 3 +- Plugins/StalkerNotifications/README.md | 9 - .../StalkerNotifications.plugin.js | 430 ++++-------------- 5 files changed, 349 insertions(+), 467 deletions(-) delete mode 100644 Plugins/StalkerNotifications/README.md diff --git a/Plugins/FriendNotifications/FriendNotifications.plugin.js b/Plugins/FriendNotifications/FriendNotifications.plugin.js index 7b4b48f7a5..117ebc4911 100644 --- a/Plugins/FriendNotifications/FriendNotifications.plugin.js +++ b/Plugins/FriendNotifications/FriendNotifications.plugin.js @@ -3,22 +3,23 @@ class FriendNotifications { getName () {return "FriendNotifications";} - getVersion () {return "1.1.9";} + getVersion () {return "1.2.1";} getAuthor () {return "DevilBro";} - getDescription () {return "Notifies you when a friend either logs in or out. Click the Online Friend-Counter to display a timelog of the current session.";} + getDescription () {return "Notifies you when a Friend or a User your choose to observe changing his online status, can be configured individually in the settings.";} initConstructor () { this.changelog = { - "fixed":[["Missing Friend Counter","Falls back to a check interval if the Online Counter isn't rendered. Timelog can now also be viewed in the settings"]] + "improved":[["New Settings Interface","Completely new settings interface to more easily customize your notifications"],["New Options","You can now observe users for any kind of status changes (online, mobile, idle, dnd, streaming, offline)"],["Merged FriendNotifications and StalkerNotifications","Since both of these plugins now work the same, I decided to merge them. FriendNotifications will be continued and StalkerNotifications will be disconntinued. You can find the old StalkerNotifications settings in the FriendNotifications settings. All old configurations of FriendNotifications and StalkerNotifications should have been merged"]] }; this.patchModules = { - "FriendsOnline":["componentDidMount","componentDidUpdate"] + "FriendsOnline":"componentDidMount", + "StandardSidebarView":"componentWillUnmount" }; - this.friendsOnlineList = {}; + this.userStatusStore = {}; this.checkInterval = null; @@ -80,11 +81,6 @@ class FriendNotifications { background-position: center; border-radius: 50%; } - .${this.name}-settings .avatar-list { - display: flex; - align-items: center; - flex-wrap: wrap; - } .${this.name}-settings .type-toast, .${this.name}-settings .type-desktop { border-radius: 3px; padding: 0 3px; @@ -100,11 +96,11 @@ class FriendNotifications { } .${this.name}-settings .settings-avatar { margin: 5px; - width: 50px; - height: 50px; + width: 35px; + height: 35px; background-size: cover; background-position: center; - border: 5px solid #7289DA; + border: 3px solid #7289DA; border-radius: 50%; box-sizing: border-box; cursor: pointer; @@ -115,50 +111,102 @@ class FriendNotifications { .${this.name}-settings .settings-avatar.disabled { border-color: #36393F; filter: grayscale(100%) brightness(50%); + } + .${this.name}-settings .settings-avatar.disabled ~ * { + filter: grayscale(100%) brightness(50%); }`; this.defaults = { + configs: { + online: {value:true}, + mobile: {value:true}, + idle: {value:false}, + dnd: {value:false}, + streaming: {value:false}, + offline: {value:true} + }, settings: { muteOnDND: {value:false, description:"Do not notify me when I am DnD:"}, - onlyOnOnline: {value:false, description:"Only notify me when a User logs in:"}, openOnClick: {value:false, description:"Open the DM when you click a Notification:"} }, notificationsounds: { toastonline: {value:{url:null,song:null,mute:false}}, + toastmobile: {value:{url:null,song:null,mute:false}}, + toastidle: {value:{url:null,song:null,mute:false}}, + toastdnd: {value:{url:null,song:null,mute:false}}, + toaststreaming: {value:{url:null,song:null,mute:false}}, toastoffline: {value:{url:null,song:null,mute:false}}, desktoponline: {value:{url:null,song:null,mute:false}}, + desktopmobile: {value:{url:null,song:null,mute:false}}, + desktopidle: {value:{url:null,song:null,mute:false}}, + desktopdnd: {value:{url:null,song:null,mute:false}}, + desktopstreaming: {value:{url:null,song:null,mute:false}}, desktopoffline: {value:{url:null,song:null,mute:false}} + }, + amounts: { + checkInterval: {value:10, min:5, description:"Check Users every X seconds:"} } }; } getSettingsPanel () { if (!global.BDFDB || typeof BDFDB != "object" || !BDFDB.loaded || !this.started) return; + let settings = BDFDB.getAllData(this, "settings"); let notificationsounds = BDFDB.getAllData(this, "notificationsounds"); - let desktop = BDFDB.loadAllData(this, "desktop"); - let disabled = BDFDB.loadAllData(this, "disabled"); + let amounts = BDFDB.getAllData(this, "amounts"); + + let friendIDs = this.FriendUtils.getFriendIDs(); + let friends = BDFDB.loadAllData(this, "friends"); + let nonfriends = BDFDB.loadAllData(this, "nonfriends"); + let settingshtml = `
${this.name}
`; - for (let key in settings) { - settingshtml += `

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

`; - } - for (let key in notificationsounds) { - if (key.indexOf("desktop") == -1 || "Notification" in window) settingshtml += `
${key} notification sound:
Mute:
`; - } - settingshtml += `

Click on a Icon to toggle Notifications for that User:

`; - if ("Notification" in window) settingshtml += `

Rightclick on a Icon to toggle Notifications for that User:

`; - settingshtml += `
`; - for (let id of this.FriendUtils.getFriendIDs()) { + settingshtml += `
General Settings
`; + for (let key in settings) settingshtml += `

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

`; + for (let key in amounts) settingshtml += `

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

`; + settingshtml += `
`; + settingshtml += `
Friend-List
`; + settingshtml += `

Click on an Icon to toggle Notifications for that User:

`; + if ("Notification" in window) settingshtml += `

Rightclick on an Icon to toggle Notifications for that User:

`; + settingshtml += `

Click/Rightclick on the table headers to batch set all Friends

`; + settingshtml += `

TYPE
DISABLE

`; + for (let config in this.defaults.configs) settingshtml += `
${config.toUpperCase()}
`; + settingshtml += `
`; + for (let id of friendIDs) { let user = this.UserUtils.getUser(id); if (user) { - let data = BDFDB.loadData(user.id, "EditUsers", "users") || {}; - settingshtml += `
`; + let friend = friends[id] || (friends[id] = nonfriends[id] || this.createDefaultConfig()); + settingshtml += this.createHoverCard(user, friend, "friends"); } } settingshtml += `
`; - settingshtml += `

Batch set Users:

${"Notification" in window ? `` : ``}
`; + settingshtml += `
`; + settingshtml += `
Non-Friend-List
`; + settingshtml += `

Click on a Icon to toggle Notifications for that User:

`; + if ("Notification" in window) settingshtml += `

Rightclick on a Icon to toggle Notifications for that User:

`; + settingshtml += `

Click/Rightclick on the table headers to batch set all Non-Friends

`; + settingshtml += `

Add Non-Friend:

`; + settingshtml += `

TYPE
DISABLE

`; + for (let config in this.defaults.configs) settingshtml += `
${config.toUpperCase()}
`; + settingshtml += `
`; + for (let id in nonfriends) if (!friendIDs.includes(id)) { + let user = this.UserUtils.getUser(id); + if (user) { + let nonfriend = nonfriends[id] || (nonfriends[id] = this.createDefaultConfig()); + settingshtml += this.createHoverCard(user, nonfriend, "nonfriends"); + } + } + settingshtml += `
`; + settingshtml += `
`; + settingshtml += `
Timelog
`; settingshtml += `

Timelog of LogIns/-Outs:

`; + settingshtml += `
`; + settingshtml += `
Sound Settings
`; + for (let key in notificationsounds) if (key.indexOf("desktop") == -1 || "Notification" in window) settingshtml += `
${key} notification sound:
Mute:
`; + settingshtml += `
`; settingshtml += `
`; + + BDFDB.saveAllData(friends, this, "friends"); let settingspanel = BDFDB.htmlToElement(settingshtml); @@ -171,42 +219,55 @@ class FriendNotifications { notificationsound.mute = e.currentTarget.checked; BDFDB.saveData(option, notificationsound, this, "notificationsounds"); }); - BDFDB.addEventListener(this, settingspanel, "mouseenter", ".settings-avatar", e => { - let user = this.UserUtils.getUser(e.currentTarget.getAttribute("user-id")); - let data = BDFDB.loadData(user.id, "EditUsers", "users") || {}; - BDFDB.createTooltip(data.name ? data.name : user.username, e.currentTarget, {type:"top"}); + BDFDB.addEventListener(this, settingspanel, "click", ".settings-avatar", e => { + this.changeNotificationType(e.currentTarget, false, !BDFDB.containsClass(e.currentTarget, "disabled", "desktop", false)); }); BDFDB.addEventListener(this, settingspanel, "contextmenu", ".settings-avatar", e => { if (!("Notification" in window)) return; - let desktopoff = !BDFDB.containsClass(e.currentTarget, "desktop"); - let id = e.currentTarget.getAttribute("user-id"); - BDFDB.removeClass(e.currentTarget, "disabled"); - BDFDB.toggleClass(e.currentTarget, "desktop", desktopoff); - BDFDB.saveData(id, desktopoff, this, "desktop"); - BDFDB.removeData(id, this, "disabled"); + this.changeNotificationType(e.currentTarget, true, !(BDFDB.containsClass(e.currentTarget, "disabled") || !BDFDB.containsClass(e.currentTarget, "desktop"))); }); - BDFDB.addEventListener(this, settingspanel, "click", ".settings-avatar", e => { - let disableoff = !BDFDB.containsClass(e.currentTarget, "disabled"); - let id = e.currentTarget.getAttribute("user-id"); - BDFDB.removeClass(e.currentTarget, "desktop"); - BDFDB.toggleClass(e.currentTarget, "disabled", disableoff); - BDFDB.saveData(id, disableoff, this, "disabled"); - BDFDB.removeData(id, this, "desktop"); + BDFDB.addEventListener(this, settingspanel, "click", ".btn-batch", e => { + this.changeAllNotificationTypes(settingspanel, e.currentTarget, true); }); - BDFDB.addEventListener(this, settingspanel, "click", ".disable-all, .toast-all, .desktop-all", e => { - let disableon = e.currentTarget.getAttribute("do-disable"); - let desktopon = e.currentTarget.getAttribute("do-desktop"); - let disabledata = BDFDB.loadAllData(this, "disabled"); - let desktopdata = BDFDB.loadAllData(this, "desktop"); - settingspanel.querySelectorAll(".settings-avatar").forEach(avatar => { - let id = avatar.getAttribute("user-id"); - BDFDB.toggleClass(avatar, "disabled", disableon); - BDFDB.toggleClass(avatar, "desktop", desktopon); - disableon ? disabledata[id] = true : delete disabledata[id]; - desktopon ? desktopdata[id] = true : delete desktopdata[id]; - }); - BDFDB.saveAllData(disabledata, this, "disabled"); - BDFDB.saveAllData(desktopdata, this, "desktop"); + BDFDB.addEventListener(this, settingspanel, "contextmenu", ".btn-batch", e => { + this.changeAllNotificationTypes(settingspanel, e.currentTarget, false); + }); + BDFDB.addEventListener(this, settingspanel, "click", BDFDB.dotCN.checkboxinput, e => { + if (BDFDB.containsClass(e.target, "remove-user")) return; + this.changeNotificationConfig(e.currentTarget); + }); + BDFDB.addEventListener(this, settingspanel, "click", ".BDFDB-tableheadercolumn", e => { + this.changeAllNotificationConfigs(settingspanel, e.currentTarget, true); + }); + BDFDB.addEventListener(this, settingspanel, "contextmenu", ".BDFDB-tableheadercolumn", e => { + this.changeAllNotificationConfigs(settingspanel, e.currentTarget, false); + }); + BDFDB.addEventListener(this, settingspanel, "click", ".remove-user", e => { + let id = e.currentTarget.getAttribute("user-id"); + let group = e.currentTarget.getAttribute("group"); + if (id && group) { + BDFDB.removeData(id, this, group); + BDFDB.removeEles(BDFDB.getParentEle(BDFDB.dotCN.hovercard, e.currentTarget)); + } + }); + BDFDB.addEventListener(this, settingspanel, "click", ".btn-adduser", e => { + let idinput = settingspanel.querySelector("#input-userid"); + let id = idinput.value; + idinput.value = ""; + if (friendIDs.includes(id)) BDFDB.showToast("User is already a friend of yours. Please use the 'Friends' area to configure him/her.", {type:"error"}); + else if (BDFDB.loadData(id, this, "nonfriends")) BDFDB.showToast("User is already being observed as a 'Non-Friend'.", {type:"error"}); + else { + let user = this.UserUtils.getUser(id); + if (user) { + let data = this.createDefaultConfig(); + BDFDB.saveData(user.id, data, this, "nonfriends"); + let hovercard = BDFDB.htmlToElement(this.createHoverCard(user, data, "nonfriends")); + settingspanel.querySelector(".nonfriend-list").appendChild(hovercard); + BDFDB.initElements(hovercard); + } + else if (/.+#[0-9]{4}/.test(id)) BDFDB.showToast("A UserID does not consist of the username and discriminator.", {type:"error"}); + else BDFDB.showToast("Please enter a valid UserID of a user that has been loaded in your client.", {type:"error"}); + } }); BDFDB.addEventListener(this, settingspanel, "click", ".btn-timelog", () => {this.showTimeLog();}); @@ -257,11 +318,28 @@ class FriendNotifications { this.ChannelUtils = BDFDB.WebModules.findByProperties("getDMFromUserId"); this.ChannelSwitchUtils = BDFDB.WebModules.findByProperties("selectPrivateChannel"); this.PrivateChannelUtils = BDFDB.WebModules.findByProperties("openPrivateChannel"); - this.UserMetaStore = BDFDB.WebModules.findByProperties("getStatus", "getOnlineFriendCount"); - this.UserUtils = BDFDB.WebModules.findByProperties("getUsers"); - - for (let id of this.FriendUtils.getFriendIDs()) { - this.friendsOnlineList[id] = this.UserMetaStore.getStatus(id) != "offline"; + this.MobileUtils = BDFDB.WebModules.findByProperties("isMobileOnline"); + this.UserUtils = BDFDB.WebModules.findByProperties("getUsers", "getUsers"); + this.APIUtils = BDFDB.WebModules.findByProperties("getAPIBaseURL"); + this.DiscordConstants = BDFDB.WebModules.findByProperties("Permissions", "ActivityTypes", "StatusTypes"); + + /* REMOVE AFTER SOME TIME - 22.08.2019 */ + let oldFriendDataDesktop = BDFDB.loadAllData("FriendNotifications", "desktop"); + let oldFriendDataDisabled = BDFDB.loadAllData("FriendNotifications", "disabled"); + if (!BDFDB.isObjectEmpty(oldFriendDataDesktop) || !BDFDB.isObjectEmpty(oldFriendDataDisabled)) { + let friends = BDFDB.loadAllData(this, "friends") + for (let id in oldFriendDataDesktop) friends[id] = Object.assign(this.createDefaultConfig(), (friends[id] || {}), {desktop: oldFriendDataDesktop[id]}); + for (let id in oldFriendDataDisabled) friends[id] = Object.assign(this.createDefaultConfig(), (friends[id] || {}), {disabled: oldFriendDataDesktop[id]}); + BDFDB.saveAllData(friends, this, "friends"); + BDFDB.removeAllData("FriendNotifications", "desktop"); + BDFDB.removeAllData("FriendNotifications", "disabled"); + } + let oldStalkerData = BDFDB.loadAllData("StalkerNotifications", "users"); + if (!BDFDB.isObjectEmpty(oldStalkerData)) { + let nonfriends = BDFDB.loadAllData(this, "nonfriends") + for (let id in oldStalkerData) nonfriends[id] = Object.assign(this.createDefaultConfig(), oldStalkerData[id]); + BDFDB.saveAllData(nonfriends, this, "nonfriends"); + require("fs").unlinkSync(require("path").join(BDFDB.getPluginsFolder(), "StalkerNotifications.config.json")); } this.startInterval(); @@ -282,6 +360,73 @@ class FriendNotifications { // begin of own functions + + createHoverCard (user, data, group) { + let EUdata = BDFDB.loadData(user.id, "EditUsers", "users") || {}; + var hovercardhtml = `
${BDFDB.encodeToHTML(EUdata.name || user.username)}
`; + for (let config in this.defaults.configs) { + hovercardhtml += `
`; + } + return hovercardhtml + `
${group == "nonfriends" ? `
` : ''}
` + } + + changeNotificationType (avatar, desktopon, disableon) { + let id = avatar.getAttribute("user-id"); + let group = avatar.getAttribute("group"); + if (id && group) { + let data = BDFDB.loadData(id, this, group) || this.createDefaultConfig(); + data.desktop = desktopon; + data.disabled = disableon; + BDFDB.toggleClass(avatar, "desktop", desktopon); + BDFDB.toggleClass(avatar, "disabled", disableon); + BDFDB.saveData(id, data, this, group); + } + } + + changeAllNotificationTypes (settingspanel, tableheader, enable) { + let config = tableheader.getAttribute("config"); + let group = tableheader.getAttribute("group"); + if (config && group) { + let data = BDFDB.loadAllData(this, group); + if (config == "desktop") { + enable = !enable; + for (let id in data) data[id].disabled = false; + for (let avatar of settingspanel.querySelectorAll(`.settings-avatar[group="${group}"]`)) BDFDB.removeClass(avatar, "disabled"); + } + for (let id in data) data[id][config] = enable; + for (let avatar of settingspanel.querySelectorAll(`.settings-avatar[group="${group}"]`)) BDFDB.toggleClass(avatar, config, enable); + BDFDB.saveAllData(data, this, group); + } + } + + changeNotificationConfig (checkbox) { + let id = checkbox.getAttribute("user-id"); + let config = checkbox.getAttribute("config"); + let group = checkbox.getAttribute("group"); + if (id && config && group) { + let data = BDFDB.loadData(id, this, group) || this.createDefaultConfig(); + data[config] = checkbox.checked; + BDFDB.saveData(id, data, this, group); + } + } + + changeAllNotificationConfigs (settingspanel, tableheader, enable) { + let config = tableheader.getAttribute("config"); + let group = tableheader.getAttribute("group"); + if (config && group) { + let data = BDFDB.loadAllData(this, group); + for (let id in data) data[id][config] = enable; + BDFDB.saveAllData(data, this, group); + for (let checkbox of settingspanel.querySelectorAll(`${BDFDB.dotCN.checkboxinput}[config="${config}"][group="${group}"]`)) { + checkbox.checked = enable; + if (typeof checkbox.BDFDBupdateElement == "function") checkbox.BDFDBupdateElement(); + } + } + } + + createDefaultConfig () { + return Object.assign({desktop: false, disabled: false}, BDFDB.mapObject(this.defaults.configs, "value")); + } saveAudio (settingspanel, option) { let successSavedAudio = (parsedurl, parseddata) => { @@ -320,61 +465,62 @@ class FriendNotifications { processFriendsOnline (instance, wrapper) { BDFDB.addEventListener(this, wrapper, "mouseenter", () => {BDFDB.createTooltip("Timelog", wrapper, {type:"right"});}); BDFDB.addEventListener(this, wrapper, "click", () => {this.showTimeLog();}); - - clearInterval(this.checkInterval); + } - this.checkFriends(); + processStandardSidebarView (instance, wrapper) { + if (this.SettingsUpdated) { + delete this.SettingsUpdated; + this.startInterval(); + } } - checkFriends () { - let settings = BDFDB.getAllData(this, "settings"); - for (let id of this.FriendUtils.getFriendIDs()) { - let online = this.UserMetaStore.getStatus(id) != "offline"; - let user = this.UserUtils.getUser(id); - if (user && this.friendsOnlineList[id] != online && !BDFDB.loadData(id, this, "disabled")) { - this.timeLog.push({user, online, time: new Date()}); - if (!(settings.onlyOnOnline && !online) && !(settings.muteOnDND && BDFDB.getUserStatus() == "dnd")) { - let data = BDFDB.loadData(user.id, "EditUsers", "users") || {}; - let string = `${BDFDB.encodeToHTML(data.name ? data.name : user.username)} is ${online ? "online" : "offline"}.`; - let avatar = data.removeIcon ? "" : (data.url ? data.url : BDFDB.getUserAvatar(user.id)); - let openChannel = () => { - if (settings.openOnClick) { - let DMid = this.ChannelUtils.getDMFromUserId(user.id) - if (DMid) this.ChannelSwitchUtils.selectPrivateChannel(DMid); - else this.PrivateChannelUtils.openPrivateChannel(BDFDB.myData.id, user.id); - require("electron").remote.getCurrentWindow().maximize(); - } - }; - if (!BDFDB.loadData(id, this, "desktop")) { - let toast = BDFDB.showToast(`
${string}
`, {html:true, timeout:5000, type:(online ? "success" : null), icon:false, selector:`friendnotifications-${online ? "online" : "offline"}-toast`}); - toast.addEventListener("click", openChannel); - let notificationsound = BDFDB.getData(online ? "toastonline" : "toastoffline", this, "notificationsounds"); - if (!notificationsound.mute && notificationsound.song) { - let audio = new Audio(); - audio.src = notificationsound.song; - audio.play(); - } - } - else { - let notificationsound = BDFDB.getData(online ? "desktoponline" : "desktopoffline", this, "notificationsounds"); - BDFDB.showDesktopNotification(string, {icon:avatar, timeout:5000, click:openChannel, silent:notificationsound.mute, sound:notificationsound.song}); - } - } - } - this.friendsOnlineList[id] = online; - } + getStatusWithMobile (id) { + let status = BDFDB.getUserStatus(id); + return status == "online" && this.MobileUtils.isMobileOnline(id) ? "mobile" : status; } startInterval () { clearInterval(this.checkInterval); - let oldcount = this.UserMetaStore.getOnlineFriendCount(), newcount = 0; + let settings = BDFDB.getAllData(this, "settings"); + let users = Object.assign(BDFDB.loadAllData(this, "nonfriends"), BDFDB.loadAllData(this, "friends")); + for (let id in users) this.userStatusStore[id] = this.getStatusWithMobile(id); this.checkInterval = setInterval(() => { - newcount = this.UserMetaStore.getOnlineFriendCount(); - if (oldcount != newcount) { - oldcount = newcount; - this.checkFriends(); + for (let id in users) if (!users[id].disabled) { + let user = this.UserUtils.getUser(id); + let status = this.getStatusWithMobile(id); + if (user && this.userStatusStore[id] != status && users[id][status]) { + this.timeLog.push({user, status, time: new Date()}); + if (!(settings.muteOnDND && BDFDB.getUserStatus() == "dnd")) { + let EUdata = BDFDB.loadData(user.id, "EditUsers", "users") || {}; + let string = `${BDFDB.encodeToHTML(EUdata.name || user.username)} is ${status}.`; + let avatar = EUdata.removeIcon ? "" : (EUdata.url ? EUdata.url : BDFDB.getUserAvatar(user.id)); + let openChannel = () => { + if (settings.openOnClick) { + let DMid = this.ChannelUtils.getDMFromUserId(user.id) + if (DMid) this.ChannelSwitchUtils.selectPrivateChannel(DMid); + else this.PrivateChannelUtils.openPrivateChannel(BDFDB.myData.id, user.id); + require("electron").remote.getCurrentWindow().maximize(); + } + }; + if (!users[id].desktop) { + let toast = BDFDB.showToast(`
${string}
`, {html:true, timeout:5000, color:BDFDB.getUserStatusColor(status), icon:false, selector:`friendnotifications-${status}-toast`}); + toast.addEventListener("click", openChannel); + let notificationsound = BDFDB.getData("toast" + status, this, "notificationsounds"); + if (!notificationsound.mute && notificationsound.song) { + let audio = new Audio(); + audio.src = notificationsound.song; + audio.play(); + } + } + else { + let notificationsound = BDFDB.getData("desktop" + status, this, "notificationsounds"); + BDFDB.showDesktopNotification(string, {icon:avatar, timeout:5000, click:openChannel, silent:notificationsound.mute, sound:notificationsound.song}); + } + } + } + this.userStatusStore[id] = status; } - },10000); + },BDFDB.getData("checkInterval", this, "amounts") * 1000); } showTimeLog () { @@ -383,12 +529,12 @@ class FriendNotifications { if (!container) return; let logs = this.timeLog.slice(0).reverse(); for (let log of logs) { - if (container.childElementCount) container.appendChild(BDFDB.htmlToElement(`
`)); + if (container.childElementCount) container.appendChild(BDFDB.htmlToElement(`
`)); let data = BDFDB.loadData(log.user.id, "EditUsers", "users") || {}; let entry = BDFDB.htmlToElement(this.logEntryMarkup); entry.querySelector(".log-time").innerText = `[${log.time.toLocaleTimeString()}]`; entry.querySelector(".log-avatar").style.setProperty("background-image", `url(${data.removeIcon ? "" : (data.url ? data.url : BDFDB.getUserAvatar(log.user.id))})`); - entry.querySelector(".log-description").innerText = `${data.name || log.user.username} is ${log.online ? "online" : "offline"}.`; + entry.querySelector(".log-description").innerText = `${data.name || log.user.username} is ${log.status}.`; container.appendChild(entry) } BDFDB.appendModal(timeLogModal); diff --git a/Plugins/FriendNotifications/README.md b/Plugins/FriendNotifications/README.md index 22b0a38ff3..0d36b11b5a 100644 --- a/Plugins/FriendNotifications/README.md +++ b/Plugins/FriendNotifications/README.md @@ -6,4 +6,4 @@ [paypal-badge]: https://img.shields.io/badge/Paypal-Donate!-%2300457C.svg?logo=paypal&style=flat [paypal-link]: https://paypal.me/MircoWittrien -Notifies you when a friend either logs in or out. Click the Online Friend-Counter to display a timelog of the current session. +Notifies you when a Friend or a User your choose to observe changing his online status, can be configured individually in the settings. diff --git a/Plugins/README.md b/Plugins/README.md index 2753db02bf..1c12220a90 100644 --- a/Plugins/README.md +++ b/Plugins/README.md @@ -19,7 +19,7 @@ - [Edit Users](https://github.com/mwittrien/BetterDiscordAddons/tree/master/Plugins/EditUsers) - Allows you to change the icon, name, tag and color of users. - [Emoji Statistics](https://github.com/mwittrien/BetterDiscordAddons/tree/master/Plugins/EmojiStatistics) - Displays emojiinformation when hovering over an emoji in the emojipicker and adds a button to the emojipicker to open a statistics overview. - [Force Image Previews](https://github.com/mwittrien/BetterDiscordAddons/tree/master/Plugins/ForceImagePreviews) - Forces embedded Image Previews, if Discord doesn't do it itself. - - [Friend Notifications](https://github.com/mwittrien/BetterDiscordAddons/tree/master/Plugins/FriendNotifications) - Notifies you when a friend either logs in or out. Click the Online Friend-Counter to display a timelog of the current session. + - [Friend Notifications](https://github.com/mwittrien/BetterDiscordAddons/tree/master/Plugins/FriendNotifications) - Notifies you when a Friend or a User your choose to observe changing his online status, can be configured individually in the settings. - [Google Search Replace](https://github.com/mwittrien/BetterDiscordAddons/tree/master/Plugins/GoogleSearchReplace) - Replaces the default Google Text Search with a selection menu of several search engines. - [Google Translate Option](https://github.com/mwittrien/BetterDiscordAddons/tree/master/Plugins/GoogleTranslateOption) - Adds a Google Translate option to your context menu, which will open the selected text in Google Translate. - [Image Gallery](https://github.com/mwittrien/BetterDiscordAddons/tree/master/Plugins/ImageGallery) - Allows the user to browse through images sent inside the same message. @@ -45,7 +45,6 @@ - [Show Hidden Channels](https://github.com/mwittrien/BetterDiscordAddons/tree/master/Plugins/ShowHiddenChannels) - Displays all hidden channels that can't be accessed due to role restrictions in a new category. - [Show Image Details](https://github.com/mwittrien/BetterDiscordAddons/tree/master/Plugins/ShowImageDetails) - Display the name, size and dimensions of uploaded images (does not include embed images) in the chat as an header or as a tooltip. - [Spell Check](https://github.com/mwittrien/BetterDiscordAddons/tree/master/Plugins/SpellCheck) - Adds a spellcheck to all textareas. - - [Stalker Notifications](https://github.com/mwittrien/BetterDiscordAddons/tree/master/Plugins/StalkerNotifications) - Lets you observe the status of people that aren't your friends. - [Steam Profile Link](https://github.com/mwittrien/BetterDiscordAddons/tree/master/Plugins/SteamProfileLink) - Opens a steam profile in steam instead of a browser when clicking the steamlink in a userprofile. With the help of square. - [Theme Repo](https://github.com/mwittrien/BetterDiscordAddons/tree/master/Plugins/ThemeRepo) - Allows you to preview all themes from the theme repo and download them on the fly. - [Theme Settings](https://github.com/mwittrien/BetterDiscordAddons/tree/master/Plugins/ThemeSettings) - Allows you to change Theme Variables within BetterDiscord. diff --git a/Plugins/StalkerNotifications/README.md b/Plugins/StalkerNotifications/README.md deleted file mode 100644 index 6997f0ae21..0000000000 --- a/Plugins/StalkerNotifications/README.md +++ /dev/null @@ -1,9 +0,0 @@ -# Stalker Notifications - [![Downlad][download-badge]][download-link] [![Paypal][paypal-badge]][paypal-link] - -[download-badge]: https://img.shields.io/badge/Download-Plugin-brightgreen.svg?logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAQAAAAAYLlVAAAACXBIWXMAAA7EAAAOxAGVKw4bAAADGGlDQ1BQaG90b3Nob3AgSUNDIHByb2ZpbGUAAHjaY2BgnuDo4uTKJMDAUFBUUuQe5BgZERmlwH6egY2BmYGBgYGBITG5uMAxIMCHgYGBIS8/L5UBFTAyMHy7xsDIwMDAcFnX0cXJlYE0wJpcUFTCwMBwgIGBwSgltTiZgYHhCwMDQ3p5SUEJAwNjDAMDg0hSdkEJAwNjAQMDg0h2SJAzAwNjCwMDE09JakUJAwMDg3N+QWVRZnpGiYKhpaWlgmNKflKqQnBlcUlqbrGCZ15yflFBflFiSWoKAwMD1A4GBgYGXpf8EgX3xMw8BSMDVQYqg4jIKAUICxE+CDEESC4tKoMHJQODAIMCgwGDA0MAQyJDPcMChqMMbxjFGV0YSxlXMN5jEmMKYprAdIFZmDmSeSHzGxZLlg6WW6x6rK2s99gs2aaxfWMPZ9/NocTRxfGFM5HzApcj1xZuTe4FPFI8U3mFeCfxCfNN45fhXyygI7BD0FXwilCq0A/hXhEVkb2i4aJfxCaJG4lfkaiQlJM8JpUvLS19QqZMVl32llyfvIv8H4WtioVKekpvldeqFKiaqP5UO6jepRGqqaT5QeuA9iSdVF0rPUG9V/pHDBYY1hrFGNuayJsym740u2C+02KJ5QSrOutcmzjbQDtXe2sHY0cdJzVnJRcFV3k3BXdlD3VPXS8Tbxsfd99gvwT//ID6wIlBS4N3hVwMfRnOFCEXaRUVEV0RMzN2T9yDBLZE3aSw5IaUNak30zkyLDIzs+ZmX8xlz7PPryjYVPiuWLskq3RV2ZsK/cqSql01jLVedVPrHzbqNdU0n22VaytsP9op3VXUfbpXta+x/+5Em0mzJ/+dGj/t8AyNmf2zvs9JmHt6vvmCpYtEFrcu+bYsc/m9lSGrTq9xWbtvveWGbZtMNm/ZarJt+w6rnft3u+45uy9s/4ODOYd+Hmk/Jn58xUnrU+fOJJ/9dX7SRe1LR68kXv13fc5Nm1t379TfU75/4mHeY7En+59lvhB5efB1/lv5dxc+NH0y/fzq64Lv4T8Ffp360/rP8f9/AA0ADzT6lvFdAAAAIGNIUk0AAHolAACAgwAA+f8AAIDpAAB1MAAA6mAAADqYAAAXb5JfxUYAAAF1SURBVHja7JihTgNBEIb/K1WkBtEEAsESBKEvgEKRAhLHOxAMfQ9cHwEMBoFA1/ACBEGgzbkmUAwI+BENubTs9WZmLz1CZtZd9v7/u9vMZGdAGFabA05Hn3sWrYQwRB9rwafreikbQN5LiV6qhorDARzAARzAARzAARzAARzAARygGOAQ6a+GLr9jmlwpDuJbsxQrER+YYrXaI2D8EZyAEfangj2Fq0NrnBWry8YI5yb7rkRbBrDAK7X9NevlAYCL7Kns79iQKcunOU0+iO0fuSzV1QyUNjkU2b9wS66qm2nt8L3Q/oO7Gk3tWO2InzPtv3isU9RP9jqxmR8LMKsqdPVqFoC8qiDM/HiAcFUQZ34IYDr0VUGW+QEfK8BkVZBmfqkAWVWQZ37JAOA+n/nEtnh/wGd8JWP81Nt0P0r8Wu4ADvAHAOq2fsaP4N8BvFXi/ZoB3FYCcJMNKDbQw9Kc7YdoYfDzB+6xjUuM5mY+wsXYHvgeABIzsPkSOM/lAAAAAElFTkSuQmCC&style=flat -[download-link]: https://betterdiscord.net/ghdl?url=https://raw.githubusercontent.com/mwittrien/BetterDiscordAddons/master/Plugins/StalkerNotifications/StalkerNotifications.plugin.js - -[paypal-badge]: https://img.shields.io/badge/Paypal-Donate!-%2300457C.svg?logo=paypal&style=flat -[paypal-link]: https://paypal.me/MircoWittrien - -Lets you observe the status of people that aren't your friends. diff --git a/Plugins/StalkerNotifications/StalkerNotifications.plugin.js b/Plugins/StalkerNotifications/StalkerNotifications.plugin.js index a738657e9e..2bedbcc1cd 100644 --- a/Plugins/StalkerNotifications/StalkerNotifications.plugin.js +++ b/Plugins/StalkerNotifications/StalkerNotifications.plugin.js @@ -3,249 +3,16 @@ class StalkerNotifications { getName () {return "StalkerNotifications";} - getVersion () {return "1.1.2";} + getVersion () {return "9.9.9";} getAuthor () {return "DevilBro";} - getDescription () {return "Lets you observe the status of people that aren't your friends.";} + getDescription () {return "DISCONTINUED.";} initConstructor () { - this.patchModules = { - "StandardSidebarView":"componentWillUnmount" + this.changelog = { + "improved":[["Merged FriendNotifications and StalkerNotifications","Since both of these plugins now work the same, I decided to merge them. FriendNotifications will be continued and StalkerNotifications will be disconntinued. You can find the old StalkerNotifications settings in the FriendNotifications settings. All old configurations of FriendNotifications and StalkerNotifications should have been merged"]] }; - - this.stalkerOnlineList = {}; - - this.checkInterval = null; - - this.timeLog = []; - - this.timeLogModalMarkup = - ` -
-
-
-
-
-
-

User LogIn/-Out Timelog

-
- -
-
-
-
-
-
- -
-
-
-
-
`; - - this.logEntryMarkup = - `
-

-
-

-
`; - - this.dividerMarkup = `
`; - - this.css = ` - .${this.name}-modal .log-time { - width: 110px; - } - .${this.name}-modal .log-avatar { - width: 35px; - height: 35px; - background-size: cover; - background-position: center; - border-radius: 50%; - } - .${this.name}-settings .avatar-list { - display: flex; - align-items: center; - flex-wrap: wrap; - } - .${this.name}-settings .type-toast, .${this.name}-settings .type-desktop { - border-radius: 3px; - padding: 0 3px; - } - .${this.name}-settings .type-toast { - background-color: #7289DA; - } - .${this.name}-settings .type-desktop { - background-color: #43B581; - } - .${this.name}-settings .settings-avatar.desktop { - border-color: #43B581; - } - .${this.name}-settings .settings-avatar { - margin: 5px; - width: 50px; - height: 50px; - background-size: cover; - background-position: center; - border: 5px solid #7289DA; - border-radius: 50%; - box-sizing: border-box; - cursor: pointer; - } - .${this.name}-settings .settings-avatar.desktop { - border-color: #43B581; - } - .${this.name}-settings .settings-avatar.disabled { - border-color: #36393F; - filter: grayscale(100%) brightness(50%); - } - .${this.name}-settings .settings-avatar ${BDFDB.dotCN.hovercardbutton} { - position: relative; - top: -10px; - right: -25px; - } - .${this.name}-settings .settings-avatar:not(:hover) ${BDFDB.dotCN.hovercardbutton} { - opacity: 1; - }`; - - this.defaults = { - settings: { - muteOnDND: {value:false, description:"Do not notify me when I am DnD:"}, - onlyOnOnline: {value:false, description:"Only notify me when a User logs in:"}, - openOnClick: {value:false, description:"Open the DM when you click a Notification:"} - }, - notificationsounds: { - toastonline: {value:{url:null,song:null,mute:false}}, - toastoffline: {value:{url:null,song:null,mute:false}}, - desktoponline: {value:{url:null,song:null,mute:false}}, - desktopoffline: {value:{url:null,song:null,mute:false}} - }, - amounts: { - checkInterval: {value:10, min:5, description:"Check Users every X seconds:"} - } - }; - } - - getSettingsPanel () { - if (!global.BDFDB || typeof BDFDB != "object" || !BDFDB.loaded || !this.started) return; - - let amounts = BDFDB.getAllData(this, "amounts"); - let settings = BDFDB.getAllData(this, "settings"); - let users = BDFDB.loadAllData(this, "users"); - let notificationsounds = BDFDB.getAllData(this, "notificationsounds"); - let settingshtml = `
${this.name}
`; - settingshtml += `

Add User:

`; - for (let key in amounts) { - settingshtml += `

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

`; - } - for (let key in settings) { - settingshtml += `

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

`; - } - for (let key in notificationsounds) { - if (key.indexOf("desktop") == -1 || "Notification" in window) settingshtml += `
${key} notification sound:
Mute:
`; - } - settingshtml += `

Click on a Icon to toggle Notifications for that User:

`; - if ("Notification" in window) settingshtml += `

Rightclick on a Icon to toggle Notifications for that User:

`; - settingshtml += `
`; - for (let id in users) { - let user = this.UserUtils.getUser(id); - if (user) settingshtml += this.createSettingsAvatarHtml(user, users[id]); - } - settingshtml += `
`; - settingshtml += `

Batch set Users:

${"Notification" in window ? `` : ``}
`; - settingshtml += `

Timelog of LogIns/-Outs:

`; - settingshtml += `
`; - - let settingspanel = BDFDB.htmlToElement(settingshtml); - - BDFDB.initElements(settingspanel, this); - - BDFDB.addEventListener(this, settingspanel, "click", ".btn-savesong", e => {this.saveAudio(settingspanel, e.currentTarget.getAttribute("option"));}) - BDFDB.addEventListener(this, settingspanel, "click", ".mute-checkbox", e => { - let option = e.currentTarget.getAttribute("option"); - let notificationsound = BDFDB.getData(option, this, "notificationsounds"); - notificationsound.mute = e.currentTarget.checked; - BDFDB.saveData(option, notificationsound, this, "notificationsounds"); - }); - BDFDB.addEventListener(this, settingspanel, "mouseenter", ".settings-avatar", e => { - let user = this.UserUtils.getUser(e.currentTarget.getAttribute("user-id")); - let data = BDFDB.loadData(user.id, "EditUsers", "users") || {}; - BDFDB.createTooltip(data.name ? data.name : user.username, e.currentTarget, {type:"top"}); - }); - BDFDB.addEventListener(this, settingspanel, "contextmenu", ".settings-avatar", e => { - if (!("Notification" in window)) return; - let desktopoff = !BDFDB.containsClass(e.currentTarget, "desktop"); - let id = e.currentTarget.getAttribute("user-id"); - BDFDB.removeClass(e.currentTarget, "disabled"); - BDFDB.toggleClass(e.currentTarget, "desktop", desktopoff); - BDFDB.saveData(id, {"desktop":desktopoff,"disabled":false}, this, "users"); - }); - BDFDB.addEventListener(this, settingspanel, "click", ".settings-avatar", e => { - if (BDFDB.containsClass(e.target, "remove-user")) return; - let disableoff = !BDFDB.containsClass(e.currentTarget, "disabled"); - let id = e.currentTarget.getAttribute("user-id"); - BDFDB.removeClass(e.currentTarget, "desktop"); - BDFDB.toggleClass(e.currentTarget, "disabled", disableoff); - BDFDB.saveData(id, {"desktop":false,"disabled":disableoff}, this, "users"); - }); - BDFDB.addEventListener(this, settingspanel, "click", ".remove-user", e => { - BDFDB.removeData(e.currentTarget.parentElement.getAttribute("user-id"), this, "users"); - BDFDB.removeEles(this.name + "-settings .settings-avatar"); - let listhtml = `
`; - let users = BDFDB.loadAllData(this, "users"); - for (let id in users) { - let user = this.UserUtils.getUser(id); - if (user) listhtml += this.createSettingsAvatarHtml(user, users[id]); - } - listhtml += `
`; - settingspanel.querySelector(".avatar-list").innerHTML = listhtml; - }); - BDFDB.addEventListener(this, settingspanel, "click", ".disable-all, .toast-all, .desktop-all", e => { - let disableon = e.currentTarget.getAttribute("do-disable"); - let desktopon = e.currentTarget.getAttribute("do-desktop"); - let users = BDFDB.loadAllData(this, "users"); - settingspanel.querySelectorAll(".settings-avatar").forEach(avatar => { - let id = avatar.getAttribute("user-id"); - BDFDB.toggleClass(avatar, "disabled", disableon); - BDFDB.toggleClass(avatar, "desktop", desktopon); - users[id].desktop = desktopon ? true : false; - users[id].disabled = disableon ? true : false; - }); - BDFDB.saveAllData(users, this, "users"); - }); - BDFDB.addEventListener(this, settingspanel, "click", ".btn-adduser", e => { - let idinput = settingspanel.querySelector("#input-userid"); - let user = this.UserUtils.getUser(idinput.value); - if (user) { - idinput.value = ""; - BDFDB.saveData(user.id, {desktop:false,disabled:false}, this, "users"); - BDFDB.removeEles(this.name + "-settings .settings-avatar"); - let listhtml = `
`; - let users = BDFDB.loadAllData(this, "users"); - for (let id in users) { - let user = this.UserUtils.getUser(id); - if (user) listhtml += this.createSettingsAvatarHtml(user, users[id]); - } - listhtml += `
`; - settingspanel.querySelector(".avatar-list").innerHTML = listhtml; - } - else BDFDB.showToast("Please enter a valid UserID.",{type:"error"}); - }); - BDFDB.addEventListener(this, settingspanel, "click", ".btn-timelog", () => {this.showTimeLog();}); - - return settingspanel; } //legacy @@ -287,18 +54,76 @@ class StalkerNotifications { if (global.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) { if (this.started) return; BDFDB.loadMessage(this); + //META{"name":"StalkerNotifications","website":"https://github.com/mwittrien/BetterDiscordAddons/tree/master/Plugins/StalkerNotifications","source":"https://raw.githubusercontent.com/mwittrien/BetterDiscordAddons/master/Plugins/StalkerNotifications/StalkerNotifications.plugin.js"}*// - this.ChannelUtils = BDFDB.WebModules.findByProperties("getDMFromUserId"); - this.ChannelSwitchUtils = BDFDB.WebModules.findByProperties("selectPrivateChannel"); - this.PrivateChannelUtils = BDFDB.WebModules.findByProperties("openPrivateChannel"); - this.UserMetaStore = BDFDB.WebModules.findByProperties("getStatus", "getOnlineFriendCount"); - this.UserUtils = BDFDB.WebModules.findByProperties("getUsers"); +class StalkerNotifications { + getName () {return "StalkerNotifications";} - for (let id in BDFDB.loadAllData(this, "users")) { - this.stalkerOnlineList[id] = this.UserMetaStore.getStatus(id) != "offline"; - } + getVersion () {return "9.9.9";} - this.startInterval(); + getAuthor () {return "DevilBro";} + + getDescription () {return "DISCONTINUED.";} + + initConstructor () { + this.changelog = { + "improved":[["Merged FriendNotifications and StalkerNotifications","Since both of these plugins now work the same, I decided to merge them. FriendNotifications will be continued and StalkerNotifications will be disconntinued. You can find the old StalkerNotifications settings in the FriendNotifications settings. All old configurations of FriendNotifications and StalkerNotifications should have been merged"]] + }; + } + + //legacy + load () {} + + start () { + if (!global.BDFDB) global.BDFDB = {myPlugins:{}}; + if (global.BDFDB && global.BDFDB.myPlugins && typeof global.BDFDB.myPlugins == "object") global.BDFDB.myPlugins[this.getName()] = this; + var 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.js"); + libraryScript.setAttribute("date", performance.now()); + libraryScript.addEventListener("load", () => {this.initialize();}); + document.head.appendChild(libraryScript); + this.libLoadTimeout = setTimeout(() => { + libraryScript.remove(); + require("request")("https://mwittrien.github.io/BetterDiscordAddons/Plugins/BDFDB.js", (error, response, body) => { + if (body) { + libraryScript = document.createElement("script"); + libraryScript.setAttribute("id", "BDFDBLibraryScript"); + libraryScript.setAttribute("type", "text/javascript"); + libraryScript.setAttribute("date", performance.now()); + libraryScript.innerText = body; + document.head.appendChild(libraryScript); + } + this.initialize(); + }); + }, 15000); + } + 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; + BDFDB.loadMessage(this); + + BDFDB.openConfirmModal(this, "StalkerNotifications has been discontinued and was merged with FriendNotifications. To download FriendNotifications click the 'OK' button bellow. This will delete StalkerNotifications and download FriendNotifications.", "Update Notification", () => { + require("request")("https://raw.githubusercontent.com/mwittrien/BetterDiscordAddons/master/Plugins/FriendNotifications/FriendNotifications.plugin.js", (error, response, body) => { + if (error) BDFDB.showToast(`Unable to download FriendNotifications.plugin.js.`, {type:"error"}); + else { + require("fs").writeFile(require("path").join(BDFDB.getPluginsFolder(), "FriendNotifications.plugin.js"), body, (error) => { + if (!error) { + BDFDB.showToast(`Successfully downloaded FriendNotifications.plugin.js.`, {type:"success"}); + require("fs").unlinkSync(require("path").join(BDFDB.getPluginsFolder(), "StalkerNotifications.plugin.js")); + } + }); + } + }); + }); } else { console.error(`%c[${this.getName()}]%c`, 'color: #3a71c1; font-weight: 700;', '', 'Fatal Error: Could not load BD functions!'); @@ -307,117 +132,38 @@ class StalkerNotifications { stop () { if (global.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) { - clearInterval(this.checkInterval); BDFDB.unloadMessage(this); } } // begin of own functions - - saveAudio (settingspanel, option) { - let successSavedAudio = (parsedurl, parseddata) => { - if (parsedurl && parseddata) BDFDB.showToast(`Sound was saved successfully.`, {type:"success"}); - let notificationsound = BDFDB.getData(option, this, "notificationsounds"); - notificationsound.url = parsedurl; - notificationsound.song = parseddata; - BDFDB.saveData(option, notificationsound, this, "notificationsounds"); - }; - - let url = settingspanel.querySelector(`.songInput[option="${option}"]`).value; - if (url.length == 0) { - BDFDB.showToast(`Sound file was removed.`, {type:"warn"}); - successSavedAudio(url, url); - } - else if (url.indexOf("http") == 0) { - require("request")(url, (error, response, result) => { - if (response) { - let type = response.headers["content-type"]; - if (type && (type.indexOf("octet-stream") > -1 || type.indexOf("audio") > -1 || type.indexOf("video") > -1)) { - successSavedAudio(url, url); - return; +} + BDFDB.openConfirmModal(this, "StalkerNotifications has been discontinued and was merged with FriendNotifications. To download FriendNotifications click the 'OK' button bellow. This will delete StalkerNotifications and download FriendNotifications.", "Update Notification", () => { + require("request")("https://raw.githubusercontent.com/mwittrien/BetterDiscordAddons/master/Plugins/FriendNotifications/FriendNotifications.plugin.js", (error, response, body) => { + if (error) BDFDB.showToast(`Unable to download FriendNotifications.plugin.js.`, {type:"error"}); + else { + require("fs").writeFile(require("path").join(BDFDB.getPluginsFolder(), "FriendNotifications.plugin.js"), body, (error) => { + if (!error) { + BDFDB.showToast(`Successfully downloaded FriendNotifications.plugin.js.`, {type:"success"}); + require("fs").unlinkSync(require("path").join(BDFDB.getPluginsFolder(), "StalkerNotifications.plugin.js")); + } + }); } - } - BDFDB.showToast("Use a valid direct link to a video or audio source. They usually end on something like .mp3, .mp4 or .wav.", {type:"danger"}); + }); }); } else { - require("fs").readFile(url, (error, response) => { - if (error) BDFDB.showToast("Could not fetch file. Please make sure the file exists.", {type:"danger"}); - else successSavedAudio(url, `data:audio/mpeg;base64,${response.toString("base64")}`); - }); + console.error(`%c[${this.getName()}]%c`, 'color: #3a71c1; font-weight: 700;', '', 'Fatal Error: Could not load BD functions!'); } } - createSettingsAvatarHtml (user, settings) { - let data = BDFDB.loadData(user.id, "EditUsers", "users") || {}; - return `
`; - } - - processStandardSidebarView (instance, wrapper) { - if (this.SettingsUpdated) { - delete this.SettingsUpdated; - this.startInterval(); + stop () { + if (global.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) { + BDFDB.unloadMessage(this); } } - startInterval () { - clearInterval(this.checkInterval); - this.checkInterval = setInterval(() => { - let settings = BDFDB.getAllData(this, "settings"); - let users = BDFDB.loadAllData(this, "users"); - for (let id in users) { - let online = this.UserMetaStore.getStatus(id) != "offline"; - let user = this.UserUtils.getUser(id); - if (user && !user.disabled && this.stalkerOnlineList[id] != online) { - this.timeLog.push({user, online, time: new Date()}); - if (!(settings.onlyOnOnline && !online) && !(settings.muteOnDND && BDFDB.getUserStatus() == "dnd")) { - let data = BDFDB.loadData(user.id, "EditUsers", "users") || {}; - let string = `${BDFDB.encodeToHTML(data.name ? data.name : user.username)} is ${online ? "online" : "offline"}.`; - let avatar = data.removeIcon ? "" : (data.url ? data.url : BDFDB.getUserAvatar(user.id)); - let openChannel = () => { - if (settings.openOnClick) { - let DMid = this.ChannelUtils.getDMFromUserId(user.id) - if (DMid) this.ChannelSwitchUtils.selectPrivateChannel(DMid); - else this.PrivateChannelUtils.openPrivateChannel(BDFDB.myData.id, user.id); - require("electron").remote.getCurrentWindow().maximize(); - } - }; - if (!user.desktop) { - let toast = BDFDB.showToast(`
${string}
`, {html:true, timeout:5000, type:(online ? "success" : null), icon:false, selector:`stalkernotifications-${online ? "online" : "offline"}-toast`}); - toast.addEventListener("click", openChannel); - let notificationsound = BDFDB.getData(online ? "toastonline" : "toastoffline", this, "notificationsounds"); - if (!notificationsound.mute && notificationsound.song) { - let audio = new Audio(); - audio.src = notificationsound.song; - audio.play(); - } - } - else { - let notificationsound = BDFDB.getData(online ? "desktoponline" : "desktopoffline", this, "notificationsounds"); - BDFDB.showDesktopNotification(string, {icon:avatar, timeout:5000, click:openChannel, silent:notificationsound.mute, sound:notificationsound.song}); - } - } - } - this.stalkerOnlineList[id] = online; - } - },BDFDB.getData("checkInterval", this, "amounts") * 1000); - } - showTimeLog () { - let timeLogModal = BDFDB.htmlToElement(this.timeLogModalMarkup); - let container = timeLogModal.querySelector(".entries"); - if (!container) return; - let logs = this.timeLog.slice(0).reverse(); - for (let log of logs) { - if (container.childElementCount) container.appendChild(BDFDB.htmlToElement(`
`)); - let data = BDFDB.loadData(log.user.id, "EditUsers", "users") || {}; - let entry = BDFDB.htmlToElement(this.logEntryMarkup); - entry.querySelector(".log-time").innerText = `[${log.time.toLocaleTimeString()}]`; - entry.querySelector(".log-avatar").style.setProperty("background-image", `url(${data.removeIcon ? "" : (data.url ? data.url : BDFDB.getUserAvatar(log.user.id))})`); - entry.querySelector(".log-description").innerText = `${data.name || log.user.username} is ${log.online ? "online" : "offline"}.`; - container.appendChild(entry) - } - BDFDB.appendModal(timeLogModal); - } + // begin of own functions } \ No newline at end of file