forked from hlfbt/AnimeBytes-Userscripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathab_notifications.user.js
421 lines (390 loc) · 33.9 KB
/
ab_notifications.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
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
// ==UserScript==
// @name AnimeBytes Notifications
// @author potatoe
// @version 2.5
// @description shows toasty notifications for various things!.
// @include *animebyt.es/*
// @include *animebytes.tv/*
// @icon http://animebytes.tv/favicon.ico
// ==/UserScript==
/*
* Check wether the Browser supports Notifications and if they are granted for AnimeBytes
*/
if (!("Notification" in window)) alert("Notifications are not supported by your browser!");
if (Notification.permission !== "granted") document.getElementById('alerts').innerHTML += "<div id='notificationsalert' class='alertbar message' style='background: #FFB2B2; border: 1px solid #D45A5A;'><a href='javascript:Notification.requestPermission(function () {document.getElementById(\"notificationsalert\").parentNode.removeChild(document.getElementById(\"notificationsalert\"));});' style='color: #E40000;'>Enable Notifications</a></div>"
if (Notification.permission === "denied") alert("Notifications are denied for AnimeBytes, please reenable them in your browsers settings or disable/remove this userscript (AnimeBytes Notifications).")
/*
* Define some basic needed Functions and Objects
*/
// Native script support for Chrome
if (!this.GM_getValue || (this.GM_getValue.toString && this.GM_getValue.toString().indexOf("not supported")>-1)) {
this.GM_getValue=function (key,def) { return localStorage[key] || def; };
this.GM_setValue=function (key,value) { return localStorage[key]=value; };
this.GM_deleteValue=function (key) { return delete localStorage[key]; };
}
// Simple custom NetworkError that gets thrown in case a XMLHttpRequest fails
NetworkError = function (message) {
this.name = "NetworkError";
this.message = (message || "");
};
NetworkError.prototype = Error.prototype;
// Custom UserscriptEvent that can be fired for various custom Events. Most notably error Events!
// UserscriptEvent not yet fully supported (dispatchEvent() doesn't seem to accept any other than the standard Events).
/*UserscriptEvent = function (type, source, obj) {
if (typeof type === "undefined") throw new TypeError("Failed to construct 'UserscriptEvent': An event name must be provided.");
if (typeof obj !== "undefined" && typeof obj !== "object") throw new TypeError("Failed to construct 'UserscriptEvent': Argument is not an object.");
var evt = new Event(type);
for (var k in evt) this[k] = evt[k];
for (var k in obj) this[k] = obj[k];
this.source = (source || "AnimeBytes Notifications");
};*/
UserscriptEvent = function (type, source, obj) {
if (typeof type === "undefined") throw new TypeError("Failed to construct 'UserscriptEvent': An event name must be provided.");
if (typeof obj !== "undefined" && typeof obj !== "object") throw new TypeError("Failed to construct 'UserscriptEvent': Argument is not an object.");
var evt = new CustomEvent(type);
for (var k in obj) evt[k] = obj[k];
evt.name = "UserscriptEvent";
evt.source = (source || "AnimeBytes Notifications");
return evt;
}
UserscriptEvent.prototype = CustomEvent.prototype;
// Don't you hate it to build a new XMLHttpRequest every single time you want to fetch a site?!
// Yea, I do too...
// Depends on NetworkError
function XHRWrapper(location, callback, method, sync, data) {
if (this.constructor != XHRWrapper) throw new TypeError("Constructor XHRWrapper requires 'new'");
this.name = "XHRWrapper";
this.typeOf = function () { return this.name; };
this.toString = function () { return '[object ' + this.name + ']'; };
this.valueOf = function () { return this; };
var xhr = new XMLHttpRequest();
Object.defineProperty(this, 'xmlHttpRequest', {
get: function () { return xhr; },
set: function () { return xhr; }
});
xhr.onerror = function(e) {
var netErr = new Error("A Network Error occured while loading the resource");
// Custom error code handling if client error occurs
var xhr = e.target;
if (xhr.status == 331) netErr.message += "\nSystem went to sleep/was suspended";
netErr.xmlHttpRequestProgressEvent = e;
netErr.xmlHttpRequest = xhr;
if (typeof error !== "undefined") { error = netErr; }
else { throw netErr; }
};
xhr.onreadystatechange = function(xhrpe) {
var xhr = xhrpe.target;
if (xhr.readyState == 4 && xhr.status == 200) {
var doc = document.implementation.createHTMLDocument();
doc.documentElement.innerHTML = xhr.responseText;
xhr.__callback(doc);
}
else if (xhr.readyState == 4 && xhr.status != 200) {
var netErr = new NetworkError();
// Custom error code handling if server error occurs
console.log("Error Code " + xhr.status + " (" + xhr.statusText + ")");
if (xhr.status == 331) netErr.message = "System went to sleep/was suspended";
throw netErr
}
};
this.location = xhr.__location = location;
this.callback = xhr.__callback = callback;
xhr.open(method || 'GET', location, (typeof sync==="undefined")?true:sync);
xhr.send(data);
return this;
}
// Make it completely seemless. For this we 'cheat' a bit by simply copying all property names in a new XHR and assigning them getters/setters to our private XHR Object.
// This does have the drawback that the 'on...' handlers will be the same for both the Wrapper and XHR, but that's not a problem for this usecase.
for (var key in new XMLHttpRequest()) {
if (!(key in ['addEventListener', 'removeEventListener', 'dispatchEvent']) && key !== key.toUpperCase()) { // Those should be seperate thought! Same with constants.
Object.defineProperty(XHRWrapper.prototype, key, {
get: new Function("return this.xmlHttpRequest."+key+";"),
set: new Function('val', "return this.xmlHttpRequest."+key+" = val;")
});
}
}
// Make some noise!
function CustomAudio (src) {
this.audio = document.createElement('audio');
if (arguments[0]) this.audio.src = arguments[0];
if (Object.defineProperty) { // The proper way
Object.defineProperty(this, 'src', {
get: function(){ return this.audio.src; },
set: function(src){ if (!arguments[0]) { this.audio.removeAttribute('src'); } else { this.audio.src = arguments[0]; } return arguments[0]; }
});
} else { // The deprecated way
this.__defineGetter__('src', function(){ return this.audio.src; });
this.__defineSetter__('src', function(src){ if (!arguments[0]) { this.audio.removeAttribute('src'); } else { this.audio.src = arguments[0]; } return arguments[0]; });
}
this.play = function() { this.audio.play(); };
return this;
}
// This helps initializing all the GM variables
// Sets 'def' to 'gm' or returns 'gm's value if already set
// 'json' controlls wether the variable is/should be encoded as JSON String
// 'overwrite' controlls wether to overwrite 'gm' if it is not the same type as 'def'
function initGM(gm, def, json, overwrite) {
if (typeof def === "undefined") throw "shit";
if (typeof overwrite !== "boolean") overwrite = true;
if (typeof json !== "boolean") json = true;
var that = GM_getValue(gm);
if (that != null) {
var err = null;
try { that = ((json)?JSON.parse(that):that); }
catch (e) { if (e.message.match(/Unexpected token .*/)) err = e; }
if (!err && Object.prototype.toString.call(that) === Object.prototype.toString.call(def)) { return that; }
else if (overwrite) {
GM_setValue(gm, ((json)?JSON.stringify(def):def));
return def;
} else { if (err) { throw err; } else { return that; } }
} else {
GM_setValue(gm, ((json)?JSON.stringify(def):def));
return def;
}
}
/*
* Initialize all needed GM or global variables
*/
// Initialize all the GM variables
var notifyInterval = initGM('notifyinterval', 300);
var notifyTimeout = initGM('notifytimeout', 15);
var oldPMs = initGM('oldpms', {});
var oldPosts = initGM('oldposts', {});
var oldRecentThreads = initGM('oldrecentthreads', {});
var gm_aotf = initGM('aotf', '', false);
var gm_aotw = initGM('aotw', '', false);
var gm_icon = initGM('notifyicon', 'data:image/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EyWEtV2Vcn9rpOXRc0LWHcMrUGpqjfxCjLunsybEZB5TngTz1GAuL8pWaR7rjSUzXHvPR5ILSqBunuLJi82FZYMojuG1gBYlUxdz+Hesyzw4b5lmRbuWjrKThVlNw2fs6V6F8r2yQVbilTUMTQav13reCTtHDNfw0U7/yePc8DngM8BnwM+B/y/U/47APgkYRik+rGGAAAAAElFTkSuQmCC', false);
var gm_sound = initGM('notifysound', 'data:audio/ogg;base64,T2dnUwACAAAAAAAAAAD7EQAAAAAAABQugBABHgF2b3JiaXMAAAAAAkSsAAAAAAAAAGsDAAAAAAC4AU9nZ1MAAAAAAAAAAAAA+xEAAAEAAACx2aLvEC3//////////////////3EDdm9yYmlzHQAAAFhpcGguT3JnIGxpYlZvcmJpcyBJIDIwMDcwNjIyAAAAAAEFdm9yYmlzK0JDVgEACAAAADFMIMWA0JBVAAAQAABgJCkOk2ZJKaWUoSh5mJRISSmllMUwiZiUicUYY4wxxhhjjDHGGGOMIDRkFQAABACAKAmOo+ZJas45ZxgnjnKgOWlOOKcgB4pR4DkJwvUmY26mtKZrbs4pJQgNWQUAAAIAQEghhRRSSCGFFGKIIYYYYoghhxxyyCGnnHIKKqigggoyyCCDTDLppJNOOumoo4466ii00EILLbTSSkwx1VZjrr0GXXxzzjnnnHPOOeecc84JQkNWAQAgAAAEQgYZZBBCCCGFFFKIKaaYcgoyyIDQkFUAACAAgAAAAABHkRRJsRTLsRzN0SRP8ixREzXRM0VTVE1VVVVVdV1XdmXXdnXXdn1ZmIVbuH1ZuIVb2IVd94VhGIZhGIZhGIZh+H3f933f930gNGQVACABAKAjOZbjKaIiGqLiOaIDhIasAgBkAAAEACAJkiIpkqNJpmZqrmmbtmirtm3LsizLsgyEhqwCAAABAAQAAAAAAKBpmqZpmqZpmqZpmqZpmqZpmqZpmmZZlmVZlmVZlmVZlmVZlmVZlmVZlmVZlmVZlmVZlmVZlmVZlmVZQGjIKgBAAgBAx3Ecx3EkRVIkx3IsBwgNWQUAyAAACABAUizF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VEIpoZRSSimllJRSKimVUkopoYRSQgmllFRSSamUUkoJpZRSSkmllFJKKaWUUkoppZRSUkmplFJCKCWEEkopJaVSSimlhFBKCaGUUkoqqZRSSgmllFJKKaUAAKADBwCAACMqLcROM648AkcUMkxAhYasBABSAQAAQiillFJKKTVKUUoppZRSahijlFJKKaWUUkoppZRSSimllFJKKaWUUkoppZRSSimllFJKKaWUUkoppZRSSimllFJKKaWUUkoppZRSSimllFJKKaWUUkoppZRSSimllFJKKaWUUkoppZRSAcDdFw6APhM2rI5wUjQWWGjISgAgFQAAMIYxxphyzjmllHPQOQYdlUgp56BzTkJKvXPQQQidhFR65yCUEkIpKfUYQygllJRa6jGGTkIppaTUa+8ghFRSaqn3HjLJqKTUUu+9tVBSaqm13nsrJaPOUmu9595TK6Wl1nrvOadUSmutFQBgEuEAgLhgw+oIJ0VjgYWGrAIAYgAACEMMQkgppZRSSinGGGOMMcYYY4wxxhhjjDHGGGOMMQEAgAkOAAABVrArs7Rqo7ipk7zog8AndMRmZMilVMzkRNAjNdRiJdihFdzgBWChISsBADIAAMRRzLXGXCuDGJSUaiwNQcxBibFlxiDloNUYKoSUg1ZbyBRCylFqKXRMKSYpphI6phSkGFtrJXSQWs25tlRKCwAAgCAAwECEzAQCBVBgIAMADhASpACAwgJDx3AREJBLyCgwKBwTzkmnDQBAECIzRCJiMUhMqAaKiukAYHGBIR8AMjQ20i4uoMsAF3Rx14EQghCEIBYHUEACDk644Yk3POEGJ+gUlToQAAAAAAAIAHgAAEg2gIhoZuY4Ojw+QEJERkhKTE5QUlQEAAAAAAAQAD4AAJIVICKamTmODo8PkBCREZISkxOUFJUAAEAAAQAAAAAQQAACAgIAAAAAAAEAAAACAk9nZ1MABE0DAAAAAAAA+xEAAAIAAADDUhavCeTe5t/ZtK7/r9zwCrANZVwEcigzP0+gdnlWIw50sI/My7/+74fW5fPb9eL8tn4vv7/8fP79z689Lgf+8gofv776288/v357+/rzvnoRa01r3NXp5XH343/8eK6fP+6de9+PPa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Paz8ziP8ziPjx8+fvj44eOHjx8+fvh4nMd5ZABZLv+gH/SDftAP+kHHeZwfPn74eHz88PHDx+P8QT/oB5XLQPbjcR4ZCQCQR0dHR0dHHB0dHWF2Ob16+e3lVb+YGwDg6Ojo6Ojo6Ajso6Ojo6Ojo6Ojo6OjIwDUcvnbHzQ7Ozs7Ozs7Ozs7Ozs7Ozs7O5sB2EdHR0dHR0dHR0dHR0dHR0dHRwkA', false);
// Initialize all other global variables
var userID = document.getElementById('username_menu').firstChild.getAttribute('href').replace(/.*id=([0-9]+).*/, '$1');
var error = null;
/*
* All the actual "work" Functions
*/
// Creates a Userscript Settings Page or adds configuration options if it already exists
function createSettingsPage() {
function injectScript(content, id) {
var script = document.createElement('script');
if (id) script.setAttribute('id', id);
script.textContent = content.toString();
document.body.appendChild(script);
return script;
}
function addCheckbox(title, description, varName, onValue, offValue) {
if (typeof onValue !== "string" || typeof offValue !== "string" || onValue === offValue) onValue='true', offValue='false';
var newLi = document.createElement('li');
this[varName] = initGM(varName, onValue, false);
newLi.innerHTML = "<span class='ue_left strong'>"+title+"</span>\n<span class='ue_right'><input type='checkbox' onvalue='"+onValue+"' offvalue='"+offValue+"' name='"+varName+"' id='"+varName+"'"+((this[varName]===onValue)?" checked='checked'":" ")+">\n<label for='"+varName+"'>"+description+"</label></span>";
newLi.addEventListener('click', function(e){var t=e.target;if(typeof t.checked==="boolean"){if(t.checked){GM_setValue(t.id,t.getAttribute('onvalue'));}else{GM_setValue(t.id,t.getAttribute('offvalue'));}}});
var poselistNode = document.getElementById('pose_list');
poselistNode.appendChild(newLi);
return newLi;
}
function addNumberInput(title, description, varName, defValue) {
if (typeof defValue !== "integer") defValue = (JSON.parse(GM_getValue(varName)) || 0);
var newLi = document.createElement('li');
this[varName] = initGM(varName, defValue);
newLi.innerHTML = "<span class='ue_left strong'>"+title+"</span>\n<span class='ue_right'><input type='number' size='50' name='"+varName+"' id='"+varName+"' value='"+this[varName]+"'> <span>"+description+"</span></span>";
newLi.addEventListener('keypress', function(e){var t=(e.which?e.which:e.keyCode),n=+e.target.value.replace(/(.)-/g,'$1');if(t===13&&!isNaN(n))GM_setValue(e.target.id,JSON.stringify(n));if(t===13||(t>31&&t!==45&&(t<48||t>57)))e.preventDefault();});
newLi.addEventListener('blur', function(e){var n=+e.target.value.replace(/(.)-/g,'$1');if(!isNaN(n))GM_setValue(e.target.id,JSON.stringify(n));}, true);
var poselistNode = document.getElementById('pose_list');
poselistNode.appendChild(newLi);
return newLi;
}
function addTextInput(title, description, varName, defValue) {
if (typeof defValue !== "string") defValue = (GM_getValue(varName) || "");
var newLi = document.createElement('li');
this[varName] = initGM(varName, defValue, false);
newLi.innerHTML = "<span class='ue_left strong'>"+title+"</span>\n<span class='ue_right'><input type='text' style='margin: 0;' size='50' name='"+varName+"' id='"+varName+"' value='"+this[varName]+"'> <span>"+description+"</span></span>";
newLi.addEventListener('keypress', function(e){var t=e.which?e.which:e.keyCode;if(t===13){GM_setValue_setValue(e.target.id,e.target.value);e.preventDefault();}});
newLi.addEventListener('blur', function(e){GM_setValue(e.target.id,e.target.value);}, true);
var poselistNode = document.getElementById('pose_list');
poselistNode.appendChild(newLi);
return newLi;
}
function addCustom(title, description) {
var newLi = document.createElement('li');
newLi.innerHTML = "<span class='ue_left strong'>"+title+"</span>\n<span class='ue_right'>"+description+"</span>";
var poselistNode = document.getElementById('pose_list');
poselistNode.appendChild(newLi);
return newLi;
}
function relink(){$j(function(){var stuff=$j('#tabs > div');$j('ul.ue_tabs a').click(function(){stuff.hide().filter(this.hash).show();$j('ul.ue_tabs a').removeClass('selected');$j(this).addClass('selected');return false;}).filter(':first,a[href="'+window.location.hash+'"]').slice(-1)[0].click();});}
var pose = document.createElement('div');
pose.id = "potatoes_settings";
pose.innerHTML = '<div class="head colhead_dark strong">User Script Settings</div><ul id="pose_list" class="nobullet ue_list"></ul>';
var poseanc = document.createElement('li');
poseanc.innerHTML = '•<a href="#potatoes_settings">User Script Settings</a>';
var tabsNode = document.getElementById('tabs');
var linksNode = document.getElementsByClassName('ue_tabs')[0];
if (document.getElementById('potatoes_settings') == null) { tabsNode.insertBefore(pose, tabsNode.childNodes[tabsNode.childNodes.length-2]); linksNode.appendChild(poseanc); document.body.removeChild(injectScript('('+relink.toString()+')();', 'settings_relink')); }
addCheckbox("PM Notifications", "Notify about new private messages.", 'pmnotify');
addCheckbox("Bookmarks Notifications", "Notify if someone posted in a bookmarked thread.", 'bookmarknotify');
addCheckbox("AotF/AotW Notifications", "Notify if a new AotF or AotW have been chosen.", 'aotxnotify');
addCheckbox("Recent Threads Notifications", "Notify about a new post in a thread I recently posted in.", 'recentthreadnotify');
addNumberInput("Notification Check Interval", "(in seconds)", 'notifyinterval');
addNumberInput("Notification Timeout", "(in seconds) when the notifications should close automatically again.<br />0 for same as check interval, negative for indefinitely.", 'notifytimeout');
addTextInput("Notification Icon", "(url or base64)", 'notifyicon');
addTextInput("Notification Sound", "(url or base64)", 'notifysound');
addCustom("Test Notifications", "<a href='#' onclick='return false;' id='notifytest'>Click me!</a>");
addCustom("Reset Notifications", "Warning: this will reset all old, saved notifications. You might get spammed. <a href='#' onclick='return false;' id='notifyreset'>Reset</a>.");
document.getElementById('notifytest').addEventListener('click', function(){var testNotification=new Notification("Test Notification",{icon:GM_getValue('notifyicon'),body:"Hello World!"});testNotification.onclick=function(){this.close();};var notifyTimeout=JSON.parse(GM_getValue('notifytimeout'));if(notifyTimeout>=0)window.setTimeout(function(){testNotification.close();},((notifyTimeout==0)?notifyInterval:notifyTimeout)*1000);new CustomAudio(GM_getValue('notifysound')).play();});
document.getElementById('notifyreset').addEventListener('click', function(){if(confirm("Really?")){GM_deleteValue('oldpms');GM_deleteValue('oldposts');GM_deleteValue('oldrecentthreads');GM_deleteValue('aotf');GM_deleteValue('aotw');initGM('oldpms', {});initGM('oldposts', {});initGM('oldrecentthreads', {});initGM('aotf', '', false);initGM('aotw', '', false);var resetNotification=new Notification("Notifications reset!",{icon:GM_getValue('notifyicon'),body:"All old, saved Notifications have been reset."});resetNotification.onclick=function(){this.close();};window.setTimeout(function(){resetNotification.close();},15e3);}});
}
// Checks 'doc' for new PMs ('doc' should be a document element of the '/inbox.php' page)
function checkPMs(doc) {
var unreadpms = new Array();
var newpmnode = doc.evaluate("//tr[@class='unreadpm'][1]", doc, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
for (var i=2; newpmnode!=null; i++) {
unreadpms.push(newpmnode);
newpmnode = doc.evaluate("//tr[@class='unreadpm']["+i+"]", doc, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
}
for (var i=0; i<unreadpms.length; i++) {
var senderTd = null, sender = null, subject = null, id = null, epoch = null;
senderTd = unreadpms[i].getElementsByTagName('td')[2];
sender = (senderTd.getElementsByTagName('a').length > 0) ? senderTd.getElementsByTagName('a')[0].innerHTML : senderTd.innerHTML;
subject = unreadpms[i].getElementsByTagName('a')[0].innerHTML;
id = unreadpms[i].getElementsByTagName('input')[0].value;
epoch = new Date(unreadpms[i].getElementsByTagName('span')[0].getAttribute('title')).getTime() / 1000;
oldPMs = JSON.parse(GM_getValue('oldpms'));
if (oldPMs[id] !== epoch) {
eval("window.pmnotif"+id+" = new Notification('New PM from "+sender+"', {icon:'"+GM_getValue('notifyicon')+"', body:'"+subject+"', tag:'pm"+id+"'})");
eval("window.pmnotif"+id+".onclick = function () { window.open('/inbox.php?action=viewconv&id="+id+"#latest'); this.close(); }");
var notifyTimeout = JSON.parse(GM_getValue('notifytimeout'));
if (notifyTimeout >= 0) window.setTimeout(eval('(function(){window.pmnotif'+id+'.close();})'), ((notifyTimeout==0)?notifyInterval:notifyTimeout)*1000);
oldPMs[id] = epoch;
GM_setValue('oldpms', JSON.stringify(oldPMs));
new CustomAudio(GM_getValue('notifysound')).play();
}
}
}
// Checks 'doc' for new AotW and AotF ('doc' should be a document element of the '/index.php' page)
function checkAotx(doc) {
var aotf = null, aotftitle = null, aotfnode = doc.getElementById('aotf'), aotw = null, aotwtitle = null, aotwnode = doc.getElementById('aotw');
aotf = aotfnode.getElementsByTagName('a')[0].getAttribute('href');
aotw = aotwnode.getElementsByTagName('a')[0].getAttribute('href');
aotftitle = aotfnode.getElementsByTagName('img')[0].getAttribute('title');
aotwtitle = aotwnode.getElementsByTagName('img')[0].getAttribute('title');
gm_aotf = initGM('aotf', aotf, false);
gm_aotw = initGM('aotw', aotw, false);
if (aotf !== gm_aotf && aotf !== "") {
var aotfNotification = new Notification("New Anime of the Fortnight!", {icon:GM_getValue('notifyicon'), body:aotftitle})
aotfNotification.onclick = new Function("window.open('"+aotf+"')");
var notifyTimeout = JSON.parse(GM_getValue('notifytimeout'));
if (notifyTimeout >= 0) window.setTimeout(function(){aotfNotification.close();}, ((notifyTimeout==0)?notifyInterval:notifyTimeout)*1000);
gm_aotf = aotf;
GM_setValue('aotf', gm_aotf);
new CustomAudio(GM_getValue('notifysound')).play();
}
if (aotw !== gm_aotw && aotw !== "") {
var aotwNotification = new Notification("New Album of the Week!", {icon:GM_getValue('notifyicon'), body:aotwtitle})
aotwNotification.onclick = new Function("window.open('"+aotw+"'); this.close();");
var notifyTimeout = JSON.parse(GM_getValue('notifytimeout'));
if (notifyTimeout >= 0) window.setTimeout(function(){aotwNotification.close();}, ((notifyTimeout==0)?notifyInterval:notifyTimeout)*1000);
gm_aotw = aotw;
GM_setValue('aotw', gm_aotw);
new CustomAudio(GM_getValue('notifysound')).play();
}
}
// Checks 'doc' for new Posts in bookmarked Threads ('doc' should be a document element of the '/bookmarks.php?type=3' page)
function checkBookmarks(doc) {
var bookmarksTable = doc.evaluate("//div[@id='content']/div[@class='thin']/table[@width='100%']", doc, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
for (var i=bookmarksTable.rows.length-1; row=(i>0)?bookmarksTable.rows[i]:null; i--) {
if (row.cells[0].getElementsByTagName('img')[0].getAttribute('class') === 'unread') {
var link = null, title = null, id = null, poster = null, date = null, epoch = null;
link = row.cells[1].getElementsByClassName('go-last-read')[0].parentNode.getAttribute('href');
title = row.cells[1].getElementsByTagName('strong')[0].innerText.trim();
id = row.cells[1].getElementsByTagName('strong')[0].getElementsByTagName('a')[0].getAttribute('href').match(/.*threadid=([0-9]+).*/)[1];
poster = row.cells[4].innerText.match(/By (.*)\n.*/)[1];
date = row.cells[4].getElementsByTagName('span')[0].getAttribute('title');
epoch = new Date(date).getTime() / 1000;
oldPosts = JSON.parse(GM_getValue('oldposts'));
if (oldPosts[id] !== epoch) {
eval("window.bmnotif"+id+" = new Notification('New Post in "+title+"', {icon:'"+GM_getValue('notifyicon')+"', body:'By "+poster+" on "+date+"', tag:'post"+id+"'})");
eval("window.bmnotif"+id+".onclick = function () { window.open('"+link+"'); this.close(); }");
var notifyTimeout = JSON.parse(GM_getValue('notifytimeout'));
if (notifyTimeout >= 0) window.setTimeout(eval('(function(){window.bmnotif'+id+'.close();})'), ((notifyTimeout==0)?notifyInterval:notifyTimeout)*1000);
oldPosts[id] = epoch;
GM_setValue('oldposts', JSON.stringify(oldPosts));
new CustomAudio(GM_getValue('notifysound')).play();
}
}
}
}
// Checks 'doc' for new Posts in recent Threads ('doc' should be a document element of the '/userhistory.php?action=posts&userid=USERID' page where USERID is the Users ID)
function checkRecentThreads(doc) {
var unreadrecentthreads = new Array();
var newrecentthreadnode = doc.evaluate("//table[contains(@class,'forum_post')]/tbody/tr/td/span[.='(New!)'][1]", doc, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
for (var i=2; newrecentthreadnode!=null; i++) {
unreadrecentthreads.push(newrecentthreadnode.parentNode);
newrecentthreadnode = doc.evaluate("//table[contains(@class,'forum_post')]/tbody/tr/td/span[.='(New!)']["+i+"]", doc, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
}
for (var i=0; i<unreadrecentthreads.length; i++) {
var title = null, link = null, id = null, epoch = null;
title = unreadrecentthreads[i].getElementsByTagName('a')[0].innerText;
link = unreadrecentthreads[i].getElementsByTagName('a')[1].getAttribute('href');
id = unreadrecentthreads[i].parentNode.parentNode.parentNode.id.replace('post', '');
epoch = new Date(unreadrecentthreads[i].getElementsByTagName('span')[0].innerText).getTime() / 1000;
oldRecentThreads = JSON.parse(GM_getValue('oldrecentthreads'));
oldPosts = JSON.parse(GM_getValue('oldposts'));
if (oldRecentThreads[id] !== epoch && (oldPosts[id] == null || oldPosts[id] < epoch)) {
eval("window.rtnotif"+id+" = new Notification('New Post in a recent Thread!', {icon:'"+GM_getValue('notifyicon')+"', body:'"+title+"', tag:'post"+id+"'})");
eval("window.rtnotif"+id+".onclick = function () { window.open('"+link+"'); this.close(); }");
var notifyTimeout = JSON.parse(GM_getValue('notifytimeout'));
if (notifyTimeout >= 0) window.setTimeout(eval('(function(){window.rtnotif'+id+'.close();})'), ((notifyTimeout==0)?notifyInterval:notifyTimeout)*1000);
oldRecentThreads[id] = epoch;
GM_setValue('oldrecentthreads', JSON.stringify(oldRecentThreads));
new CustomAudio(GM_getValue('notifysound')).play();
}
}
}
/*
* Now put all that together and do stuff!
*/
if (window.location.pathname === '/user.php' && window.location.search.indexOf('action=edit') > -1) createSettingsPage();
window.setInterval(function () {
error = null;
var checks = [
{
condition: GM_getValue('pmnotify') === 'true',
location: '/inbox.php',
callback: checkPMs
},
{
condition: GM_getValue('bookmarknotify') === 'true',
location: '/bookmarks.php?type=3',
callback: checkBookmarks
},
{
condition: GM_getValue('aotxnotify') === 'true',
location: '/index.php',
callback: checkAotx
},
{
condition: GM_getValue('recentthreadnotify') === 'true' && userID != null,
location: '/userhistory.php?action=posts&userid='+userID,
callback: checkRecentThreads
}
]
function work(checks) {
if (typeof checks === "undefined") throw new Error("No checks to work");
var c = checks.shift();
if (typeof c !== "undefined" && c.condition) window.setTimeout(function () {
try {
if (typeof error === "undefined" || !error) {
new XHRWrapper(c.location, c.callback, c.method, c.sync, c.data);
work(checks);
}
else {
throw error;
}
}
catch (e) {
document.dispatchEvent(new UserscriptEvent("error", null, e));
console.log("Error fetching new notifications: " + e.toString());
console.log(e);
}
}, 1e3);
}
work(checks);
}, notifyInterval * 1e3);