-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathNsIssueCompactorRand.user.js
85 lines (75 loc) · 2.29 KB
/
NsIssueCompactorRand.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
// ==UserScript==
// @name NsIssueCompactorRand-GM
// @version 0.4.2
// @namespace dithpri.RCES
// @description Hide everything except issue buttons and focus on a random option (GM-compat version)
// @author dithpri
// @downloadURL https://github.com/dithpri/RCES/raw/GM-Hacks/userscripts/issue_answering/NsIssueCompactorRand.user.js
// @noframes
// @match https://www.nationstates.net/*page=show_dilemma/*x-rces=openissue
// @grant window.close
// @run-at document-end
// ==/UserScript==
/*
* Copyright (c) 2019-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.
*/
function addStyle(style) {
"use strict";
var node = document.createElement("style");
node.innerHTML = style;
document.getElementsByTagName("head")[0].appendChild(node);
}
(function () {
addStyle(`
body > *, body > #banner, .smalltext, .dilemmapaper, p, h5 {display : none;}
body > #dilemma, body > #main, p.dilemmaaccept, p.dilemmadismissbox {display: initial;}
button.button.big.icon.approve, p.dilemmadismissbox > button.big.icon.remove.danger {
visibility: initial;
}
ol {
list-style: none;
padding-left: 0;
}
button.rces-chosen {
font-weight: 700;
}
p.dilemmadismissbox {
position: fixed;
top: 0;
right: 0;
}
* { visibility: hidden;}
`);
document
.querySelectorAll('form[action^="/page=enact_dilemma/"]')
.forEach(function (el) {
el.action += "/template-overall=none/x-rces=autoclose";
el.target = "_blank";
});
const issuebtns = document.querySelectorAll(
"button.button.big.icon.approve"
);
if (issuebtns.length > 0) {
document.querySelector(
"p.dilemmadismissbox > button.big.icon.remove.danger"
).disabled = true;
const chosenButtonNumber = Math.floor(Math.random() * issuebtns.length);
issuebtns[chosenButtonNumber].classList.add("rces-chosen");
document.addEventListener("keyup", function (ev) {
if (ev.key != "Enter" || ev.repeat) {
ev.preventDefault();
return;
}
document
.querySelectorAll("button.button.big.icon")
.forEach(function (el) {
el.style.display = "none";
});
issuebtns[chosenButtonNumber].click();
window.close();
});
}
})();