Skip to content

Commit

Permalink
callback mit object, icons als material
Browse files Browse the repository at this point in the history
  • Loading branch information
AlterTobi committed Dec 11, 2024
1 parent d87842f commit 916fad1
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 27 deletions.
29 changes: 18 additions & 11 deletions no_support/wfes-NominationNotify.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// @name Nomination Notify
// @version 1.7.0
// @version 1.7.1
// @description show nomination status updates
// @author AlterTobi

Expand Down Expand Up @@ -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];

Expand All @@ -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) {
Expand All @@ -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);
}
}

Expand Down
4 changes: 2 additions & 2 deletions wfes-AutoHold.js
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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"});
}
}

Expand Down
40 changes: 26 additions & 14 deletions wfes-Base.js
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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 */
Expand Down Expand Up @@ -73,7 +70,6 @@
/* notification Buttons */
.wfesNotiButton {
border: none;
width: 32px;
height: 32px;
cursor: pointer;
Expand Down Expand Up @@ -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":
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit 916fad1

Please sign in to comment.