-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathNASPAQ Highlighter.user.js
127 lines (114 loc) · 6.17 KB
/
NASPAQ Highlighter.user.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
// ==UserScript==
// @name NASPAQ Highlighter
// @version 0.2
// @namespace dithpri.RCES
// @description Adds NASPAQ's icon besides members during auctions
// @author dithpri
// @downloadURL https://github.com/dithpri/RCES/raw/master/userscripts/auction/NASPAQ%20Highlighter.user.js
// @noframes
// @match https://www.nationstates.net/*page=deck*/*card=*
// @match https://www.nationstates.net/*card=*/*page=deck*
// @grant GM.xmlHttpRequest
// @grant GM.setValue
// @grant GM.getValue
// @connect docs.google.com
// @connect googleusercontent.com
// ==/UserScript==
/*
* Copyright (c) 2020 dithpri (Racoda) <[email protected]>
* This file is part of RCES: https://github.com/dithpri/RCES and licensed under
* the MIT license. See LICENSE.md or
* https://github.com/dithpri/RCES/blob/master/LICENSE.md for more details.
*/
/* Permissions:
*
* GM.xmlHttpRequest, `connect docs.google.com`, `connect googleusercontent.com`:
* to automatically fetch and update members' nations.
*
* GM.setValue, GM.getValue:
* to save and load members' nations locally.
*/
function GM_addStyle(style) {
"use strict";
var node = document.createElement("style");
node.innerHTML = style;
document.getElementsByTagName("head")[0].appendChild(node);
}
const icon_base64 =
"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADIAAAAyCAMAAAAp4XiDAAACZFBMVEUAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABSUlIAAABjY2MAAAAXFxcAAAAAAAA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qT-TqOM7cTpr0/export?format=tsv&id=1lixnsslj-KhWd5-1f_ijcRcaPRi0aUqT-TqOM7cTpr0&gid=0";
(async function () {
"use strict";
const update_auctiontable = async function () {
const members_array = (await GM.getValue("naspaq", "")).split("\n");
document.querySelectorAll("#cardauctiontable > tbody > tr > td > p > a.nlink").forEach(function (el, i) {
const canonical_nname = el.getAttribute("href").replace(/^nation=/, "");
if (members_array.includes(canonical_nname)) {
el.parentNode.parentNode.classList.add("rces-cl-naspaq");
} else {
el.parentNode.parentNode.classList.remove("rces-cl-naspaq");
}
});
document.querySelectorAll("a.nlink:not(.rces-cl-naspaq-parsed)").forEach(function (el, i) {
const canonical_nname = el.getAttribute("href").replace(/^nation=/, "");
if (members_array.includes(canonical_nname)) {
const new_el = document.createElement("span");
new_el.classList.add("rces-cl-naspaq-inline");
el.parentNode.insertBefore(new_el, el);
el.classList.add("rces-cl-naspaq-parsed");
}
});
};
if (document.getElementById("auctiontablebox")) {
// If we haven't updated in the last 12h
if ((await GM.getValue("naspaq-lastupdate", 0)) + 12 * 60 * 60 * 1000 < new Date().getTime()) {
GM.xmlHttpRequest({
method: "GET",
url: sheet_url,
onload: async function (data) {
console.info("updated");
await GM.setValue(
"naspaq",
data.responseText
.split("\n")
.map((x) => x.split("\t")[4].trim().toLowerCase().replace(/ /g, "_"))
.slice(1)
.join("\n")
);
GM.setValue("naspaq-lastupdate", new Date().getTime());
update_auctiontable();
},
});
}
update_auctiontable();
let observer = new MutationObserver(function (mutationList) {
update_auctiontable();
});
const observerOptions = {
subtree: true,
childList: true,
};
observer.observe(document.getElementById("auctiontablebox"), observerOptions);
GM_addStyle(`
.rces-cl-naspaq {
background-repeat: no-repeat;
}
tr > td.rces-cl-naspaq:nth-child(1) {
background-image: linear-gradient(90deg, rgba(255,255,255,0), rgb(255,255,255) 50px, rgba(255,255,255,0) 100px), url('${icon_base64}');
background-position: left;
}
tr > td.rces-cl-naspaq:nth-child(5) {
background-image: linear-gradient(270deg, rgba(255,255,255,0), rgb(255,255,255) 50px, rgba(255, 255, 255, 0) 100px), url('${icon_base64}');
background-position: right;
}
.rces-cl-naspaq-inline {
background-repeat: no-repeat;
background-image: url('${icon_base64}');
filter: drop-shadow(0px 0px 1px);
background-size: contain;
padding-left: 1.5em;
}
`);
}
})();