-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathwfes-AppealData.js
113 lines (97 loc) · 4.18 KB
/
wfes-AppealData.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
// @name Appeal Data
// @version 1.4.0
// @description save and show appeal your statements
// @author AlterTobi
(function() {
"use strict";
const sessvarMiss = "warnBase";
const baseMinVersion = "2.3.0";
const lStoreList = "wfes_AppealData";
const warnFlag = "wfes_AppealData_warn";
const myID = "nominationAppealData";
const nominationSelector = "app-details-pane > div > div > div > div.flex.flex-row.justify-between";
function warnOnce() {
window.wfes.f.localGet(warnFlag, false).then((warn)=>{
if(warn) {
return(false);
} else {
const msg = Array(GM_info.script.name + ":",
"Wayfarer now handles appeal statements. This script still saves data, but will not show it in the future (as long as Wayfarer does this) ",
"Maybe you want to disable the script?"
);
window.wfes.f.createNotification(msg, "fuchsia");
window.wfes.f.localSave(warnFlag, true);
return(true);
}
})
.catch((e) => {console.warn(GM_info.script.name, ": ", e);});
return(false);
}
function storeAppealData() {
const appeal = window.wfes.g.reviewAppeal();
// console.log(GM_info.script.name, ": storeAppealData()");
// console.dir(appeal);
window.wfes.f.localGet(lStoreList, {}).then((appealHistory)=>{
appealHistory[appeal.id] = appeal.statement;
window.wfes.f.localSave(lStoreList, appealHistory)
// .then(() => { console.log(GM_info.script.name, ": ", "appeal data saved for:", appeal.id);})
.catch((e) => {console.warn(GM_info.script.name, ": ", e);});
})
.catch((e) => {console.warn(GM_info.script.name, ": ", e);});
}
function NominationSelected() {
const myElem = document.getElementById(myID);
// remove if there
if (myElem) { myElem.remove();}
const nom = window.wfes.g.nominationDetail();
window.wfes.f.localGet(lStoreList, {}).then((appealHistory)=>{
if (nom.id in appealHistory) {
wfes.f.waitForElem(nominationSelector)
.then(elem => {
const h5 = document.createElement("h5");
h5.appendChild(document.createTextNode("Appeal Statement"));
h5.setAttribute("class", "wfesBold");
h5.style.fontWeight = "bold";
const textDiv = document.createElement("div");
// Ersetze Zeilenumbrüche durch <br>, sanitize text
const safeText = appealHistory[nom.id].split("\n").map(line => {
const div = document.createElement("div");
div.textContent = line;
return div.innerHTML;
})
.join("<br>");
textDiv.innerHTML = safeText;
const appealDiv = document.createElement("div");
appealDiv.setAttribute("class", "ng-star-inserted");
appealDiv.setAttribute("id", myID);
appealDiv.style.marginBottom = "1em";
appealDiv.appendChild(h5);
appealDiv.appendChild(textDiv);
elem.insertAdjacentElement("beforeBegin", appealDiv);
})
.catch((e) => {console.warn(GM_info.script.name, ": ", e);});
}
}
)
.catch((e) => {console.warn(GM_info.script.name, ": ", e);});
}
const init = () => {
window.addEventListener("WFESReviewAppealSent", storeAppealData);
// Wayfarer 5.24 shows user statement, no need to display duplicate content
if (warnOnce()) {window.addEventListener("WFESNominationDetailLoaded", NominationSelected);}
};
// === no changes needed below this line ======================
if("undefined" === typeof(wfes)) {
if (undefined === sessionStorage[sessvarMiss]) {
sessionStorage[sessvarMiss] = 1;
alert("Missing WFES Base. Please install from https://altertobi.github.io/Wayfarer-Extension-Scripts/");
console.error("Missing WFES Base. Please install from https://altertobi.github.io/Wayfarer-Extension-Scripts/");
}
} else if (window.wfes.f.hasMinVersion(baseMinVersion)) {
init();
} else {
console.warn(GM_info.script.name, "Need at least wfes-Base version ", baseMinVersion, " Please upgrade.");
}
/* we are done :-) */
console.log("Script loaded:", GM_info.script.name, "v" + GM_info.script.version);
})();