forked from lg188/volafile-scripts
-
Notifications
You must be signed in to change notification settings - Fork 2
/
volafile-mod.user.js
234 lines (211 loc) · 5.86 KB
/
volafile-mod.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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
// ==UserScript==
// @name volafile-mod
// @namespace org.lg188.volafile-mod
// @description Aids the current volafile moderators
// @include https://volafile.org/*
// @exclude https://volafile.org/
// @exclude https://volafile.org/rules
// @exclude https://volafile.org/top/*
// @exclude https://volafile.org/tos
// @exclude https://volafile.org/privacy
// @exclude https://volafile.org/impressum
// @exclude https://volafile.org/user/*
// @exclude https://volafile.org/donate
// @exclude https://volafile.org/about
// @exclude https://volafile.org/faq
// @exclude https://volafile.org/different
// @exclude https://volafile.org/credits
// @version 0.3.0-rc2
// @grant none
// @require https://code.jquery.com/jquery-2.1.3.js
// @require http://notifyjs.com/dist/notify-combined.js
// ==/UserScript==
// Default Settings
var defaultconf = { interval : 60, threshold : 72, debug : true, rate: 1, regex: false};
var config = defaultconf;
var regex = [];
/*
* Save a value int the local storage
*/
function save(key, value) { localStorage.setItem(key, JSON.stringify(value)); }
/*
* Load a value from the local storage
*/
function load(key) {return JSON.parse(localStorage.getItem(key));}
function log(str, type){
if(typeof type === 'undefined'){ type = "info";}
$.notify(str, type);
}
if(load("config:data")){
config = load("config:data");
if(typeof config.interval === 'undefined' || isNaN(config.rate) ){
config.interval = defaultconf.interval;
}
if(typeof config.threshold === 'undefined' || isNaN(config.interval) ){
config.threshold = defaultconf.threshold;
}
if(typeof config.debug === 'undefined' ){
config.debug = defaultconf.debug;
}
if(typeof config.rate === 'undefined' || isNaN(config.rate) ){
config.rate = defaultconf.rate;
}
if(typeof config.regex === 'undefined' ){
config.regex = defaultconf.regex;
}
}
var path = window.location.pathname;
var loc = "undetected";
var roomID = "";
var counter = 0;
var help = "n next room (preceded by history) \n N next room in new tab\n p go back into history\n r reload\n q quit \n : execute command \n F1 help \n / search \n i insert";
var help2= "s[et] <variable> [<value>] \n d[el] <variable>";
switch(path){
case "/adiscover":
loc = "adiscover";
break;
case "reports":
loc = "reports";
break;
default:
if(path.match(/^\/r\/.{1,}/)){
loc = "room";
counter = -1;
roomID = path.match(/^\/r\/(.{1,})/)[1];
window.addEventListener('unload', saveData);
window.addEventListener('keypress',keyHandler);
var wrench = $("#room_settings > span");
if(wrench){
wrench.append("<span id='room_public'>P<span>");
}
}
}
setInterval(tick, config.rate * 1000);
function saveData(e,state){
if(typeof state === 'undefined'){
state = "closed";
}
//collect data;
var data = {"state" : state};
var strgID = "meta:" + roomID;
data.date = Date.now();
data.private = window.config.private;
data.disabled = window.config.disabled;
save(strgID, data);
}
function tick(){
save("config:data", config);
$("a ").not("nVolaLink").each(colourLinks);
if(loc == "room"){
saveData(null, "open");
if(window.config.disabled){
$("#room_name").css({color: "grey"});
}else{
var colour = $("body").css("color");
$("#room_name").css({color: colour });
}
if(!window.config.private){
$("#room_public").css({visibility: "visible "});
}else{
$("#room_public").css({visibility: "hidden"});
}
}
if(counter > -1){
counter++;
if(counter >= config.interval){
location.reload();
}
}
}
function colourLinks(){
var dest = $(this).context;
if(dest.pathname.match(/^\/r\/.{1,}/) && dest.hostname == "volafile.org"){
var id = dest.pathname.match(/^\/r\/(.{1,})/)[1];
var strgID = "meta:" + id;
var roomData = load(strgID);
if( roomData !== null){
if(roomData.disabled !== true ){
$(this).css({color: "cyan"});
if(roomData.state == "open"){
$(this).css({color: "#D880FC"});
}else{
if(roomData.date !== null && roomData.state == "closed"){
var now = Math.floor(Date.now() / 1000);
var diff = now - Math.floor(roomData.date/1000);
var value = (diff / (config.threshold * 3600))*255;
if(value > 255) {
value = 255;
try{
var strTarget = load("config:next");
if(strTarget === "" || load("meta:"+strTarget) !== undefined ){
save("config:next", id);
}
}catch(e){
console.log(e);
}
} else {
value = Math.ceil(value);
}
var r = value;
var g = 255-value;
var b = 50;
var rgb = "rgb(" + r + "," + g + "," + b + ")";
$(this).css({color:rgb});
}else{
$(this).css({color:"pink"});
}
}
}else{
$(this).css({color: "grey"});
}
}else{
if( !load(strgID) ){
save("config:next", id);
}
}
}else{
if(dest.hostname == "volafile.org" && dest.pathname.match(/^\/get\/.{1,}/)){
reg(this);
}else{
$(this).addClass("nVolaLink");
}
}
}
function keyHandler(e){
var key = e.key;
var target = e.target.toString();
var TextArea = target.search(/TextAreaElement/);
var input = target.search(/InputElement/);
if(TextArea < 0 && input < 0 ){
var next , nextURL;
switch(key){
}
}else{
if(key == "Escape" || key == "Esc"){
document.getElementById("room_filters").style.display = "none";
document.getElementById("room_search").style.display = "none";
document.getElementById("show_search_ui").style.display = "";
document.activeElement.blur();
}
}
}
function reg(obj){
if(config.regex){
try{
for(var i = 0; i < regex.length; i++){
var re = regex[i];
var data = re.split("/");
//console.log(data);
if(data[2].match(/\b[fu]\b/)){
var color = /color:\((\x{3}|\x{6})\)/;
color = data[2].match(color);
if(obj.innerHTML.match(data[1])){
$(obj).css({"color":"pink"});
}
}
}
}catch(e){
console.log(e);
}
}
}