-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathscript.js
More file actions
5065 lines (4524 loc) · 224 KB
/
Copy pathscript.js
File metadata and controls
5065 lines (4524 loc) · 224 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
// Generate random number between two numbers https://stackoverflow.com/a/7228322
function getRndInteger(min, max) { // min and max included
return Math.floor(Math.random() * (max - min + 1) + min);
}
// https://developer.mozilla.org/en-US/docs/Web/API/Window/beforeunload_event#examples
function beforeUnloadListener(event) {
event.preventDefault();
return event.returnValue = '';
}
// Deep clone object
function deepClone(obj) {
return JSON.parse(JSON.stringify(obj));
}
// Check if string is number https://stackoverflow.com/a/175787
function isNumeric(data) {
if (typeof data == 'number') return true;
return !isNaN(data) && !isNaN(parseFloat(data));
}
function isUrl(str) {
try {
return new URL(str);
} catch (error) {
return false;
}
}
// Check if an image is loaded (no errors) https://stackoverflow.com/a/1977898
function isImageLoaded(img) {
if (!img.complete) return false;
if (img.naturalWidth === 0) return false;
return true;
}
// Check if browser is Chromium-based https://stackoverflow.com/a/62797156
function isChromium() {
return !!window.chrome || !!navigator.userAgentData && navigator.userAgentData.brands.some(data => data.brand == 'Chromium');
}
// Uppercase first character or letter
function firstUCase(str, letter) {
if (str.length == 0) return str;
if (letter) {
return str.replace(/\b\w/g, function(char) { return char.toUpperCase(); });
} else {
return str.charAt(0).toUpperCase() + str.slice(1);
}
}
// Toggle multiple classes
function toggleMtClass(elem, array) {
// example: toggleMtClass(document.body, ['mobile', 'no_js']);
for (var i in array) elem.classList.toggle(array[i]);
}
// Add and remove class with if/else statement
function toggleClass(elem, cls, cond) {
// example: toggleClass(document.body, 'no_js', true);
elem.classList[cond ? 'add' : 'remove'](cls);
}
// Add or remove from array
function modArray(note, array, str) {
if (note == 'add') array.push(str);
if (note == 'remove') return array.filter(function(item) { return item !== str });
return array;
}
function shuffleArray(array) {
const arr = deepClone(array);
for (let i = arr.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
[arr[i], arr[j]] = [arr[j], arr[i]];
}
return arr;
}
function urls(str) {
try {
var url = str || window.location;
return new URL(url);
} catch (error) {
console.error('!! ERROR: Invalid URL, url: '+ str);
return false;
}
}
// Escape
function escape(note, str) {
if (note == 'json') return str.replace(/["\&\t\b\f\r\n]/g, '\\$&');
if (note == 'regex') return str.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&');
if (note == 'html') return str.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/\'/g, ''').replace(/\"/g, '"');
}
// Extract data from hash, example: "#/page/1" use "getHash('page')" to get "1"
function getHash(k) {
// var rgx = new RegExp('#(?:.*)\\/'+ k +'\\/([^\\/]+)', 'i');
var rgx = new RegExp(k +'\\/([^\\/]+)', 'i');
var mtch = window.location.hash.match(rgx);
var str = mtch ? mtch[1] : null;
return str;
}
// Trigger event https://stackoverflow.com/a/35659572
function triggerEvent(evnt, elem) {
var event = new Event(evnt, {
bubbles: true,
cancelable: true,
});
elem.dispatchEvent(event);
}
// Position (X,Y) element https://stackoverflow.com/a/28222246
function getOffset(element) {
var rect = element.getBoundingClientRect();
var pos = {};
pos.top = rect.top + window.scrollY;
pos.right = rect.right + window.scrollX;
pos.bottom = rect.bottom + window.scrollY;
pos.left = rect.left + window.scrollX;
return pos;
}
// Get first {n} data from Array https://stackoverflow.com/a/50930772
function firstArray(array, length, last) {
return array.filter(function(item, index) {
if (last) {
return index >= length && index < array.length;
} else {
return index < length;
}
});
}
function genArray(json) {
var arr = [];
for (var key in json) {
arr.push(json[key]);
}
return arr;
}
function genJSON(array, param) {
var json = {};
for (index in array) {
var name = param ? array[index][param] : index;
name = bmf_fbase_limits(name);
json[name] = array[index];
}
return json;
}
// Sorting JSON by values https://stackoverflow.com/a/9188211
function sortBy(array, prop, asc) {
return array.sort(function(a, b) {
if (asc) {
return (a[prop] > b[prop]) ? 1 : ((a[prop] < b[prop]) ? -1 : 0);
} else {
return (b[prop] > a[prop]) ? 1 : ((b[prop] < a[prop]) ? -1 : 0);
}
});
}
// Local Storage
function local(prop, name, val) {
var methods = prop == 'get' ? 'getItem' : prop == 'set' ? 'setItem' : prop == 'remove' ? 'removeItem' : 'clear';
if (prop == 'set') return localStorage[methods](name, val);
if (prop == 'get' || prop == 'remove') return localStorage[methods](name);
if (prop == 'clear') return localStorage[methods]();
}
// Date toLocaleString() with local format, ref: https://www.w3schools.com/jsref/jsref_tolocalestring.asp
function dateLocal(date) {
var date_lang = 'id-ID';
var date_format = {
// timeZone: 'Asia/Jakarta',
hour12: false,
dateStyle: 'full',
timeStyle: 'long'
};
return new Date(date).toLocaleString(date_lang, date_format);
}
function keyEvent(event, code) {
// Based on the US standard 101 keyboard https://www.toptal.com/developers/keycode/table
var list = {"Enter":13,"Shift":16,"Control":17,"Alt":18,"ArrowLeft":37,"ArrowUp":38,"ArrowRight":39,"ArrowDown":40,"KeyA":65,"KeyC":67,"KeyI":73,"KeyJ":74,"KeyR":82,"KeyS":83,"KeyU":85,"KeyV":86,"KeyX":88,"F12":123};
var key, prop = '';
if (event.code && event.key) {
prop = event.code in list ? event.code : event.key;
key = list[prop];
} else {
key = event.keyCode;
}
return key == code || prop.toLowerCase() == String(code).toLowerCase() || new RegExp(`^${escape('regex', prop)}$`).test(code);
}
// Check document (DOM) status https://codepen.io/sekedus/pen/ZEMzorv
function loadListener(type, callback) {
type = type == 'initial' ? 0 : type == 'dom' ? 3 : 4; //4 = complete/load
var load_chk = setInterval(function() {
var ready = document.readyState;
var state = ready == 'uninitialized' ? 0 : ready == 'loading' ? 1 : ready == 'loaded' ? 2 : ready == 'interactive' ? 3 : 4;
if (state >= type) {
clearInterval(load_chk);
callback();
}
}, 100);
}
// Validation of file extension before upload https://stackoverflow.com/a/4237161
function fileValidate(elem, accept) {
if (elem.type == 'file') {
var file_name = elem.value;
if (file_name.length > 0) {
var valid = false;
for (var i = 0; i < accept.length; i++) {
if (file_name.substr(file_name.length - accept[i].length, accept[i].length).toLowerCase() == accept[i].toLowerCase()) {
valid = true;
break;
}
}
if (!valid) return false;
}
}
return true;
}
// Add script to head https://codepen.io/sekedus/pen/QWKYpVR
function addScript(options, callback) {
// data, id, info, boolean, parent
if (!('data' in options)) return;
var js_new = document.createElement('script');
if ('id' in options) js_new.id = options.id;
if ('async' in options) js_new.async = options.async;
if ('defer' in options) js_new.defer = options.defer;
if ('html' in options && options.html == true) {
js_new.type = 'text/javascript';
js_new.innerHTML = options.data;
} else {
if (callback) {
js_new.onerror = callback(true);
js_new.onload = callback(false);
}
js_new.src = options.data;
}
var parent = 'parent' in options && options.parent.tagName ? options.parent : document.querySelector('head');
parent.appendChild(js_new);
}
// Copy to clipboard https://stackoverflow.com/a/30810322
function copyToClipboard(text, elem) {
var msg, elm = elem || document.body; /* parent element for textarea */
var copyTextarea = document.createElement('textarea');
copyTextarea.value = text;
elm.appendChild(copyTextarea);
copyTextarea.focus();
copyTextarea.select();
try {
var successful = document.execCommand('copy');
msg = successful ? true : false;
} catch (error) {
msg = false;
console.log('Oops, unable to copy ', error);
}
elm.removeChild(copyTextarea);
return msg;
}
// Timestamp to relative time https://stackoverflow.com/a/6109105
function timeDifference(date) {
if (isNumeric(date)) {
date = Number(date);
if (date < 1e12) date *= 1000; //If it's in seconds, convert to milliseconds
}
var msPerMinute = 60 * 1000;
var msPerHour = msPerMinute * 60;
var msPerDay = msPerHour * 24;
var msPerMonth = msPerDay * 30;
var msPerYear = msPerDay * 365;
var elapsed = new Date() - new Date(date);
if (elapsed < msPerMinute) {
return Math.round(elapsed / 1000) + ' seconds ago';
} else if (elapsed < msPerHour) {
return Math.round(elapsed / msPerMinute) + ' minutes ago';
} else if (elapsed < msPerDay) {
return Math.round(elapsed / msPerHour) + ' hours ago';
} else if (elapsed < msPerMonth) {
return Math.round(elapsed / msPerDay) + ' days ago';
} else if (elapsed < msPerYear) {
return Math.round(elapsed / msPerMonth) + ' months ago';
} else {
return Math.round(elapsed / msPerYear) + ' years ago';
}
}
// Remove element https://codepen.io/sekedus/pen/ZEYRyeY
function removeElem(elem, index) {
var elmn = typeof elem === 'string' ? document.querySelectorAll(elem) : elem;
if (!elmn || (elmn && elmn.length == 0)) {
console.error('!! ERROR: removeElem(), elem = ', elem);
return;
}
// if match 1 element & have specific index
if (elmn && !elmn.length && index) {
console.error('!! ERROR: use querySelectorAll() for specific index');
return;
}
elmn = index ? (index == 'all' ? elmn : elmn[index]) : (typeof elem == 'string' || elmn.length ? elmn[0] : elmn);
if (elmn.length && index == 'all') {
for (var i = 0; i < elmn.length; i++) {
elmn[i].parentElement.removeChild(elmn[i]);
}
} else {
elmn.parentElement.removeChild(elmn);
}
}
// Simple querySelector https://codepen.io/sekedus/pen/oKYOEK
function el(e,l,m,n) {
var elem, parent = l != 'all' && l != 'xpath' && (l || l === null) ? l : document;
if (parent === null) {
elem = parent;
console.error('selector: '+ e +' => parent: '+ parent);
} else {
if ((n || m || l) == 'xpath') {
// https://stackoverflow.com/q/10596417
if ((m || l) == 'all') {
var result = document.evaluate(e, parent, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
elem = [];
for (var i = 0; i < result.snapshotLength; i++) {
elem.push(result.snapshotItem(i));
}
} else {
elem = document.evaluate(e, parent, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
}
} else {
elem = ((m || l) == 'all') ? parent.querySelectorAll(e) : parent.querySelector(e);
}
}
return elem;
}
// Detect mobile device https://stackoverflow.com/a/22327971
function isMobile() {
var ua = navigator.userAgent || navigator.vendor || window.opera;
return (/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino/i.test(ua) || /1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(ua.substr(0,4)));
}
// Cookies with custom timer https://codepen.io/sekedus/pen/xxYeZZj
var cookies = {
set: function(name, value, interval) {
var expires = '';
if (interval) {
var date = new Date();
var timer = interval.includes('|') ? Number(interval.split('|')[1]) : 1;
if (/(year|month)s?/i.test(interval)) {
var year_add = /years?/i.test(interval) ? timer : 0;
var month_add = /months?/i.test(interval) ? timer : 0;
date.setFullYear(date.getFullYear() + year_add, date.getMonth() + month_add);
} else {
var date_num = /weeks?/i.test(interval) ? (timer*7*24*60*60) : /days?/i.test(interval) ? (timer*24*60*60) : /hours?/i.test(interval) ? (timer*60*60) : /minutes?/i.test(interval) ? (timer*60) : timer; // default = second
date.setTime(date.getTime() + (date_num * 1000));
}
expires = '; expires='+ date.toGMTString();
}
// if no interval, timer = session
document.cookie = name +'='+ value + expires+'; path=/';
},
get: function(name) {
// https://www.quirksmode.org/js/cookies.html
var nameEQ = name +'=';
var ca = document.cookie.split(';');
for (var i = 0; i < ca.length; i++) {
var c = ca[i];
while (c.charAt(0) == ' ') c = c.substring(1, c.length);
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
}
return null;
},
remove: function(name) {
document.cookie = name +'=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;';
document.cookie = name +'=; Max-Age=0; path=/; domain='+ window.location.hostname;
},
};
// #===========================================================================================#
// Filter Array data with multiple value https://stackoverflow.com/a/10870500
function bmf_filterBy(note, array, param) {
return array.filter(function(item) {
if (note == 'history' && !('bookmarked' in item)) item['bookmarked'] = 'false';
for (var i in param) {
// match or indexOf
if (!item[i].toString().match(param[i])) return null;
}
return item;
});
}
function bmf_get_id(title) {
var seriesID = title.replace(/&#{0,1}[a-z0-9]+;/gi, '').replace(/\([^\)]+\)/g, '');
// seriesID = seriesID.replace(/\s((bahasa?|sub(title)?)\s)?(\bindo\b|indos?nesiaa?)/i, '').replace(/(baca|read|download)\s/i, '').replace(/\s?(man(ga|hwa|hua)|[kc]omi[kc]s?|series|novel|anime)\s?/i, '\x20');
seriesID = seriesID.replace(/(\.|\t)+/g, '\x20').replace(/\s+/g, '\x20').replace(/[^\s\w\-]/g, '').replace(/\s+$/g, '').replace(/\s+/g, '-').toLowerCase();
return seriesID;
}
// Get URL Parameters https://codepen.io/sekedus/pen/jOpNmja
function bmf_getParam(param, url) {
if (!urls(url)) return false;
var result = [];
var params = urls(url).searchParams;
if (params.has(param)) result = params.getAll(param);
return result.length == 0 ? false : result;
}
function bmf_connectionNotif(e) {
bmv_connection = e.type;
if (bmv_connection == 'online' && !el('#connection')) return;
var c_el;
if (el('#connection')) {
c_el = el('#connection');
} else {
c_el = document.createElement('div');
c_el.id = 'connection';
document.body.appendChild(c_el);
c_el.addEventListener('click', function() {
if (bmv_connection != 'online') {
toggleMtClass(this, ['red', 'bgrey', 'hide', 'pulse']);
if (this.classList.contains('hide')) {
this.setAttribute('title', this.innerHTML);
this.innerHTML = '<svg data-name="mdi/globe-remove" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><path fill="currentColor" d="m14.46 15.88l1.42-1.42L18 16.59l2.12-2.12l1.42 1.41L19.41 18l2.13 2.12l-1.42 1.42L18 19.41l-2.12 2.13l-1.42-1.42L16.59 18l-2.12-2.12M20 12c0-3.36-2.07-6.23-5-7.41V5c0 1.1-.9 2-2 2h-2v2c0 .55-.45 1-1 1H8v2h6c.5 0 .9.35 1 .81c-1.8 1.04-3 2.98-3 5.19c0 1.5.54 2.85 1.44 3.9L12 22C6.5 22 2 17.5 2 12S6.5 2 12 2s10 4.5 10 10l-.1 1.44c-.56-.48-1.2-.85-1.9-1.1V12m-9 7.93V18c-1.1 0-2-.9-2-2v-1l-4.79-4.79C4.08 10.78 4 11.38 4 12c0 4.08 3.06 7.44 7 7.93Z"/></svg>';
} else {
this.innerHTML = this.getAttribute('title');
}
}
});
}
var c_msg = bmv_connection == 'online' ? 'Kembali Online.' : 'Tidak ada koneksi internet. Pastikan Wi-Fi atau data seluler aktif, lalu muat ulang halaman.';
// var c_msg = bmv_connection == 'online' ? 'Internet connected.' : 'No internet connection. Make sure Wi-Fi or mobile data is turned on, then reload the page.';
c_el.className = bmv_connection == 'online' ? 'green' : 'red';
c_el.innerHTML = c_msg;
if (bmv_connection == 'online') {
setTimeout(function() {
if (bmv_connection == 'online') removeElem(c_el);
}, 1500);
if (!bmv_page_loaded) wl.reload();
}
}
// loadXMLDoc (XMLHttpRequest) https://codepen.io/sekedus/pen/vYGYBNP
function bmf_loadXMLDoc(info, url, callback) {
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function() {
if (xhr.readyState == XMLHttpRequest.DONE) {
var response = this.responseText;
if (this.status == 200) {
if (info.parse) {
var resHTML = new DOMParser();
response = resHTML.parseFromString(response, 'text/html');
}
} else {
var err_msg = '❗ ERROR: bmf_loadXMLDoc';
if ('timeout' in info) err_msg += ` timed out (${info.timeout}).`;
err_msg += ' status = '+ this.status +', url = '+ url;
console.error(err_msg);
}
var data = {"code": this.status, "response": response};
if (typeof err_msg !== 'undefined') data.error = err_msg;
callback(info.note, data);
}
};
xhr.open('GET', url, true);
xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
if ('timeout' in info) xhr.timeout = info.timeout;
xhr.send();
}
// Lazy Loading Images
function bmf_lazyLoad(elem, note) {
if (!elem) return;
var lz_check_point, lz_images = elem;
if (!el('#lz_check_point')) {
lz_check_point = document.createElement('div');
lz_check_point.id = 'lz_check_point';
lz_check_point.style.cssText = 'position:fixed;top:0;bottom:0;left:-2px;';
document.body.appendChild(lz_check_point);
} else {
lz_check_point = el('#lz_check_point');
}
function lazyReset() {
bmv_chk_lazy = false;
bmv_lz_error = false;
bmv_lz_skip = false;
}
function lazyNext() {
bmv_dt_lazy.splice(0, 1); //remove first image
if (bmv_dt_lazy.length > 0) lazyQueue();
}
function lazyUrl(elem, url, callback) {
if (bmv_load_cdn || url == '') {
callback(url);
return;
}
var url_original = url;
var img_api = bmv_config.resize || `${api_path}/tools`;
if (is_mobile && bmv_dt_st.img_resize) {
var lz_width = bmv_current == 'chapter' ? window.screen.width : (window.screen.width / 2);
// image generated by wordpress or wp.com, example: "image-128x183.jpg" or "image.jpg?w=300" or "image.jpg?resize=146,208"
var resize_rgx = /(?:-(\d+)x\d+\.|(?:w|resize|fit)=(\d+))/;
var lz_size = url.match(resize_rgx);
if (lz_size && Number(lz_size[1]) <= lz_width && elem.dataset.ref == 'false') {
callback(url);
return;
}
var lz_params = '?quality='+ bmv_dt_st.resize_quality;
if (bmv_current == 'chapter') lz_params += '&index='+ elem.dataset.index;
lz_params += '&width='+ (lz_width + 50);
lz_params += '&ref='+ encodeURIComponent(bmv_lz_referer || urls(url).origin);
lz_params += '&name='+ bmv_dt_st.source.site +'_'+ bmf_get_id(elem.title);
lz_params += '&imageUrl='+ encodeURIComponent(url);
bmf_loadXMLDoc({note:`xhr/${bmv_current}/lazyload`, timeout:30000}, `${img_api}/img_chk.php${lz_params}`, function(n, res) {
if (res.code == 200 && res.response != '') {
try {
var img_data = JSON.parse(res.response);
if (img_data.status == 'success') {
url = img_data.img_url;
if (img_data['blocked']) {
var url_proxy = `${img_api}/img_ref.php?ref=${encodeURIComponent(bmv_lz_referer || urls(url_original).origin)}&url=`+ encodeURIComponent(url_original);
if (url == url_original) url = url_proxy;
if (bmv_current == 'chapter' && elem.parentElement.tagName == 'A') elem.parentElement.href = url_proxy;
}
} else {
throw new Error(img_data.error_message);
}
} catch (e) {
console.error(`!! ERROR: ${e}, ${url}`);
}
}
if ('error' in res) console.error(res.error);
callback(url);
});
} else {
if (elem.dataset.ref == 'true') {
url = `${img_api}/img_ref.php?ref=${encodeURIComponent(bmv_lz_referer || urls(url).origin)}&url=`+ encodeURIComponent(url);
if (bmv_current == 'chapter' && elem.parentElement.tagName == 'A') elem.parentElement.href = url;
}
callback(url);
}
}
function lazyQueue(single) {
if (bmv_chk_lazy) return;
var lz_elem = single ? single.elem : bmv_dt_lazy[0].elem;
var lz_img = new Image();
var lz_2nd = 'la2yloading';
lz_img.setAttribute('referrerpolicy', 'no-referrer');
var lz_wait;
if (bmv_current == 'chapter') {
lz_img = lz_elem;
lz_2nd = 'lazyload3d lazyshow';
// Get image dimensions before image has fully loaded https://stackoverflow.com/a/6575319
var lz_loaded = false;
lz_img.addEventListener('load', function() { lz_loaded = true; }, true);
lz_wait = setInterval(function() {
if (lz_loaded && lz_img.height > 0) {
clearInterval(lz_wait);
lz_elem.style.removeProperty('min-height');
lz_elem.style.minHeight = lz_img.height +'px';
}
}, 0);
if (el('.ch_menu')) el('.cm_ld_current').innerHTML = 'LZ ('+ lz_elem.dataset.index +')';
}
var imgs = single ? single.img : bmv_dt_lazy[0].img;
lz_elem.className = lz_elem.className.replace('lazy1oad', lz_2nd);
lz_img.onerror = function() { bmv_lz_error = true; };
bmv_chk_lazy = true;
if (!urls(imgs) || !single && isImageLoaded(lz_elem) && lz_elem.classList.contains('lazyload3d')) {
if (bmv_current == 'chapter') {
clearInterval(lz_wait);
lz_elem.style.removeProperty('min-height');
}
lazyReset();
lazyNext();
} else {
lazyUrl(lz_elem, imgs, function(url) {
lz_img.src = url;
var skip_time = bmv_current == 'chapter' && lz_elem.dataset.ref == 'false' && !is_mobile ? 60000 : 5000;
var skip_img = setTimeout(function() { bmv_lz_skip = true; }, skip_time);
var wait_img = setInterval(function() {
if (isImageLoaded(lz_img) || bmv_lz_error || bmv_lz_skip) {
clearInterval(wait_img);
clearTimeout(skip_img);
// repeat, if error
if (bmv_lz_error && url != '' && (lz_img.src.match(bmv_rgx_cdn) || lz_elem.dataset.ref == 'false')) {
lazyReset();
if (lz_img.src.match(bmv_rgx_cdn)) { //cdn is true
var err_url = lz_img.src.replace(bmv_rgx_cdn, '');
if (/imagecdn|weserv/.test(bmv_str_cdn)) err_url = decodeURIComponent(err_url.replace(/^(https?:)?\/\//, ''));
var img_elem = single ? single : bmv_dt_lazy[0];
img_elem.img = err_url;
} else if (lz_elem.dataset.ref == 'false') {
lz_elem.dataset.ref = 'true';
}
if (single) {
lazyQueue(single);
} else {
lazyQueue();
}
} else {
lz_elem.className = lz_elem.className.replace('la2yloading', 'lazyload3d');
lz_elem.classList.remove('loading', 'loge');
toggleClass(lz_elem, 'no-image', bmv_lz_error);
lz_elem.style.removeProperty('min-height');
if (bmv_current == 'chapter') {
if (bmv_lz_error) clearInterval(lz_wait);
} else {
lz_elem.src = lz_img.src;
// lz_elem.removeAttribute('data-src');
setTimeout(function() { lz_elem.classList.add('lazyshow'); }, 100); //transition
}
lz_elem.parentElement.classList.add('lazy-loaded');
lazyReset();
if (!single) lazyNext();
}
}
}, 100);
});
}
}
function lazyPos(img) {
var lz_top = (getOffset(img).top + img.offsetHeight) > getOffset(lz_check_point).top;
var lz_bottom = (getOffset(img).bottom - img.offsetHeight) < getOffset(lz_check_point).bottom;
return lz_top && lz_bottom;
}
function lazyLegacy(elem, index = 0) {
var lz_chk1 = lazyPos(elem) && !elem.classList.contains('lazyload3d');
var lz_next = false;
if (bmv_current == 'chapter' && 'length' in lz_images) {
// load next image, top to bottom
var lz_chk3 = lazyPos(lz_images[index]) && lz_images[index].classList.contains('lazyload3d');
var lz_chk4 = lz_images[index+1] && !lazyPos(lz_images[index+1]) && lz_images[index+1].classList.contains('lazy1oad');
if (lz_chk3 && lz_chk4) {
lz_images[index].parentElement.classList.add('load-next');
elem = lz_images[index+1];
lz_next = true;
}
}
if (lz_chk1 || note == 'single' || note == 'multi' || lz_next) {
elem.classList.remove('lazyload3d', 'lazyshow', 'no-image');
elem.classList.add('loading', 'loge', 'lazy1oad');
elem.setAttribute('data-ref', 'false');
var img = elem.dataset.src;
if (bmv_current == 'chapter') {
img = bmv_load_cdn && /imagecdn|weserv/.test(bmv_str_cdn) ? encodeURIComponent(img) : img.replace(/^(https?:)?\/\//, '');
if (bmv_chk_cdn) img = img.replace(bmv_rgx_cdn, '').replace(/\/[fhwq]=[^\/]+/, '');
if (bmv_load_cdn) img = bmv_str_cdn_url + img;
img = wl.protocol +'//'+ img;
// remove location.search ?=
if (/(pending\-load|cdn\.statically\.io|cdn\.imagesimple\.co)/.test(img)) img = img.replace(/\?(.*)/g, '');
// google images (blogger, gdrive, gphotos)
if (bmv_load_gi) {
var sNum = el('.cm_size').innerHTML;
img = img.replace(/\/([swh]\d+)(?:-[\w]+[^\/]*)?\//, '/'+ sNum +'/');
img = img.replace(/=[swh](\d+).*/, '='+ sNum);
if (img.includes('docs.google')) img = 'https://lh3.googleusercontent.com/d/'+ img.match(/.*id=([^&]+)/)[1] +'='+ sNum;
}
}
if (note == 'single') {
if (bmv_current == 'chapter') {
elem.style.minHeight = '750px';
elem.removeAttribute('src');
}
lazyQueue({"elem": elem, "img": img});
} else {
if (!bmv_dt_lazy.some(function(item) {return item.img == img})) bmv_dt_lazy.push({"elem": elem, "img": img}); //avoid duplicate
lazyQueue();
}
}
}
if ('length' in lz_images) {
lz_images.forEach(lazyLegacy);
} else {
lazyLegacy(lz_images);
}
}
// #===========================================================================================#
// Element selector meta tags
function bmf_emc(m, c) {
el('meta['+ m +']').setAttribute('content', c);
}
function bmf_meta_tags(note, data) {
var d_desc = bmv_settings.l10n.meta_tags.desc;
var d_key = bmv_settings.l10n.meta_tags.key;
var mt_page = getHash('page') ? ` \u2013 Laman ${getHash('page')}` : '';
var mt_title = bmv_current == 'search' && bmf_getParam('params', w_href)[0] == 'default' ? bmv_settings.l10n.all_series : el('h1').textContent +' | Bakomon';
var mt_url = wl.href;
var mt_img = 'https://'+ wl.hostname +'/images/cover.png';
var mt_desc = bmv_settings.l10n.meta_tags.desc2;
if (bmv_current == 'series') {
mt_img = data.cover.replace(/\?.*/, '');
mt_desc = data.desc.length > 87 ? data.desc.substring(0, 87) +'...' : data.desc;
}
if (bmv_current == 'chapter') {
if (fbase_user && fbase_user['\x74\x69\x65\x72'] == '\x70\x72\x6f') mt_title = `[${data.current.replace(/[-\s]((bahasa?[-\s])?(\bindo\b|indos?nesiaa?)|full)/, '')}] `+ mt_title;
d_desc = mt_desc = bmv_settings.l10n.meta_tags.desc_chapter.replace('{data_title}', data.title);
d_key += ', '+ data.title +' Chapter '+ data.current;
}
document.title = bmv_current == 'latest' ? `Bakomon${mt_page} \u2013 ${bmv_settings.l10n.meta_tags.title}` : mt_title;
bmf_emc('name="description"', d_desc);
bmf_emc('name="keywords"', d_key);
bmf_emc('itemprop="name"', mt_title);
bmf_emc('itemprop="description"', mt_desc);
bmf_emc('itemprop="image"', mt_img);
bmf_emc('property="og:title"', mt_title);
bmf_emc('property="og:url"', mt_url);
bmf_emc('property="og:image"', mt_img);
bmf_emc('property="og:description"', mt_desc);
bmf_emc('name="twitter:title"', mt_title);
bmv_current == 'latest' ? bmf_emc('property="og:type"', 'website') : bmf_emc('property="og:type"', 'article');
}
// #===========================================================================================#
function bmf_member_notif(info, opt) {
clearTimeout(bmv_mnotif_timeout);
if (info == 'reset') {
el('.member .m-notif').classList.remove('error');
el('.member .m-notif').classList.add('no_items');
return;
}
var m_info = info.replace(/.*\//, '');
var m_msg = m_info.replace(/\-/g, '\x20');
if (opt && 'message' in opt) m_msg = opt.message;
if (info.includes('error')) {
if (m_info == 'wrong-password') {
m_msg = 'Katasandi yang Kamu masukkan salah.';
if (!fbase_login) m_msg += ' <a href="#/member/forgot">Lupa katasandi?</a>';
}
if (m_info == 'user-not-found') m_msg = 'Email tidak terdaftar. Periksa lagi atau <a href="#/member/signup">daftar akun baru.</a>';
if (m_info == 'email-already-in-use') m_msg = 'Email sudah terdaftar. <a href="#/member/login">Login disini.</a>';
if (m_info == 'confirm-password') m_msg = 'Konfirmasi katasandi <b>TIDAK SAMA</b>';
m_msg = '<b>Error:</b> '+ m_msg +'';
el('.member .m-notif').classList.add('error');
} else {
if (m_info == 'email-verification') {
m_msg = '<span class="success">Link verifikasi email terkirim ke <b>'+ fbase_user.email +'</b></span>. Silahkan cek folder "Kotak Masuk" atau "Spam" di email.';
} else {
m_msg = '<span class="success">'+ m_msg +'</b></span>';
}
}
el('.member .m-notif').innerHTML = m_msg;
el('.member .m-notif').classList.remove('no_items');
document.body.scrollIntoView();
if (opt && 'timer' in opt) {
var milliseconds = isNumeric(opt.timer) ? opt.timer : Number(opt.timer);
bmv_mnotif_timeout = setTimeout(function() {
if (el('.member .m-notif')) el('.member .m-notif').classList.add('no_items');
}, milliseconds);
}
}
function bmf_member_valid(note, elem, elem_c) {
var m_valid = false;
var m_msg = elem.validationMessage;
// console.log(elem.validity);
if (elem.checkValidity()) {
m_valid = true;
if (note == 'cover') {
if (!fileValidate(elem, ['png', 'gif', 'jpg', 'jpeg'])) {
m_valid = false;
m_msg = 'file-format-not-supported';
}
}
if (note == 'pass-c') {
if (elem.value != elem_c.value) {
m_valid = false;
m_msg = 'confirm-password';
}
}
}
if (!m_valid) bmf_member_notif('error/'+ m_msg);
return m_valid;
}
function bmf_member_hibp(note, user, callback) {
if (new RegExp(user.pass, 'i').test(user.email) || new RegExp(user.name, 'i').test(user.pass)) {
if (callback) callback(true);
} else {
bmf_loadXMLDoc({note:`xhr/${bmv_current}/${note}`}, `${api_path}/tools/hibp.php?pass=${btoa(user.pass)}`, function(n, data) {
var pwned, hibp = JSON.parse(data.response);
if (hibp.pawned > 0) pwned = true;
if (callback) callback(pwned);
});
}
}
function bmf_email_verification(note, user, callback) {
// Default expiration time: https://github.com/firebase/firebase-js-sdk/issues/1884#issuecomment-545598830
fbase.auth().languageCode = 'id';
user.sendEmailVerification({
url: `${bmv_homepage}#/member/profile`
}).then(() => {
cookies.set('bmv_signup_verify', 'true', 'hour|1');
if (bmv_prm_slug == 'profile') bmf_member_notif(`success/${note}/email-verification`);
if (callback) callback();
}).catch(function(error) {
bmf_member_notif('error/verification/'+ error.code);
if (bmv_prm_slug == 'profile') el('.m-profile .m-detail').classList.remove('loading', 'loge');
console.error('!! ERROR: Firebase sendEmailVerification, code: '+ error.code +', message: '+ error.message);
// alert('!! ERROR: Firebase sendEmailVerification(\n'+ error.message);
});
}
function bmf_bmhs_key(e) {
if (keyEvent(e, 13)) {
if (el('.ms-form .ms-field') == e.target) el('.ms-form .ms-search').click();
if (el('.m-pagination .bmhs-goto') == e.target) bmf_bmhs_nav_goto(el('.m-pagination .bmhs-goto').value);
}
}
function bmf_bmhs_change(info, total) {
// update bmhs total data in firebase "check"
var m_info = info.split('|');
var m_path = bmf_fbase_path(`check/${m_info[0]}`);
bmf_fbase_db_get(`series/${m_info[0]}/${m_info[1]}`, m_path, function(res) {
var m_length = res.val() ? Number(res.val().length) : 0;
if (m_info[1] == 'remove') m_length = m_length > 0 ? (m_length - 1) : m_length;
if (m_info[1] == 'set') m_length = m_length + 1;
if (typeof total === 'number') m_length = total;
var m_chk_data = bmf_fbase_gen(`${m_info[0]}|check`, {length: m_length});
bmf_fbase_db_change(`series/${m_info[0]}/check`, m_path, 'set', m_chk_data);
});
}
function bmf_bmhs_length(note) {
var m_path = bmf_fbase_path(`check/${bmv_prm_slug}`);
bmf_fbase_db_get(note, m_path, function(res) {
var m_length = res.val() ? Number(res.val().length) : 0;
var m_sort = bmv_prm_slug == 'bookmark' ? 'bm_added' : 'hs_update';
if (m_length > bmv_max_bmhs) {
var new_data = genArray(bmv_dt_bmhs); //convert to Array
new_data = sortBy(new_data, m_sort); //sot by "m_sort" (desc)
new_data = firstArray(new_data, bmv_max_bmhs, 'last'); //get last after {bmv_max_bmhs} data
for (var i in new_data) bmf_bmhs_remove(`series/${new_data[i].slug}`);
}
});
}
function bmf_bmhs_remove_split(data) {
if (bmv_prm_slug == 'bookmark') {
// if there is a history list, bookmark = false
if ('hs_visited' in data) {
data.bookmarked = 'false';
return data;
}
} else { //history
// if bookmarked, history list = empty
if ('bookmarked' in data && data.bookmarked == 'true') {
data.history = 'false';
data.hs_visited = {};
return data;
}
}
// not bookmarked & no history list, return = empty (removed)
return {};
}
function bmf_bmhs_remove(note, dp) {
// dp = duplicate
var m_note = `member/${bmv_prm_slug}/${note}`;
var m_path = bmf_fbase_path(note);
bmf_fbase_db_get(m_note, m_path, function(res) {
var series = res.val();
var new_series = {};
if (note == 'series') { //remove all
for (var i in series) new_series[series[i].slug] = bmf_bmhs_remove_split(series[i]);
bmv_dt_bmhs = null;
} else {
new_series = !dp ? bmf_bmhs_remove_split(series) : {"slug": series.slug,"duplicate": true,"duplicate_id": dp};
delete bmv_dt_bmhs[series.slug];
}
bmf_fbase_db_change(m_note, m_path, 'set', new_series, function() {
var m_length = genArray(bmv_dt_bmhs).length;
bmf_bmhs_change(`${bmv_prm_slug}|remove`, m_length);
el('.member .m-total').innerHTML = m_length +'/'+ bmv_max_bmhs;
if (m_length > 0) {
bmf_member_bmhs_data(`${bmv_prm_slug}/delete`); //re-generate bmhs data
bmf_bmhs_reset('remove');
if (dp && bmv_dt_delete == 0) el('.member .post-content').classList.remove('loading', 'loge');
} else { //empty
el('.member .m-total').classList.add('no_items');
el('.member .m-action').classList.add('no_items');
el('.member .m-nav').classList.add('no_items');
el('.member .m-list').classList.remove('loading', 'loge');
el('.member .m-list').innerHTML = `<div class="flex f_middle f_center full" style="min-height:230px;">${firstUCase(bmv_prm_slug)} Kosong</div>`;
el('.member .m-pagination').classList.add('no_items');
}
});
});
}
function bmf_bmhs_reset(note) {
bmv_dt_delete = [];
if (!note) {
var ma_active = el('.m-action .act-active');
if (ma_active) {
ma_active.classList.remove('act-active');
if (ma_active.hasAttribute('data-act-pos')) el('.m-act-body').classList.remove(ma_active.dataset.actPos);
}
el('.m-act-body').classList.add('no_items');
el('.act-delete').classList.add('no_items');
if (bmv_prm_slug == 'bookmark') el('.act-duplicate').classList.add('no_items');
el('.nav-delete').classList.add('no_items');
}
if (bmv_prm_slug == 'bookmark') {
el('.act-duplicate input').value = '';
el('.act-duplicate textarea').value = '';
var m_list = el('.m-list .highlighted .duplicate input', 'all');
if (m_list.length > 0) {
m_list.forEach(function(item) {
item.checked = false;
triggerEvent('change', item);
});
}
}
el('.m-delete-select').classList.remove('pulse');
el('.m-select-all input').checked = false;
}
function bmf_bmhs_fnc(note) {
if (note == 'first') {
el('.post-header h1 span').classList.add('m-total', 'btn', 'cs_default');
if (is_mobile) el('.member .m-action').classList.add('m-space-v', 'full');
el('.member .m-action').classList.remove('no_items');