-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathwfes-showWFVersion.js
139 lines (124 loc) · 4.19 KB
/
wfes-showWFVersion.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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
// @name show Wayfarer version
// @version 1.3.6
// @description show current Wayfarer version
// @author AlterTobi
(function() {
"use strict";
const versionDivID = "wfVersionDiv";
const myCssId = "wfVersionCSS";
const myStyle = `.wfVersionCSS {
position: absolute;
z-index: 9999;
right: 270px;
top: 10px;
background-color: white;
border: 2px solid red;
padding: 5px;
max-width: 50%;
box-shadow: 7px 7px 5px grey;
cursor: pointer;
max-height: 95%;
overflow: auto;}
/* Styles for dark mode */
.dark .wfVersionCSS {
color: #ddd;
background-color: #303030;
box-shadow: 6px 6px 4px darkgrey;
}
.wfes-hidden { display: none; }
.wfes-versionChanged {
background-color: red !important;
border-color: yellow !important;
color: white !important;
}
`;
const lStoreHist = "wfes_WFVersionHistory";
let wfVersion;
function showVersion(history) {
function toggleVersions() {
const versionList = document.getElementById("version-list");
versionList.classList.toggle("wfes-hidden");
}
window.wfes.f.addCSS(myCssId, myStyle);
// Erstelle das Dropdown-Menü
const versionDropdown = document.createElement("div");
versionDropdown.setAttribute("id", "version-dropdown");
const versionButton = document.createElement("button");
versionButton.setAttribute("id", "version-button");
versionButton.appendChild(document.createTextNode("Version: " + wfVersion));
versionDropdown.appendChild(versionButton);
const versionList = document.createElement("ul");
versionList.setAttribute("id", "version-list");
versionList.setAttribute("class", "wfes-hidden");
versionList.style.fontFamily = "Courier New, monospace"; // Nichtproportionaler Font
versionDropdown.appendChild(versionList);
for (let i = history.length - 1; i >= 0; i--) {
const version = history[i].version;
const date = history[i].date;
const listItem = document.createElement("li");
listItem.textContent = `${version} (${date})`;
versionList.appendChild(listItem);
}
let versionDiv = document.getElementById(versionDivID);
if (null === versionDiv) {
const bodyElem = document.getElementsByTagName("body")[0];
versionDiv = document.createElement("div");
versionDiv.setAttribute("class", "wfVersionCSS");
versionDiv.setAttribute("id", versionDivID);
versionDiv.appendChild(versionDropdown);
bodyElem.appendChild(versionDiv);
} else {
// remove existing child first
versionDiv.removeChild(document.getElementById("version-dropdown"));
versionDiv.appendChild(versionDropdown);
}
versionDropdown.addEventListener("click", toggleVersions);
}
function versionChanged(version) {
console.warn(GM_info.script.name, "version changed");
const msgStr = "WF version change " + version;
window.wfes.f.createNotification(msgStr, "red");
const elem = document.getElementById(versionDivID);
if (null !== elem) {
elem.classList.add("wfes-versionChanged");
}
}
function handleVersion(versionHistory) {
// get latest version
const len = versionHistory.length;
const options = {
year: "numeric",
month: "2-digit",
day: "2-digit",
hour: "2-digit",
minute: "2-digit",
second: "2-digit",
};
const now = new Date().toLocaleString(undefined, options);
const v = {};
v.date = now;
v.version = wfVersion;
if ( len > 0 ) {
const last = versionHistory[len-1].version;
if (last !== wfVersion) {
versionChanged(wfVersion);
versionHistory.push(v);
window.wfes.f.localSave(lStoreHist, versionHistory);
}
} else {
// first entry
versionHistory.push(v);
window.wfes.f.localSave(lStoreHist, versionHistory);
}
}
function init() {
wfVersion = window.wfes.g.wfVersion();
window.wfes.f.localGet(lStoreHist, []).then((hist)=>{
showVersion(hist);
handleVersion(hist);
});
}
window.addEventListener("WFESVersionChanged", init);
/* we are done :-) */
console.log("Script loaded:", GM_info.script.name, "v" + GM_info.script.version);
})();