forked from aldykins/delicious
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscripts.user.js
More file actions
2357 lines (2234 loc) · 105 KB
/
Copy pathscripts.user.js
File metadata and controls
2357 lines (2234 loc) · 105 KB
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
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// ==UserScript==
// @name AnimeBytes delicious user scripts
// @author aldy, potatoe, alpha, Megure
// @version 1.956
// @downloadURL https://aldy.nope.bz/scripts.user.js
// @updateURL https://aldy.nope.bz/scripts.user.js
// @description Variety of userscripts to fully utilise the site and stylesheet.
// @include *animebytes.tv/*
// @match https://*.animebytes.tv/*
// @icon http://animebytes.tv/favicon.ico
// ==/UserScript==
// Super duper important functions
// Do not delete or something might break and stuff!! :(
HTMLCollection.prototype.each = function (f) { for (var i=0, e=null; e=this[i]; i++) f.call(e, e); return this; };
HTMLElement.prototype.clone = function (o) { var n = this.cloneNode(); n.innerHTML = this.innerHTML; if (o!==undefined) for (var e in o) n[e] = o[e]; return n; };
// Thank firefox for this ugly shit. Holy shit firefox get your fucking shit together >:(
function forEach (arr, fun) { return HTMLCollection.prototype.each.call(arr, fun); }
function clone (ele, obj) { return HTMLElement.prototype.clone.call(ele, obj); }
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;
}
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]; };
}
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;
}
}
function createSettingsPage() {
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 addDropdown(title, description, varName, list, def) {
var newLi = document.createElement('li'), innerHTML = '';
this[varName] = initGM(varName, def, false);
innerHTML += "<span class='ue_left strong'>"+title+"</span>\n<span class='ue_right'><select name='"+varName+"' id='"+varName+"'>";
for (var i = 0; i < list.length; i++) {
var el = list[i], selected = '';
if (el[1] === GM_getValue(varName)) selected = " selected='selected'";
innerHTML += "<option value='"+el[1]+"'"+selected+">"+el[0]+"</option>";
}
innerHTML += "</select><label for='"+varName+"'>"+description+"</label></span>";
newLi.innerHTML = innerHTML;
newLi.addEventListener('change', function(e) { GM_setValue(varName, e.target.value); });
var poseList = document.getElementById('pose_list');
poseList.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("Delicious Better Quote", "Enable/Disable delicious better <span style='color: green; font-family: Courier New;'>>quoting</span>", 'deliciousquote');
addCheckbox("Delicious HYPER Quote", "Enable/Disable experimental HYPER quoting: select text and press CTRL+V to instant-quote. [EXPERIMENTAL]", 'delicioushyperquote');
addCheckbox("Delicious Title Flip", "Enable/Disable delicious flipping of Forum title tags.", 'delicioustitleflip');
addCheckbox("Disgusting Treats", "Hide/Unhide those hideous treats!", 'delicioustreats');
addCheckbox("Delicious Keyboard Shortcuts", "Enable/Disable delicious keyboard shortcuts for easier access to Bold/Italics/Underline/Spoiler/Hide and aligning.", 'deliciouskeyboard');
addCheckbox("Delicious Title Notifications", "Display number of notifications in title.", 'delicioustitlenotifications');
addCheckbox("Delicious Yen per X", "Shows how much yen you receive per X, and as upload equivalent.", 'deliciousyenperx');
addCheckbox("Delicious Ratio", "Shows ratio and raw ratio and how much uploade / download you need for certain ratio milestones.", 'deliciousratio');
addCheckbox("Delicious Freeleech Pool", "Shows current freeleech pool progress in the navbar and on user pages (updated once an hour or when freeleech pool site is visited).", 'deliciousfreeleechpool');
addDropdown("FL Pool Navbar Position", "Select position of freeleech pool progress in the navbar or disable it.", 'deliciousflpoolposition', [['Before user info', 'before #userinfo_minor'], ['After user info', 'after #userinfo_minor'], ['Before menu', 'before .main-menu.nobullet'], ['After menu', 'after .main-menu.nobullet'], ['Don\'t display', 'none']], 'after #userinfo_minor');
addCheckbox("Delicious Freeleech Pie Chart", "Adds a dropdown with pie-chart to the freeleech pool progress in the navbar.", 'delicousnavbarpiechart');
document.getElementById('pose_list').appendChild(document.createElement('hr'));
addCheckbox("Delicious Dynamic Stylesheets", "Define rules below for which hour to show what stylesheet.", 'deliciousdynamicstylesheets');
document.getElementById('pose_list').appendChild(document.createElement('hr'));
}
if (/\/user\.php\?.*action=edit/i.test(document.URL)) createSettingsPage();
// A couple GM variables that need initializing
var gm_deliciousquote = initGM('deliciousquote', 'true', false);
var gm_delicioushyperquote = initGM('delicioushyperquote', 'true', false);
var gm_delicioustitleflip = initGM('delicioustitleflip', 'true', false);
var gm_delicioustreats = initGM('delicioustreats', 'true', false);
var gm_deliciouskeyboard = initGM('deliciouskeyboard', 'true', false);
var gm_delicioustitlenotifications = initGM('delicioustitlenotifications', 'true', false);
var gm_deliciousyenperx = initGM('deliciousyenperx', 'true', false);
var gm_deliciousratio = initGM('deliciousratio', 'true', false);
var gm_deliciousfreeleechpool = initGM('deliciousfreeleechpool', 'true', false);
var gm_delicousnavbarpiechart = initGM('delicousnavbarpiechart', 'false', false);
var gm_deliciousdynamicstylesheets = initGM('deliciousdynamicstylesheets', 'false', false);
// Better quote by Potatoe, multi-quote by Megure
// Makes the quoting feature on AnimeBytes better by including links back to posts and the posted date.
// Depends on injectScript
if (GM_getValue('deliciousquote') === 'true') {
var quotes = document.querySelectorAll('a[onclick^="Quote"]');
for (var i = 0, len = quotes.length; i < len; i++) {
var elem = quotes[i],
args = elem.getAttribute('onClick').match(/Quote\s*\((?:\s*'([^']*)'\s*)?(?:,\s*'([^']*)'\s*)?(?:,\s*'([^']*)'\s*)?\)/i),
cb = document.createElement('input');
cb.type = 'checkbox';
cb.className = 'com-quote-multiquoteCB';
if (args[1] === undefined) args[1] = '';
if (args[2] === undefined) args[2] = '';
if (args[3] === undefined) args[3] = '';
cb.setAttribute('postid', args[1]);
cb.setAttribute('username', args[2]);
cb.setAttribute('surround', args[3]);
// Hide it if usercomment
if (/usercomment/i.test(elem.className))
cb.style.display = 'none';
elem.parentNode.insertBefore(cb, elem);
}
function Quote(postid, username, surround) {
var result = [],
results = 0,
multiQuote,
temp = document.querySelector('input.com-quote-multiquoteCB[postid="' + postid + '"]');
if (temp !== null)
temp.checked = true;
multiQuote = document.querySelectorAll('.com-quote-multiquoteCB:checked');
if (multiQuote.length > 0) {
for (var i = 0, len = multiQuote.length; i < len; i++) {
var elem = multiQuote[i],
postid = elem.getAttribute('postid'),
username = elem.getAttribute('username'),
surround = elem.getAttribute('surround');
retrievePost(postid, username, surround, i);
}
} else {
multiQuote = [document.createElement('input')];
retrievePost(postid, username, surround, 0);
}
function checkResult() {
if (multiQuote.length === ++results) {
insert_text(result.join('\n\n\n'), '');
for (var i = 0, len = multiQuote.length; i < len; i++)
multiQuote[i].checked = false;
}
}
function retrievePost(postid, username, surround, index) {
$j.ajax({
url: window.location.pathname,
data: {
action: 'get_post',
post: postid
},
success: function (response) {
function replaceImg(text){if(text.match(/^([^]*)(\[img\][^\[]+\[\/img\])([^]*)$/mi)!=null){return text.replace(/^([^]*)(\[img\][^\[]+\[\/img\])([^]*)$/mi,function(full,$1,$2,$3){var tmp="BQTMPBQ"+new Date().getTime()+"BQTMPBQ",ssm=$1.match(/\[hide(=[^\]]*)?\]/mgi),sem=$1.match(/\[\/hide\]/mgi),esm=$3.match(/\[hide(=[^\]]*)?\]/mgi),eem=$3.match(/\[\/hide\]/mgi),ssm=(ssm!=null)?ssm.length:0,sem=(sem!=null)?sem.length:0,esm=(esm!=null)?esm.length:0,eem=(eem!=null)?eem.length:0,hsm=ssm-sem,hem=esm-eem,tmptxt=replaceImg($1+tmp+$3);$1=tmptxt.substring(0,tmptxt.search(tmp));$3=tmptxt.substring(tmptxt.search(tmp)+tmp.length,tmptxt.length);if(hsm>=hem&&hsm>0)return $1+$2+$3;return $1+'[hide=Image]'+$2+'[/hide]'+$3})}return text}
function replaceYouTube(text){if(text.match(/^([^]*)(\[youtube\][^\[]+\[\/youtube\])([^]*)$/mi)!=null){return text.replace(/^([^]*)(\[youtube\][^\[]+\[\/youtube\])([^]*)$/mi,function(full,$1,$2,$3){var tmp="BQTMPBQ"+new Date().getTime()+"BQTMPBQ",ssm=$1.match(/\[hide(=[^\]]*)?\]/mgi),sem=$1.match(/\[\/hide\]/mgi),esm=$3.match(/\[hide(=[^\]]*)?\]/mgi),eem=$3.match(/\[\/hide\]/mgi),ssm=(ssm!=null)?ssm.length:0,sem=(sem!=null)?sem.length:0,esm=(esm!=null)?esm.length:0,eem=(eem!=null)?eem.length:0,hsm=ssm-sem,hem=esm-eem,tmptxt=replaceYouTube($1+tmp+$3);$1=tmptxt.substring(0,tmptxt.search(tmp));$3=tmptxt.substring(tmptxt.search(tmp)+tmp.length,tmptxt.length);if(hsm>=hem&&hsm>0)return $1+$2+$3;return $1+'[hide=YouTube Video]'+$2+'[/hide]'+$3})}return text}
response = replaceYouTube(replaceImg(response));
if (window.location.pathname === '/forums.php') var type = '#';
if (window.location.pathname === '/user.php') var type = '*';
if (window.location.pathname === '/torrents.php') var type = '-1';
if (window.location.pathname === '/torrents2.php') var type = '-2';
if (typeof type === 'undefined')
var quoteText = '[quote=' + username + ']' + response + '[/quote]';
else
var quoteText = '[quote=' + type + postid + ']' + response + '[/quote]';
if (surround && surround.length > 0) quoteText = '[' + surround + ']' + quoteText + '[/' + surround + ']';
result[index] = quoteText;
checkResult();
},
error: function () {
result[index] = 'error retrieving post #' + postid;
checkResult();
},
dataType: 'html'
});
}
}
injectScript(Quote, 'BetterQuote');
}
// HYPER QUOTE by Megure
// Select text and press CTRL+V to quote
if (GM_getValue('delicioushyperquote') === 'true' && document.getElementById('quickpost') !== null) {
function formattedUTCString(date, timezone) {
var creation = new Date(date);
if (isNaN(creation.getTime()))
return date;
else {
creation = creation.toUTCString().split(' ');
return creation[1] + ' ' + creation[2] + ' ' + creation[3] + ', ' + creation[4].substring(0, 5) + (timezone !== false ? ' ' + creation[5] : '');
}
}
function QUOTEALL() {
var sel = window.getSelection();
for(var i = 0; i < sel.rangeCount; i++)
QUOTEMANY(sel.getRangeAt(i));
}
function QUOTEMANY(range) {
function removeChildren(node, prev) {
if (node === null || node.parentNode === null) return;
if (prev === true)
while (node.parentNode.firstChild !== node)
node.parentNode.removeChild(node.parentNode.firstChild);
else
while (node.parentNode.lastChild !== node)
node.parentNode.removeChild(node.parentNode.lastChild);
removeChildren(node.parentNode, prev);
}
function inArray(arr, elem) {
for (var i = 0; i < arr.length; i++) {
if (arr[i] === elem)
return i;
}
return -1;
}
if (range.collapsed === true) return;
var html1, html2, copy, res, start = [], end = [], startNode, endNode;
html1 = range.startContainer;
while (html1.parentNode !== null) {
start.push(inArray(html1.parentNode.childNodes, html1));
html1 = html1.parentNode;
}
html2 = range.endContainer;
while (html2.parentNode !== null) {
end.push(inArray(html2.parentNode.childNodes, html2));
html2 = html2.parentNode;
}
if (html1 !== html2 || html1 === null) return;
copy = html1.cloneNode(true);
startNode = copy;
for (var i = start.length - 1; i >= 0; i--) {
if (start[i] === -1) return;
startNode = startNode.childNodes[start[i]];
}
endNode = copy;
for (var i = end.length - 1; i >= 0; i--) {
if (end[i] === -1) return;
endNode = endNode.childNodes[end[i]];
}
if (endNode.nodeType === 3)
endNode.data = endNode.data.substr(0, range.endOffset);
else if (endNode.nodeType === 1)
for (var i = endNode.childNodes.length; i > range.endOffset; i--)
endNode.removeChild(endNode.lastChild);
if (range.startOffset > 0) {
if (startNode.nodeType === 3)
startNode.data = startNode.data.substr(range.startOffset);
else if (startNode.nodeType === 1)
for (var i = 0; i < range.startOffset; i++)
startNode.removeChild(startNode.firstChild);
}
removeChildren(startNode, true);
removeChildren(endNode, false);
var posts = copy.querySelectorAll('div[id^="post"],div[id^="msg"]');
for (var i = 0; i < posts.length; i++)
QUOTEONE(posts[i]);
}
function QUOTEONE(post) {
function HTMLtoBB(str) {
// Order is somewhat relevant
var ret = str.replace(/<br.*?>/ig, '').
replace(/<strong><a.*?>.*?<\/a><\/strong> <a.*?href="(.*?)#(?:msg|post)(.*?)".*?>wrote(?: on )?(.*?)<\/a>:?\s*<blockquote class="blockquote">([\s\S]*?)<\/blockquote>/ig, function(html, href, id, dateString, quote) {
var type = '';
if (/\/forums\.php/i.test(href)) type = '#';
if (/\/user\.php/i.test(href)) type = '*';
if (/\/torrents\.php/i.test(href)) type = '-1';
if (/\/torrents2\.php/i.test(href)) type = '-2';
if (type !== '')
return '[quote=' + type + id + ']' + quote + '[/quote]';
else
return html.replace(dateString, formattedUTCString(dateString));
}).
replace(/<strong>Added on (.*?):?<\/strong>/ig, function(html,dateString) {
return html.replace(dateString, formattedUTCString(dateString));
}).
replace(/<span class="smiley-.+?" title="(.+?)"><\/span>/ig, function(html, smiley) {
var smileyNode = document.querySelector('img[alt="' + smiley + '"]');
if (smileyNode === null)
smileyNode = document.querySelector('img[src$="' + smiley + '.png"]');
if (smileyNode === null)
smileyNode = document.querySelector('img[src$="' + smiley.replace(/-/g, '_') + '.png"]');
if (smileyNode === null)
smileyNode = document.querySelector('img[src$="' + smiley.replace(/-/g, '_').toLowerCase() + '.png"]');
if (smileyNode === null)
smileyNode = document.querySelector('img[src$="' + smiley.replace(/face/g, '~_~') + '.png"]');
if (smileyNode !== null && smileyNode.parentNode !== null) {
smileyNode = smileyNode.parentNode.getAttribute('onclick').match(/'(.+?)'/i);
if (smileyNode !== null)
return smileyNode[1];
}
return ':' + smiley + ':';
}).
replace(/<iframe.*?src="([^?"]*).*?".*?><\/iframe>/ig, '[youtube]$1[/youtube]').
replace(/<([^\s>\/]+)[^>]*>\s*<\/([^>]+)>/ig, function(html, match1, match2) {
if (match1 === match2)
return '';
return html;
}).
replace(/<ul><li>(.+?)<\/li><\/ul>/ig, '[*]$1').
replace(/<a.*?href="torrents\.php\?.*?torrentid=([0-9]*?)".*?>([\s\S]*?)<\/a>/ig, '[torrent=$1]$2[/torrent]').
replace(/<a.*?href="(.*?)".*?>([\s\S]*?)<\/a>/ig, function(html, match1, match2) {
if (match1.indexOf('://') === -1 && match1.length > 0 && match1[0] !== '/')
return '[url=/' + match1 + ']' + match2 + '[/url]'
else
return '[url=' + match1 + ']' + match2 + '[/url]'
}).
replace(/<strong>([\s\S]*?)<\/strong>/ig, '[b]$1[/b]').
replace(/<em>([\s\S]*?)<\/em>/ig, '[i]$1[/i]').
replace(/<u>([\s\S]*?)<\/u>/ig, '[u]$1[/u]').
replace(/<s>([\s\S]*?)<\/s>/ig, '[s]$1[/s]').
replace(/<div style="text-align: center;">([\s\S]*?)<\/div>/ig, '[align=center]$1[/align]').
replace(/<div style="text-align: left;">([\s\S]*?)<\/div>/ig, '[align=left]$1[/align]').
replace(/<div style="text-align: right;">([\s\S]*?)<\/div>/ig, '[align=right]$1[/align]').
replace(/<span style="color:\s*(.*?);?">([\s\S]*?)<\/span>/ig, '[color=$1]$2[/color]').
replace(/<span class="size(.*?)">([\s\S]*?)<\/span>/ig, '[size=$1]$2[/size]').
replace(/<blockquote class="blockquote">([\s\S]*?)<\/blockquote>/ig, '[quote]$1[/quote]').
replace(/<div.*?class=".*?spoilerContainer.*?hideContainer.*?".*?><input.*?value="(?:Show\s*|Hide\s*)(.*?)".*?><div.*?class=".*?spoiler.*?".*?>([\s\S]*?)<\/div><\/div>/ig, function(html, button, content) {
if (button !== '')
return '[hide=' + button + ']' + content + '[/hide]';
else
return '[hide]' + content + '[/hide]';
}).
replace(/<div.*?class=".*?spoilerContainer.*?".*?><input.*?><div.*?class=".*?spoiler.*?".*?>([\s\S]*?)<\/div><\/div>/ig, '[spoiler]$1[/spoiler]').
replace(/<img.*?src="(.*?)".*?>/ig, '[img]$1[/img]').
replace(/<span class="last-edited">[\s\S]*$/ig, '');
if (ret !== str) return HTMLtoBB(ret);
else {
// Decode HTML
var tempDiv = document.createElement('div');
tempDiv.innerHTML = ret;
return tempDiv.textContent.trim();
}
}
var res = HTMLtoBB(post.querySelector('div.post,div.body').innerHTML),
author, creation, postid, type = '';
if (res === '') return;
postid = post.id.match(/(?:msg|post)(\d+)/i);
if (postid === null)
return;
if (window.location.pathname === '/forums.php') type = '#';
if (window.location.pathname === '/user.php') type = '*';
if (window.location.pathname === '/torrents.php') type = '-1';
if (window.location.pathname === '/torrents2.php') type = '-2';
if (type !== '')
res = '[quote=' + type + postid[1] + ']' + res + '[/quote]';
else {
author = post.className.match(/user_(\d+)/i);
if (author !== null)
author = '[b][user]' + author[1] + '[/user][/b] ';
else {
author = document.querySelector('#' + postid[0] + ' a[href^="/user.php?"]');
if (author !== null) {
author = author.href.match(/id=(\d+)/i);
author = (author !== null ? '[b][user]' + author[1] + '[/user][/b] ' : '');
}
else
author = '';
}
creation = document.querySelector('div#' + postid[0] + ' > div > div > p.posted_info > span');
if (creation === null)
creation = document.querySelector('div#' + postid[0] + ' > div > span > span.usercomment_posttime');
if (creation !== null)
creation = ' on ' + formattedUTCString(creation.title.replace(/-/g,'/'));
else
creation = '';
res = author + '[url=' + window.location.pathname + window.location.search + '#' + postid[0] + ']wrote' + creation + '[/url]:\n[quote]' + res + '[/quote]\n\n';
}
document.getElementById('quickpost').value += res;
sel = document.getElementById('quickpost');
if (sel !== null)
sel.scrollIntoView();
}
document.addEventListener('keydown', function (e) {
if((e.ctrlKey || e.metaKey) && e.keyCode === 'V'.charCodeAt(0))
QUOTEALL();
});
}
// Forums title inverter by Potatoe
// Inverts the forums titles.
if (GM_getValue('delicioustitleflip') === 'true' && document.title.indexOf(' > ') > -1) document.title = document.title.split(" :: ")[0].split(" > ").reverse().join(" < ") + " :: AnimeBytes";
// Hide treats by Alpha
// Hide treats on profile.
if (GM_getValue('delicioustreats') === 'true') {
var treatsnode = document.evaluate('//*[@id="user_leftcol"]/div[@class="box" and div[@class="head" and .="Treats"]]', document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
if (treatsnode) treatsnode.style.display = "none";
}
// Keyboard shortcuts by Alpha, mod by Megure
// Enables keyboard shortcuts for forum (new post and edit) and PM
if (GM_getValue('deliciouskeyboard') === 'true' && document.querySelector('textarea') !== null) {
function custom_insert_text(open, close) {
var elem = document.activeElement;
if (elem.selectionStart || elem.selectionStart == '0') {
var startPos = elem.selectionStart;
var endPos = elem.selectionEnd;
elem.value = elem.value.substring(0, startPos) + open + elem.value.substring(startPos, endPos) + close + elem.value.substring(endPos, elem.value.length);
elem.selectionStart = elem.selectionEnd = endPos + open.length + close.length;
elem.focus();
if (close.length == 0)
elem.setSelectionRange(startPos + open.length, startPos + open.length);
else
elem.setSelectionRange(startPos + open.length, endPos + open.length);
} else if (document.selection && document.selection.createRange) {
elem.focus();
sel = document.selection.createRange();
sel.text = open + sel.text + close;
if (close.length != 0) {
sel.move("character", -close.length);
sel.select();
}
elem.focus();
} else {
elem.value += open;
elem.focus();
elem.value += close;
}
}
var ctrlorcmd = (navigator.appVersion.indexOf('Mac') != -1) ? '⌘' : 'CTRL';
document.addEventListener('keydown', function(e) {
function insert(key, ctrl, alt, shift, open, close, query) {
if ((ctrl !== true || e.ctrlKey || e.metaKey) && (alt !== true || e.altKey) && (shift !== true || e.shiftKey) && e.keyCode === key.charCodeAt(0) && document.activeElement.tagName.toLowerCase() === 'textarea') {
e.preventDefault();
custom_insert_text(open, close);
return false;
}
if (query !== undefined) {
var imgs = document.querySelectorAll(query);
for (var i = 0; i < imgs.length; i++) {
var img = imgs[i];
img.title += ' (';
if (ctrl === true) img.title += ctrlorcmd + ' + ';
if (alt === true) img.title += 'ALT + ';
if (shift === true) img.title += 'SHIFT + ';
img.title += key + ')';
}
}
}
/**
* All keyboard shortcuts based on MS Word
**/
// Bold
insert('B', true, false, false, '[b]', '[/b]', '#bbcode img[title="Bold"]');
// Italics
insert('I', true, false, false, '[i]', '[/i]', '#bbcode img[title="Italics"]');
// Underline
insert('U', true, false, false, '[u]', '[/u]', '#bbcode img[title="Underline"]');
// Align right
insert('R', true, false, false, '[align=right]', '[/align]');
// Align left
insert('L', true, false, false, '[align=left]', '[/align]');
// Align center
insert('E', true, false, false, '[align=center]', '[/align]');
// Spoiler
insert('S', true, false, false, '[spoiler]', '[/spoiler]', '#bbcode img[title="Spoilers"]');
// Hide
insert('H', true, false, false, '[hide]', '[/hide]', '#bbcode img[title="Hide"]');
// YouTube
insert('Y', true, true, false, '[youtube]', '[/youtube]', '#bbcode img[alt="YouTube"]');
// Image
insert('G', true, false, false, '[img]', '[/img]', '#bbcode img[title="Image"]');
});
}
// Title Notifications by Megure
// Will prepend the number of notifications to the title
if(GM_getValue('delicioustitlenotifications') === 'true') {
var new_count = 0, _i, cnt, notifications = document.querySelectorAll('#alerts .new_count'), _len = notifications.length;
for(_i = 0; _i < _len; _i++) {
cnt = parseInt(notifications[_i].textContent, 10);
if (!isNaN(cnt))
new_count += cnt;
}
if (new_count > 0)
document.title = '(' + new_count + ') ' + document.title;
}
// Freeleech Pool Status by Megure, inspired by Lemma, Alpha, NSC
// Shows current freeleech pool status in navbar with a pie-chart
// Updates only once every hour or when pool site is visited, showing a pie-chart on pool site
if (GM_getValue('deliciousfreeleechpool', 'true') === 'true') {
function niceNumber(num) {
var res = '';
while (num >= 1000) {
res = ',' + ('00' + (num % 1000)).slice(-3) + res;
num = Math.floor(num / 1000);
}
return num + res;
}
var locked = false;
function getFLInfo() {
function parseFLInfo(elem) {
var boxes = elem.querySelectorAll('#content .box.pad');
if (boxes.length < 3) return;
// The first box holds the current amount, the max amount and the user's individual all-time contribution
var match = boxes[0].textContent.match(/have ([0-9,]+) \/ ([0-9,]+) yen/i),
max = parseInt(GM_getValue('FLPoolMax', '50000000'), 10),
current = parseInt(GM_getValue('FLPoolCurrent', '0'), 10);
if (match == null) {
match = boxes[0].textContent.match(/Our donation box is already full/i);
if (match != null) current = max;
}
else {
current = parseInt(match[1].replace(/,/g, ''), 10);
max = parseInt(match[2].replace(/,/g, ''), 10);
}
if (match != null) {
GM_setValue('FLPoolCurrent', current);
GM_setValue('FLPoolMax', max);
}
// Check first box for user's individual all-time contribution
match = boxes[0].textContent.match(/you've donated ([0-9,]+) yen/i);
if (match != null)
GM_setValue('FLPoolContribution', parseInt(match[1].replace(/,/g, ''), 10));
// The third box holds the top 10 donators for the current box
var box = boxes[2],
firstP = box.querySelector('p'),
tr = box.querySelector('table').querySelectorAll('tbody > tr');
var titles = [], hrefs = [], amounts = [], colors = [], sum = 0;
for (var i = 0; i < tr.length; i++) {
var el = tr[i],
td = el.querySelectorAll('td');
titles[i] = td[0].textContent;
hrefs[i] = td[0].querySelector('a').href;
amounts[i] = parseInt(td[1].textContent.replace(/,/g, ''), 10);
colors[i] = 'red';
sum += amounts[i];
}
// Also add others and missing to the arrays
titles[tr.length] = 'Other';
hrefs[tr.length] = 'https://animebytes.tv/konbini.php?action=pool';
amounts[tr.length] = current - sum;
colors[tr.length] = 'lightgrey';
titles[tr.length + 1] = 'Missing';
hrefs[tr.length + 1] = 'https://animebytes.tv/konbini.php?action=pool';
amounts[tr.length + 1] = max - current;
colors[tr.length + 1] = 'black';
GM_setValue('FLPoolLastUpdate', Date.now());
GM_setValue('FLPoolTitles', JSON.stringify(titles));
GM_setValue('FLPoolHrefs', JSON.stringify(hrefs));
GM_setValue('FLPoolAmounts', JSON.stringify(amounts));
GM_setValue('FLPoolColors', JSON.stringify(colors));
}
// Either parse document or retrieve freeleech pool site 60*60*1000 ms after last retrieval
if (/konbini\.php\?action=pool$/i.test(document.URL))
parseFLInfo(document);
else if (Date.now() - parseInt(GM_getValue('FLPoolLastUpdate', '0'), 10) > 3600000 && locked === false) {
locked = true;
var xhr = new XMLHttpRequest(), parser = new DOMParser();
xhr.open('GET', "https://animebytes.tv/konbini.php?action=pool", true);
xhr.send();
xhr.onreadystatechange = function() {
if (xhr.readyState === 4) {
parseFLInfo(parser.parseFromString(xhr.responseText, 'text/html'));
updatePieChart();
locked = false;
}
};
}
}
function getPieChart() {
function circlePart(diff, title, href, color) {
if (diff == 0) return '';
var x = Math.sin(phi), y = Math.cos(phi);
phi -= 2 * Math.PI * diff / max;
var v = Math.sin(phi), w = Math.cos(phi);
var z = 0;
if (2 * diff > max)
z = 1; // use long arc
var perc = (100 * diff / max).toFixed(1) + '%\n' + niceNumber(diff) + ' ¥';
return '<a xlink:href="' + href + '" xlink:title="' + title + '\n' + perc + '"><path title="' + title + '\n' + perc + '" stroke-width="0.01" stroke="grey" fill="' + color + '" d="M0,0 L' + v + ',' + w + ' A1,1 0 ' + z + ',0 ' + x + ',' + y + 'z">\n' +
'<animate begin="mouseover" attributeName="d" to="M0,0 L' + 1.1 * v + ',' + 1.1 * w + ' A1.1,1.1 0 ' + z + ',0 ' + 1.1 * x + ',' + 1.1 * y + 'z" dur="0.3s" fill="freeze" />\n' +
'<animate begin="mouseout" attributeName="d" to="M0,0 L' + v + ',' + w + ' A1,1 0 ' + z + ',0 ' + x + ',' + y + 'z" dur="0.3s" fill="freeze" />\n' +
'</path></a>\n\n';
}
var str = '<svg version="1.1" xmlns="http://www.w3.org/2000/svg" viewBox="-1.11 -1.11 2.22 2.22" height="200px" width="100%">' +
'<title>Most Donated To This Box Pie-Chart</title>';
try {
var phi = Math.PI, max = parseInt(GM_getValue('FLPoolMax', '50000000'), 10),
titles = JSON.parse(GM_getValue('FLPoolTitles', '[]')),
hrefs = JSON.parse(GM_getValue('FLPoolHrefs', '[]')),
amounts = JSON.parse(GM_getValue('FLPoolAmounts', '[]')),
colors = JSON.parse(GM_getValue('FLPoolColors', '[]'));
for (var i = 0; i < titles.length; i++) {
str += circlePart(amounts[i], titles[i], hrefs[i], colors[i]);
}
} catch (e) {}
return str + '</svg>';
}
function updatePieChart() {
var pieChart = getPieChart();
p.innerHTML = pieChart;
p3.innerHTML = pieChart;
if (GM_getValue('delicousnavbarpiechart', 'false') === 'true') {
li.innerHTML = pieChart;
}
p2.innerHTML = 'There currently are ' + niceNumber(parseInt(GM_getValue('FLPoolCurrent', '0'), 10)) + ' / ' + niceNumber(parseInt(GM_getValue('FLPoolMax', '50000000'), 10)) + ' yen in the donation box.<br/>';
p2.innerHTML += '(That means it is ' + niceNumber(parseInt(GM_getValue('FLPoolMax', '50000000'), 10) - parseInt(GM_getValue('FLPoolCurrent', '0'), 10)) + ' yen away from getting sitewide freeleech!)<br/>';
p2.innerHTML += 'In total, you\'ve donated ' + niceNumber(parseInt(GM_getValue('FLPoolContribution', '0'), 10)) + ' yen to the freeleech pool.<br/>';
p2.innerHTML += 'Last Update: ' + Math.round((Date.now() - parseInt(GM_getValue('FLPoolLastUpdate', Date.now()), 10)) / 60000) + ' minutes ago.';
a.textContent = 'FL: ' + (100 * parseInt(GM_getValue('FLPoolCurrent', '0'), 10) / parseInt(GM_getValue('FLPoolMax', '50000000'), 10)).toFixed(1) + '%';
nav.replaceChild(a, nav.firstChild);
}
var pos = GM_getValue('deliciousflpoolposition', 'after #userinfo_minor');
if (pos !== 'none' || /user\.php\?id=/i.test(document.URL) || /konbini\.php\?action=pool/i.test(document.URL)) {
var p = document.createElement('p'),
p2 = document.createElement('center'),
p3 = document.createElement('p'),
nav = document.createElement('li'),
a = document.createElement('a'),
ul = document.createElement('ul'),
li = document.createElement('li');
a.href = '/konbini.php?action=pool';
nav.appendChild(a);
if (GM_getValue('delicousnavbarpiechart', 'false') === 'true') {
nav.innerHTML += '<span class="dropit hover clickmenu"><span class="stext">▼</span></span>';
ul.appendChild(li);
ul.className = 'subnav nobullet';
nav.appendChild(ul);
nav.className = 'navmenu';
}
if (pos !== 'none') {
pos = pos.split(' ');
var parent = document.querySelector(pos[1]);
if (parent !== null) {
getFLInfo();
if (pos[0] === 'after')
parent.appendChild(nav);
if (pos[0] === 'before')
parent.insertBefore(nav, parent.firstChild);
}
}
updatePieChart();
if (/user\.php\?id=/i.test(document.URL) && GM_getValue('deliciousyenperx', 'true') === 'true') {
// Only do so on the users' profile pages if Yen per X is activated and Yen per day is present in userstats
var userstats = document.querySelector('#user_rightcol > .box');
if (userstats != null) {
var tw = document.createTreeWalker(userstats, NodeFilter.SHOW_TEXT, { acceptNode: function(node) { return /Yen per day/i.test(node.data); } });
if (tw.nextNode() != null) {
getFLInfo();
var cNode = document.querySelector('.userstatsleft');
var hr = document.createElement('hr');
hr.style.clear = 'both';
cNode.insertBefore(hr, cNode.lastElementChild);
cNode.insertBefore(p2, cNode.lastElementChild);
cNode.insertBefore(p3, cNode.lastElementChild);
}
}
}
if (/konbini\.php\?action=pool/i.test(document.URL)) {
var tw = document.createTreeWalker(document.getElementById('content'), NodeFilter.SHOW_TEXT, { acceptNode: function(node) { return /^\s*Most Donated to This Box\s*$/i.test(node.data); } });
if (tw.nextNode() !== null) {
tw.currentNode.parentNode.insertBefore(p, tw.currentNode.nextSibling);
}
}
}
}
// Yen per X and ratio milestones, by Megure, Lemma, NSC, et al.
if(/user\.php\?id=/i.test(document.URL)) {
function compoundInterest(years) {
return (Math.pow(2, years) - 1) / Math.log(2);
}
function formatInteger(num) {
var res = '';
while (num >= 1000) {
res = ',' + ('00' + (num % 1000)).slice(-3) + res;
num = Math.floor(num / 1000);
}
return num + res;
}
function bytecount(num, unit) {
switch (unit) {
case 'B':
return num * Math.pow(1024, 0);
case 'KB':
return num * Math.pow(1024, 1);
case 'MB':
return num * Math.pow(1024, 2);
case 'GB':
return num * Math.pow(1024, 3);
case 'TB':
return num * Math.pow(1024, 4);
case 'PB':
return num * Math.pow(1024, 5);
case 'EB':
return num * Math.pow(1024, 6);
}
}
function humancount(num) {
if (num == 0) return '0 B';
var i = Math.floor(Math.log(Math.abs(num)) / Math.log(1024));
num = (num / Math.pow(1024, i)).toFixed(2);
switch (i) {
case 0:
return num + ' B';
case 1:
return num + ' KB';
case 2:
return num + ' MB';
case 3:
return num + ' GB';
case 4:
return num + ' TB';
case 5:
return num + ' PB';
case 6:
return num + ' EB';
default:
return num + ' * 1024^' + i + ' B';
}
}
function addDefinitionAfter(after, definition, value, cclass) {
dt = document.createElement('dt');
dt.appendChild(document.createTextNode(definition));
dd = document.createElement('dd');
if (cclass !== undefined) dd.className += cclass;
dd.appendChild(document.createTextNode(value));
after.parentNode.insertBefore(dd, after.nextElementSibling.nextSibling);
after.parentNode.insertBefore(dt, after.nextElementSibling.nextSibling);
return dt;
}
function addDefinitionBefore(before, definition, value, cclass) {
dt = document.createElement('dt');
dt.appendChild(document.createTextNode(definition));
dd = document.createElement('dd');
if (cclass !== undefined) dd.className += cclass;
dd.appendChild(document.createTextNode(value));
before.parentNode.insertBefore(dt, before);
before.parentNode.insertBefore(dd, before);
return dt;
}
function addRawStats() {
var tw, regExp = /([\d,.]+)\s*([A-Z]+)\s*\(([^)]*)\)/i;
// Find text with raw stats
tw = document.createTreeWalker(document, NodeFilter.SHOW_TEXT, { acceptNode: function(node) { return /^Raw Uploaded:/i.test(node.data); } });
if (tw.nextNode() == null) return;
var rawUpMatch = tw.currentNode.data.match(regExp);
tw = document.createTreeWalker(tw.currentNode.parentNode.parentNode, NodeFilter.SHOW_TEXT, { acceptNode: function(node) { return /^Raw Downloaded:/i.test(node.data); } });
if (tw.nextNode() == null) return;
var rawDownMatch = tw.currentNode.data.match(regExp);
tw = document.createTreeWalker(document.getElementById('content'), NodeFilter.SHOW_TEXT, { acceptNode: function(node) { return /^\s*Ratio/i.test(node.data); } });
if (tw.nextNode() == null) return;
var ratioNode = tw.currentNode.parentNode;
tw = document.createTreeWalker(document.getElementById('content'), NodeFilter.SHOW_TEXT, { acceptNode: function(node) { return /^\s*Uploaded/i.test(node.data); } });
if (tw.nextNode() == null) return;
var ulNode = tw.currentNode.parentNode;
tw = document.createTreeWalker(document.getElementById('content'), NodeFilter.SHOW_TEXT, { acceptNode: function(node) { return /^\s*Downloaded/i.test(node.data); } });
if (tw.nextNode() == null) return;
var dlNode = tw.currentNode.parentNode;
var ul = ulNode.nextElementSibling.textContent.match(regExp);
var dl = dlNode.nextElementSibling.textContent.match(regExp);
var uploaded = bytecount(parseFloat(ul[1].replace(/,/g, '')), ul[2].toUpperCase());
var downloaded = bytecount(parseFloat(dl[1].replace(/,/g, '')), dl[2].toUpperCase());
var rawuploaded = bytecount(parseFloat(rawUpMatch[1].replace(/,/g, '')), rawUpMatch[2].toUpperCase());
var rawdownloaded = bytecount(parseFloat(rawDownMatch[1].replace(/,/g, '')), rawDownMatch[2].toUpperCase());
var rawRatio = Infinity;
if (bytecount(parseFloat(rawDownMatch[1].replace(/,/g, '')), rawDownMatch[2].toUpperCase()) > 0)
rawRatio = (bytecount(parseFloat(rawUpMatch[1].replace(/,/g, '')), rawUpMatch[2].toUpperCase()) / bytecount(parseFloat(rawDownMatch[1].replace(/,/g, '')), rawDownMatch[2].toUpperCase())).toFixed(2);
// Color ratio
var color = 'r99';
if (rawRatio < 1)
color = 'r' + ('0' + Math.ceil(10 * rawRatio)).slice(-2);
else if (rawRatio < 5)
color = 'r20';
else if (rawRatio < 99)
color = 'r50';
// Add to user stats after ratio
var hr = document.createElement('hr');
hr.style.clear = 'both';
ratioNode.parentNode.insertBefore(hr, ratioNode.nextElementSibling.nextSibling);
var rawRatioNode = addDefinitionAfter(ratioNode, 'Raw Ratio:', rawRatio, color);
addDefinitionAfter(ratioNode, 'Raw Downloaded:', rawDownMatch[0]);
addDefinitionAfter(ratioNode, 'Raw Uploaded:', rawUpMatch[0]);
ratioNode.nextElementSibling.title = 'Ratio\t Buffer';
rawRatioNode.nextElementSibling.title = 'Raw ratio\t Raw Buffer';
function printBuffer(u, d, r) {
if (u / r - d >= 0)
return '\n' + r.toFixed(1) + '\t\t' + (" " + humancount(u / r - d)).slice(-10) + '\tcan be downloaded'
else
return '\n' + r.toFixed(1) + '\t\t' + (" " + humancount(d * r - u)).slice(-10) + '\tmust be uploaded'
}
for (var i = 0; i < 10; i++) {
var myRatio = [0.2, 0.5, 0.7, 0.8, 0.9, 1.0, 1.5, 2.0, 5.0, 10.0][i];
ratioNode.nextElementSibling.title += printBuffer(uploaded, downloaded, myRatio);
rawRatioNode.nextElementSibling.title += printBuffer(rawuploaded, rawdownloaded, myRatio);
}
}
function addYenPerStats() {
var dpy = 365.256363; // days per year
var tw = document.createTreeWalker(document.getElementById('content'), NodeFilter.SHOW_TEXT, { acceptNode: function(node) { return /Yen per day/i.test(node.data); } });
if (tw.nextNode() == null) return;
var ypdNode = tw.currentNode.parentNode;
var ypy = parseInt(ypdNode.nextElementSibling.textContent, 10) * dpy; // Yen per year
addDefinitionAfter(ypdNode, 'Yen per year:', formatInteger(Math.round(ypy * compoundInterest(1))));
addDefinitionAfter(ypdNode, 'Yen per month:', formatInteger(Math.round(ypy * compoundInterest(1 / 12))));
addDefinitionAfter(ypdNode, 'Yen per week:', formatInteger(Math.round(ypy * compoundInterest(7 / dpy))));
// 1 Yen = 1 MB = 1024^2 B * yen per year * interest for 1 s
var hr = document.createElement('hr');
hr.style.clear = 'both';
ypdNode.parentNode.insertBefore(hr, ypdNode);
addDefinitionBefore(ypdNode, 'Yen as upload:', humancount(Math.pow(1024, 2) * ypy * compoundInterest(1 / dpy / 24 / 60 / 60)) + '/s');
addDefinitionBefore(ypdNode, 'Yen per hour:', (ypy * compoundInterest(1 / dpy / 24)).toFixed(1));
}
if (GM_getValue('deliciousratio', 'true') === 'true')
addRawStats();
if (GM_getValue('deliciousyenperx', 'true') === 'true')
addYenPerStats();
}
// Dynamic stylesheets by Megure, requires jQuery because I'm lazy
(function() {
function updateSettings() {
var rules = document.querySelectorAll('li.deliciousdynamicstylesheetsrule');
var result = [];
for (var i = 0; i < rules.length; i++) {
var rule = rules[i];
var hour = rule.children[0].value;
var stylesheet = rule.children[1].value;
if (hour !== '' && stylesheet !== '')
result.push([parseInt(hour, 10), stylesheet]);
}
result.sort(function(a, b) { return a[0] - b[0]; });
GM_setValue('deliciousdynamicstylesheetsrules', JSON.stringify(result));
}
function addRule(hour, stylesheet) {
var newLi = document.createElement('li');
newLi.className = 'deliciousdynamicstylesheetsrule';
var hour_input = document.createElement('input');
hour_input.type = 'number';
hour_input.min = '0';
hour_input.max = '23';
hour_input.step = '1';
hour_input.placeholder = '0-23';
hour_input.style.width = '10%';
hour_input.addEventListener('keyup', updateSettings);
if (typeof hour === 'number')
hour_input.value = hour;
var stylesheet_input = document.createElement('input');
stylesheet_input.type = 'text';
stylesheet_input.placeholder = 'Either a name of an existing stylesheet like Milkyway (case-sensitive), or an external URL like https://aldy.nope.bz/toblerone.css';
stylesheet_input.style.width = '75%';
stylesheet_input.addEventListener('keyup', updateSettings);
if (typeof stylesheet === 'string')
stylesheet_input.value = stylesheet;
var delete_button = document.createElement('button');
delete_button.textContent = 'Delete rule';
delete_button.addEventListener('click', function(e) {
e.preventDefault();
newLi.parentNode.removeChild(newLi);
updateSettings();
});
newLi.appendChild(hour_input);
newLi.appendChild(stylesheet_input);
newLi.appendChild(delete_button);
var rules = document.querySelectorAll('li.deliciousdynamicstylesheetsrule');
if (rules.length > 0) {
var lastRule = rules[rules.length - 1];
lastRule.parentNode.insertBefore(newLi, lastRule.nextSibling);
}
else {
var settings = document.getElementById('deliciousdynamicstylesheets');
settings.parentNode.parentNode.parentNode.insertBefore(newLi, settings.parentNode.parentNode.nextSibling);
}
}
function setStylesheet(stylesheet) {
var settings_xhr = new XMLHttpRequest(), settings_dom_parser = new DOMParser();
settings_xhr.open('GET', "https://animebytes.tv/user.php?action=edit", true);
settings_xhr.send();
settings_xhr.onreadystatechange = function() {
if (settings_xhr.readyState === 4) {
var settings_document = settings_dom_parser.parseFromString(settings_xhr.responseText, 'text/html');
var form = settings_document.getElementById('userform');
if (form !== null) {
var styleurl = form.querySelector('input#styleurl');
var stylesheet_select = form.querySelector('select#stylesheet');
if (styleurl === null || stylesheet_select === null) {
console.log("Could not find style url or stylesheet input on settings page.");
return;
}
var stylesheet_options = settings_document.evaluate('//option[text()="' + stylesheet + '"]', settings_document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
if (stylesheet_options.snapshotItem(0) !== null) {
if (stylesheet_select.value === stylesheet_options.snapshotItem(0).value && styleurl.value === '') {
// Stylesheet settings are already properly set, nothing to do
return;
}
else {
stylesheet_select.setAttribute('onchange', '');
stylesheet_select.value = stylesheet_options.snapshotItem(0).value;
styleurl.value = '';
}
}
else {
if (styleurl === stylesheet) {
// Stylesheet settings are already properly set, nothing to do
return;
}
else {
styleurl.value = stylesheet;
}
}
$.ajax({
url: "https://animebytes.tv/user.php?action=edit",
type: "post",
data: $(form).serialize()
});
}
}
}
}
// Add to user script settings
if (/\/user\.php\?.*action=edit/i.test(document.URL)) {
var settings = document.getElementById('deliciousdynamicstylesheets');
var add_button = document.createElement('button');
add_button.textContent = 'Add rule';
add_button.addEventListener('click', function(e) {