From 916fad11c890122a01ad5d2d683495870129f56b Mon Sep 17 00:00:00 2001 From: AlterTobi Date: Thu, 12 Dec 2024 00:20:44 +0100 Subject: [PATCH] callback mit object, icons als material --- no_support/wfes-NominationNotify.js | 29 +++++++++++++-------- wfes-AutoHold.js | 4 +-- wfes-Base.js | 40 +++++++++++++++++++---------- 3 files changed, 46 insertions(+), 27 deletions(-) diff --git a/no_support/wfes-NominationNotify.js b/no_support/wfes-NominationNotify.js index d53dfd31..c14ea78d 100644 --- a/no_support/wfes-NominationNotify.js +++ b/no_support/wfes-NominationNotify.js @@ -1,5 +1,5 @@ // @name Nomination Notify -// @version 1.7.0 +// @version 1.7.1 // @description show nomination status updates // @author AlterTobi @@ -112,6 +112,13 @@ const today = getCurrentDateStr(); let myDates, historicalData, nom; + // prepare callback for createNotification() + const callbackConfig = { + callback: searchSubmission, + params: [nom.title], + icon: "search" + }; + for (let i = 0; i < nomList.length; i++) { nom = nomList[i]; @@ -127,7 +134,7 @@ // detect unknown states if (!states.includes(nom.status)) { - window.wfes.f.createNotification(`${notiTitle} has unknown state: ${nom.status}`, "blue", searchSubmission, [nom.title]); + window.wfes.f.createNotification(`${notiTitle} has unknown state: ${nom.status}`, "blue", callbackConfig); } if (undefined === historicalData) { @@ -145,36 +152,36 @@ // upgrade? if (false === historicalData.upgraded && true === nom.upgraded) { myDates.push([today, "UPGRADE"]); - window.wfes.f.createNotification(`${notiTitle} was upgraded!`, "green", searchSubmission, [nom.title]); + window.wfes.f.createNotification(`${notiTitle} was upgraded!`, "green", callbackConfig); } // Niantic Review? if ((false === historicalData.isNianticControlled && true === nom.isNianticControlled) || (( "NIANTIC_REVIEW"!== historicalData.status) && ("NIANTIC_REVIEW" === nom.status))) { - window.wfes.f.createNotification(`${notiTitle} went into Niantic review!`, "fuchsia", searchSubmission, [nom.title]); + window.wfes.f.createNotification(`${notiTitle} went into Niantic review!`, "fuchsia", callbackConfig); } // was missing? if (("MISSING" === historicalData.status)) { - window.wfes.f.createNotification(`${notiTitle} returned`, "orange", searchSubmission, [nom.title]); + window.wfes.f.createNotification(`${notiTitle} returned`, "orange", callbackConfig); } // In queue -> In voting if ((historicalData.status !== "VOTING") && ("VOTING" === nom.status)) { - window.wfes.f.createNotification(`${notiTitle} went into voting!`, "green", searchSubmission, [nom.title]); + window.wfes.f.createNotification(`${notiTitle} went into voting!`, "green", callbackConfig); } else if ((historicalData.status !== "HELD") && ("HELD" === nom.status)) { // only if nomination is "old" if (getDateDiff(nom.day) > noHeldMsgDays) { - window.wfes.f.createNotification(`${notiTitle} put on HOLD!`, "red", searchSubmission, [nom.title]); + window.wfes.f.createNotification(`${notiTitle} put on HOLD!`, "red", callbackConfig); } } else if ((historicalData.status !== "APPEALED") && ("APPEALED" === nom.status)) { - window.wfes.f.createNotification(`${notiTitle} was appealed!`, "green", searchSubmission, [nom.title]); + window.wfes.f.createNotification(`${notiTitle} was appealed!`, "green", callbackConfig); } else if (historicalData.status !== "ACCEPTED" && historicalData.status !== "REJECTED" && historicalData.status !== "DUPLICATE") { if ("ACCEPTED" === nom.status) { - window.wfes.f.createNotification(`${notiTitle} was accepted!`, "green", searchSubmission, [nom.title]); + window.wfes.f.createNotification(`${notiTitle} was accepted!`, "green", callbackConfig); }else if("REJECTED" === nom.status) { - window.wfes.f.createNotification(`${notiTitle} was rejected!`, "red", searchSubmission, [nom.title]); + window.wfes.f.createNotification(`${notiTitle} was rejected!`, "red", callbackConfig); }else if("DUPLICATE" === nom.status) { - window.wfes.f.createNotification(`${notiTitle} was marked as a duplicate!`, "", searchSubmission, [nom.title]); + window.wfes.f.createNotification(`${notiTitle} was marked as a duplicate!`, "", callbackConfig); } } diff --git a/wfes-AutoHold.js b/wfes-AutoHold.js index 9a7f4025..3ba34977 100644 --- a/wfes-AutoHold.js +++ b/wfes-AutoHold.js @@ -1,5 +1,5 @@ // @name AutoHold -// @version 1.3.0 +// @version 1.3.1 // @description put nomination on HOLD when additional stament contains the text "#hold" // @author AlterTobi @@ -68,7 +68,7 @@ window.wfes.f.createNotification(`AutoHold: ${o.title}`, "orange"); _setHold(o.id); } else { - window.wfes.f.createNotification("AutoHold: all nominations processed, click arrow to reload page", "green", _reloadPage); + window.wfes.f.createNotification("AutoHold: all nominations processed, click arrow to reload page", "green", { callback: _reloadPage, icon: "renew"}); } } diff --git a/wfes-Base.js b/wfes-Base.js index 1f2da6ee..3f6ba7f0 100644 --- a/wfes-Base.js +++ b/wfes-Base.js @@ -1,5 +1,5 @@ // @name Base -// @version 2.3.0 +// @version 2.3.1 // @description basic functionality for WFES // @author AlterTobi // @run-at document-start @@ -22,9 +22,6 @@ const idbName = "wfes-data"; const idbLocalStorageCompat = "localStorage"; - const imgClose = "https://altertobi.github.io/Wayfarer-Extension-Scripts/dev/images/white_cross.png"; - const imgAction = "https://altertobi.github.io/Wayfarer-Extension-Scripts/dev/images/white-arrow-right-up.png"; - const myCssId = "notifyAreaCSS"; const myStyle = ` /* Container */ @@ -73,7 +70,6 @@ /* notification Buttons */ .wfesNotiButton { - border: none; width: 32px; height: 32px; cursor: pointer; @@ -651,7 +647,7 @@ } }; - window.wfes.f.createNotification = function(message = "no message", color = "green", callback = null, callbackParams = []) { + window.wfes.f.createNotification = function(message = "no message", color = "green", callbackConfig = null) { const notification = document.createElement("div"); switch (color) { case "red": @@ -681,22 +677,38 @@ buttonGroup.setAttribute("class", "wfesButtonGroup"); // Schließen-Button - const closeButton = document.createElement("img"); - closeButton.setAttribute("class", "wfesNotiButton"); - closeButton.src = imgClose; + const closeButton = document.createElement("button"); + closeButton.setAttribute("class", "wfesNotiButton material-icons"); + closeButton.innerText = "close"; closeButton.onclick = function() { notification.remove(); }; // Optionaler Callback-Button - if (callback && "function" === typeof callback) { - const actionButton = document.createElement("img"); - actionButton.setAttribute("class", "wfesNotiButton"); - actionButton.src = imgAction; + if (callbackConfig && "function" === typeof callbackConfig.callback) { + const actionButton = document.createElement("button"); + actionButton.setAttribute("class", "wfesNotiButton material-icons"); + + let actionIcon; + switch (callbackConfig.icon) { + case "play": + actionIcon = "play_circle"; + break; + case "search": + actionIcon = "search"; + break; + case "renow": + actionIcon="autorenew"; + break; + default: + actionIcon = "play_circle"; + } + + actionButton.innerText = actionIcon; actionButton.onclick = function(event) { event.stopPropagation(); // Verhindert, dass der Klick das notification-Element erreicht - callback(...callbackParams); // Ruft die Callback-Funktion mit den übergebenen Parametern auf + callbackConfig.callback(...(callbackConfig.params || [])); // Ruft die Callback-Funktion mit den übergebenen Parametern auf }; buttonGroup.appendChild(actionButton); }