Repository navigation
Expand file tree
/
Copy pathuserscript.js
More file actions
1364 lines (1232 loc) · 58 KB
/
Copy pathuserscript.js
File metadata and controls
1364 lines (1232 loc) · 58 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 Return YouTube Subscribers
// @namespace ryts.mgcounts.com
// @version 4.4.1
// @description See exact subscriber counts on YouTube again: on channel pages, under videos, and in search results.
// @author @ok_aj
// @homepageURL https://ryts.mgcounts.com
// @supportURL https://github.com/returnyoutubesubscribers/returnyoutubesubscribers.github.io/issues
// @match *://*.youtube.com/*
// @icon https://raw.githubusercontent.com/returnyoutubesubscribers/returnyoutubesubscribers.github.io/main/src/icons/icon-128.png
// @downloadURL https://raw.githubusercontent.com/returnyoutubesubscribers/returnyoutubesubscribers.github.io/main/return-youtube-subscribers.user.js
// @updateURL https://raw.githubusercontent.com/returnyoutubesubscribers/returnyoutubesubscribers.github.io/main/return-youtube-subscribers.user.js
// @run-at document-start
// @noframes
// @grant none
// ==/UserScript==
// Generated from Odometer, src/shared.js and src/main.js by scripts/build.mjs. Do not edit by hand.
// Odometer 0.4.8 by HubSpot, MIT licence: https://github.hubspot.com/odometer/
// Bundled by scripts/build.mjs from node_modules/odometer. Do not edit by hand.
(function () {
var define, exports, module; // always a global
// Builds Odometer's templates, which are nested <span class="...">text</span> only.
function rytsSpans(html) {
var root = document.createDocumentFragment(), cur = root;
String(html).match(/<\/span>|<span(?: class="[^"]*")?>|[^<]+/g).forEach(function (tok) {
if (tok === "</span>") cur = cur.parentNode || root;
else if (tok.charAt(0) === "<") {
var span = document.createElement("span"), cls = tok.match(/class="([^"]*)"/);
if (cls) span.className = cls[1];
cur.appendChild(span);
cur = span;
} else cur.appendChild(document.createTextNode(tok));
});
return root;
}
(function() {
var COUNT_FRAMERATE, COUNT_MS_PER_FRAME, DIGIT_FORMAT, DIGIT_HTML, DIGIT_SPEEDBOOST, DURATION, FORMAT_MARK_HTML, FORMAT_PARSER, FRAMERATE, FRAMES_PER_VALUE, MS_PER_FRAME, MutationObserver, Odometer, RIBBON_HTML, TRANSITION_END_EVENTS, TRANSITION_SUPPORT, VALUE_HTML, addClass, createFromHTML, fractionalPart, now, removeClass, requestAnimationFrame, round, transitionCheckStyles, trigger, truncate, wrapJQuery, _jQueryWrapped, _old, _ref, _ref1,
__slice = [].slice;
VALUE_HTML = '<span class="odometer-value"></span>';
RIBBON_HTML = '<span class="odometer-ribbon"><span class="odometer-ribbon-inner">' + VALUE_HTML + '</span></span>';
DIGIT_HTML = '<span class="odometer-digit"><span class="odometer-digit-spacer">8</span><span class="odometer-digit-inner">' + RIBBON_HTML + '</span></span>';
FORMAT_MARK_HTML = '<span class="odometer-formatting-mark"></span>';
DIGIT_FORMAT = '(,ddd).dd';
FORMAT_PARSER = /^\(?([^)]*)\)?(?:(.)(d+))?$/;
FRAMERATE = 30;
DURATION = 2000;
COUNT_FRAMERATE = 20;
FRAMES_PER_VALUE = 2;
DIGIT_SPEEDBOOST = .5;
MS_PER_FRAME = 1000 / FRAMERATE;
COUNT_MS_PER_FRAME = 1000 / COUNT_FRAMERATE;
TRANSITION_END_EVENTS = 'transitionend webkitTransitionEnd oTransitionEnd otransitionend MSTransitionEnd';
transitionCheckStyles = document.createElement('div').style;
TRANSITION_SUPPORT = (transitionCheckStyles.transition != null) || (transitionCheckStyles.webkitTransition != null) || (transitionCheckStyles.mozTransition != null) || (transitionCheckStyles.oTransition != null);
requestAnimationFrame = window.requestAnimationFrame || window.mozRequestAnimationFrame || window.webkitRequestAnimationFrame || window.msRequestAnimationFrame;
MutationObserver = window.MutationObserver || window.WebKitMutationObserver || window.MozMutationObserver;
createFromHTML = function(html) {
var el;
el = document.createElement('div');
el.append(rytsSpans(html));
return el.children[0];
};
removeClass = function(el, name) {
return el.className = el.className.replace(new RegExp("(^| )" + (name.split(' ').join('|')) + "( |$)", 'gi'), ' ');
};
addClass = function(el, name) {
removeClass(el, name);
return el.className += " " + name;
};
trigger = function(el, name) {
var evt;
if (document.createEvent != null) {
evt = document.createEvent('HTMLEvents');
evt.initEvent(name, true, true);
return el.dispatchEvent(evt);
}
};
now = function() {
var _ref, _ref1;
return (_ref = (_ref1 = window.performance) != null ? typeof _ref1.now === "function" ? _ref1.now() : void 0 : void 0) != null ? _ref : +(new Date);
};
round = function(val, precision) {
if (precision == null) {
precision = 0;
}
if (!precision) {
return Math.round(val);
}
val *= Math.pow(10, precision);
val += 0.5;
val = Math.floor(val);
return val /= Math.pow(10, precision);
};
truncate = function(val) {
if (val < 0) {
return Math.ceil(val);
} else {
return Math.floor(val);
}
};
fractionalPart = function(val) {
return val - round(val);
};
_jQueryWrapped = false;
(wrapJQuery = function() {
var property, _i, _len, _ref, _results;
if (_jQueryWrapped) {
return;
}
if (window.jQuery != null) {
_jQueryWrapped = true;
_ref = ['html', 'text'];
_results = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
property = _ref[_i];
_results.push((function(property) {
var old;
old = window.jQuery.fn[property];
return window.jQuery.fn[property] = function(val) {
var _ref1;
if ((val == null) || (((_ref1 = this[0]) != null ? _ref1.odometer : void 0) == null)) {
return old.apply(this, arguments);
}
return this[0].odometer.update(val);
};
})(property));
}
return _results;
}
})();
setTimeout(wrapJQuery, 0);
Odometer = (function() {
function Odometer(options) {
var e, k, property, v, _base, _i, _len, _ref, _ref1, _ref2,
_this = this;
this.options = options;
this.el = this.options.el;
if (this.el.odometer != null) {
return this.el.odometer;
}
this.el.odometer = this;
_ref = Odometer.options;
for (k in _ref) {
v = _ref[k];
if (this.options[k] == null) {
this.options[k] = v;
}
}
if ((_base = this.options).duration == null) {
_base.duration = DURATION;
}
this.MAX_VALUES = ((this.options.duration / MS_PER_FRAME) / FRAMES_PER_VALUE) | 0;
this.resetFormat();
this.value = this.cleanValue((_ref1 = this.options.value) != null ? _ref1 : '');
this.renderInside();
this.render();
try {
_ref2 = ['innerHTML', 'innerText', 'textContent'];
for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
property = _ref2[_i];
if (this.el[property] != null) {
(function(property) {
return Object.defineProperty(_this.el, property, {
get: function() {
var _ref3;
if (property === 'innerHTML') {
return _this.inside.outerHTML;
} else {
return (_ref3 = _this.inside.innerText) != null ? _ref3 : _this.inside.textContent;
}
},
set: function(val) {
return _this.update(val);
}
});
})(property);
}
}
} catch (_error) {
e = _error;
this.watchForMutations();
}
this;
}
Odometer.prototype.renderInside = function() {
this.inside = document.createElement('div');
this.inside.className = 'odometer-inside';
this.el.textContent = '';
return this.el.appendChild(this.inside);
};
Odometer.prototype.watchForMutations = function() {
var e,
_this = this;
if (MutationObserver == null) {
return;
}
try {
if (this.observer == null) {
this.observer = new MutationObserver(function(mutations) {
var newVal;
newVal = _this.el.innerText;
_this.renderInside();
_this.render(_this.value);
return _this.update(newVal);
});
}
this.watchMutations = true;
return this.startWatchingMutations();
} catch (_error) {
e = _error;
}
};
Odometer.prototype.startWatchingMutations = function() {
if (this.watchMutations) {
return this.observer.observe(this.el, {
childList: true
});
}
};
Odometer.prototype.stopWatchingMutations = function() {
var _ref;
return (_ref = this.observer) != null ? _ref.disconnect() : void 0;
};
Odometer.prototype.cleanValue = function(val) {
var _ref;
if (typeof val === 'string') {
val = val.replace((_ref = this.format.radix) != null ? _ref : '.', '<radix>');
val = val.replace(/[.,]/g, '');
val = val.replace('<radix>', '.');
val = parseFloat(val, 10) || 0;
}
return round(val, this.format.precision);
};
Odometer.prototype.bindTransitionEnd = function() {
var event, renderEnqueued, _i, _len, _ref, _results,
_this = this;
if (this.transitionEndBound) {
return;
}
this.transitionEndBound = true;
renderEnqueued = false;
_ref = TRANSITION_END_EVENTS.split(' ');
_results = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
event = _ref[_i];
_results.push(this.el.addEventListener(event, function() {
if (renderEnqueued) {
return true;
}
renderEnqueued = true;
setTimeout(function() {
_this.render();
renderEnqueued = false;
return trigger(_this.el, 'odometerdone');
}, 0);
return true;
}, false));
}
return _results;
};
Odometer.prototype.resetFormat = function() {
var format, fractional, parsed, precision, radix, repeating, _ref, _ref1;
format = (_ref = this.options.format) != null ? _ref : DIGIT_FORMAT;
format || (format = 'd');
parsed = FORMAT_PARSER.exec(format);
if (!parsed) {
throw new Error("Odometer: Unparsable digit format");
}
_ref1 = parsed.slice(1, 4), repeating = _ref1[0], radix = _ref1[1], fractional = _ref1[2];
precision = (fractional != null ? fractional.length : void 0) || 0;
return this.format = {
repeating: repeating,
radix: radix,
precision: precision
};
};
Odometer.prototype.render = function(value) {
var classes, cls, match, newClasses, theme, _i, _len;
if (value == null) {
value = this.value;
}
this.stopWatchingMutations();
this.resetFormat();
this.inside.textContent = '';
theme = this.options.theme;
classes = this.el.className.split(' ');
newClasses = [];
for (_i = 0, _len = classes.length; _i < _len; _i++) {
cls = classes[_i];
if (!cls.length) {
continue;
}
if (match = /^odometer-theme-(.+)$/.exec(cls)) {
theme = match[1];
continue;
}
if (/^odometer(-|$)/.test(cls)) {
continue;
}
newClasses.push(cls);
}
newClasses.push('odometer');
if (!TRANSITION_SUPPORT) {
newClasses.push('odometer-no-transitions');
}
if (theme) {
newClasses.push("odometer-theme-" + theme);
} else {
newClasses.push("odometer-auto-theme");
}
this.el.className = newClasses.join(' ');
this.ribbons = {};
this.formatDigits(value);
return this.startWatchingMutations();
};
Odometer.prototype.formatDigits = function(value) {
var digit, valueDigit, valueString, wholePart, _i, _j, _len, _len1, _ref, _ref1;
this.digits = [];
if (this.options.formatFunction) {
valueString = this.options.formatFunction(value);
_ref = valueString.split('').reverse();
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
valueDigit = _ref[_i];
if (valueDigit.match(/0-9/)) {
digit = this.renderDigit();
digit.querySelector('.odometer-value').textContent = valueDigit;
this.digits.push(digit);
this.insertDigit(digit);
} else {
this.addSpacer(valueDigit);
}
}
} else {
wholePart = !this.format.precision || !fractionalPart(value) || false;
_ref1 = value.toString().split('').reverse();
for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
digit = _ref1[_j];
if (digit === '.') {
wholePart = true;
}
this.addDigit(digit, wholePart);
}
}
};
Odometer.prototype.update = function(newValue) {
var diff,
_this = this;
newValue = this.cleanValue(newValue);
if (!(diff = newValue - this.value)) {
return;
}
removeClass(this.el, 'odometer-animating-up odometer-animating-down odometer-animating');
if (diff > 0) {
addClass(this.el, 'odometer-animating-up');
} else {
addClass(this.el, 'odometer-animating-down');
}
this.stopWatchingMutations();
this.animate(newValue);
this.startWatchingMutations();
setTimeout(function() {
_this.el.offsetHeight;
return addClass(_this.el, 'odometer-animating');
}, 0);
return this.value = newValue;
};
Odometer.prototype.renderDigit = function() {
return createFromHTML(DIGIT_HTML);
};
Odometer.prototype.insertDigit = function(digit, before) {
if (before != null) {
return this.inside.insertBefore(digit, before);
} else if (!this.inside.children.length) {
return this.inside.appendChild(digit);
} else {
return this.inside.insertBefore(digit, this.inside.children[0]);
}
};
Odometer.prototype.addSpacer = function(chr, before, extraClasses) {
var spacer;
spacer = createFromHTML(FORMAT_MARK_HTML);
spacer.textContent = chr;
if (extraClasses) {
addClass(spacer, extraClasses);
}
return this.insertDigit(spacer, before);
};
Odometer.prototype.addDigit = function(value, repeating) {
var chr, digit, resetted, _ref;
if (repeating == null) {
repeating = true;
}
if (value === '-') {
return this.addSpacer(value, null, 'odometer-negation-mark');
}
if (value === '.') {
return this.addSpacer((_ref = this.format.radix) != null ? _ref : '.', null, 'odometer-radix-mark');
}
if (repeating) {
resetted = false;
while (true) {
if (!this.format.repeating.length) {
if (resetted) {
throw new Error("Bad odometer format without digits");
}
this.resetFormat();
resetted = true;
}
chr = this.format.repeating[this.format.repeating.length - 1];
this.format.repeating = this.format.repeating.substring(0, this.format.repeating.length - 1);
if (chr === 'd') {
break;
}
this.addSpacer(chr);
}
}
digit = this.renderDigit();
digit.querySelector('.odometer-value').textContent = value;
this.digits.push(digit);
return this.insertDigit(digit);
};
Odometer.prototype.animate = function(newValue) {
if (!TRANSITION_SUPPORT || this.options.animation === 'count') {
return this.animateCount(newValue);
} else {
return this.animateSlide(newValue);
}
};
Odometer.prototype.animateCount = function(newValue) {
var cur, diff, last, start, tick,
_this = this;
if (!(diff = +newValue - this.value)) {
return;
}
start = last = now();
cur = this.value;
return (tick = function() {
var delta, dist, fraction;
if ((now() - start) > _this.options.duration) {
_this.value = newValue;
_this.render();
trigger(_this.el, 'odometerdone');
return;
}
delta = now() - last;
if (delta > COUNT_MS_PER_FRAME) {
last = now();
fraction = delta / _this.options.duration;
dist = diff * fraction;
cur += dist;
_this.render(Math.round(cur));
}
if (requestAnimationFrame != null) {
return requestAnimationFrame(tick);
} else {
return setTimeout(tick, COUNT_MS_PER_FRAME);
}
})();
};
Odometer.prototype.getDigitCount = function() {
var i, max, value, values, _i, _len;
values = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
for (i = _i = 0, _len = values.length; _i < _len; i = ++_i) {
value = values[i];
values[i] = Math.abs(value);
}
max = Math.max.apply(Math, values);
return Math.ceil(Math.log(max + 1) / Math.log(10));
};
Odometer.prototype.getFractionalDigitCount = function() {
var i, parser, parts, value, values, _i, _len;
values = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
parser = /^\-?\d*\.(\d*?)0*$/;
for (i = _i = 0, _len = values.length; _i < _len; i = ++_i) {
value = values[i];
values[i] = value.toString();
parts = parser.exec(values[i]);
if (parts == null) {
values[i] = 0;
} else {
values[i] = parts[1].length;
}
}
return Math.max.apply(Math, values);
};
Odometer.prototype.resetDigits = function() {
this.digits = [];
this.ribbons = [];
this.inside.textContent = '';
return this.resetFormat();
};
Odometer.prototype.animateSlide = function(newValue) {
var boosted, cur, diff, digitCount, digits, dist, end, fractionalCount, frame, frames, i, incr, j, mark, numEl, oldValue, start, _base, _i, _j, _k, _l, _len, _len1, _len2, _m, _ref, _results;
oldValue = this.value;
fractionalCount = this.getFractionalDigitCount(oldValue, newValue);
if (fractionalCount) {
newValue = newValue * Math.pow(10, fractionalCount);
oldValue = oldValue * Math.pow(10, fractionalCount);
}
if (!(diff = newValue - oldValue)) {
return;
}
this.bindTransitionEnd();
digitCount = this.getDigitCount(oldValue, newValue);
digits = [];
boosted = 0;
for (i = _i = 0; 0 <= digitCount ? _i < digitCount : _i > digitCount; i = 0 <= digitCount ? ++_i : --_i) {
start = truncate(oldValue / Math.pow(10, digitCount - i - 1));
end = truncate(newValue / Math.pow(10, digitCount - i - 1));
dist = end - start;
if (Math.abs(dist) > this.MAX_VALUES) {
frames = [];
incr = dist / (this.MAX_VALUES + this.MAX_VALUES * boosted * DIGIT_SPEEDBOOST);
cur = start;
while ((dist > 0 && cur < end) || (dist < 0 && cur > end)) {
frames.push(Math.round(cur));
cur += incr;
}
if (frames[frames.length - 1] !== end) {
frames.push(end);
}
boosted++;
} else {
frames = (function() {
_results = [];
for (var _j = start; start <= end ? _j <= end : _j >= end; start <= end ? _j++ : _j--){ _results.push(_j); }
return _results;
}).apply(this);
}
for (i = _k = 0, _len = frames.length; _k < _len; i = ++_k) {
frame = frames[i];
frames[i] = Math.abs(frame % 10);
}
digits.push(frames);
}
this.resetDigits();
_ref = digits.reverse();
for (i = _l = 0, _len1 = _ref.length; _l < _len1; i = ++_l) {
frames = _ref[i];
if (!this.digits[i]) {
this.addDigit(' ', i >= fractionalCount);
}
if ((_base = this.ribbons)[i] == null) {
_base[i] = this.digits[i].querySelector('.odometer-ribbon-inner');
}
this.ribbons[i].textContent = '';
if (diff < 0) {
frames = frames.reverse();
}
for (j = _m = 0, _len2 = frames.length; _m < _len2; j = ++_m) {
frame = frames[j];
numEl = document.createElement('div');
numEl.className = 'odometer-value';
numEl.textContent = frame;
this.ribbons[i].appendChild(numEl);
if (j === frames.length - 1) {
addClass(numEl, 'odometer-last-value');
}
if (j === 0) {
addClass(numEl, 'odometer-first-value');
}
}
}
if (start < 0) {
this.addDigit('-');
}
mark = this.inside.querySelector('.odometer-radix-mark');
if (mark != null) {
mark.parent.removeChild(mark);
}
if (fractionalCount) {
return this.addSpacer(this.format.radix, this.digits[fractionalCount - 1], 'odometer-radix-mark');
}
};
return Odometer;
})();
Odometer.options = (_ref = window.odometerOptions) != null ? _ref : {};
setTimeout(function() {
var k, v, _base, _ref1, _results;
if (window.odometerOptions) {
_ref1 = window.odometerOptions;
_results = [];
for (k in _ref1) {
v = _ref1[k];
_results.push((_base = Odometer.options)[k] != null ? (_base = Odometer.options)[k] : _base[k] = v);
}
return _results;
}
}, 0);
Odometer.init = function() {
var el, elements, _i, _len, _ref1, _results;
if (document.querySelectorAll == null) {
return;
}
elements = document.querySelectorAll(Odometer.options.selector || '.odometer');
_results = [];
for (_i = 0, _len = elements.length; _i < _len; _i++) {
el = elements[_i];
_results.push(el.odometer = new Odometer({
el: el,
value: (_ref1 = el.innerText) != null ? _ref1 : el.textContent
}));
}
return _results;
};
if ((((_ref1 = document.documentElement) != null ? _ref1.doScroll : void 0) != null) && (document.createEventObject != null)) {
_old = document.onreadystatechange;
document.onreadystatechange = function() {
if (document.readyState === 'complete' && Odometer.options.auto !== false) {
Odometer.init();
}
return _old != null ? _old.apply(this, arguments) : void 0;
};
} else {
document.addEventListener('DOMContentLoaded', function() {
if (Odometer.options.auto !== false) {
return Odometer.init();
}
}, false);
}
if (typeof define === 'function' && define.amd) {
define([], function() {
return Odometer;
});
} else if (typeof exports !== "undefined" && exports !== null) {
module.exports = Odometer;
} else {
window.Odometer = Odometer;
}
}).call(this);
window.Odometer.options.auto = false; // only elements we create
window.Odometer.themeCSS = ".odometer.odometer-auto-theme, .odometer.odometer-theme-minimal {\n display: inline-block;\n vertical-align: middle;\n position: relative;\n}\n.odometer.odometer-auto-theme .odometer-digit, .odometer.odometer-theme-minimal .odometer-digit {\n display: inline-block;\n vertical-align: middle;\n position: relative;\n}\n.odometer.odometer-auto-theme .odometer-digit .odometer-digit-spacer, .odometer.odometer-theme-minimal .odometer-digit .odometer-digit-spacer {\n display: inline-block;\n vertical-align: middle;\n visibility: hidden;\n}\n.odometer.odometer-auto-theme .odometer-digit .odometer-digit-inner, .odometer.odometer-theme-minimal .odometer-digit .odometer-digit-inner {\n text-align: left;\n display: block;\n position: absolute;\n top: 0;\n left: 0;\n right: 0;\n bottom: 0;\n overflow: hidden;\n}\n.odometer.odometer-auto-theme .odometer-digit .odometer-ribbon, .odometer.odometer-theme-minimal .odometer-digit .odometer-ribbon {\n display: block;\n}\n.odometer.odometer-auto-theme .odometer-digit .odometer-ribbon-inner, .odometer.odometer-theme-minimal .odometer-digit .odometer-ribbon-inner {\n display: block;\n -webkit-backface-visibility: hidden;\n}\n.odometer.odometer-auto-theme .odometer-digit .odometer-value, .odometer.odometer-theme-minimal .odometer-digit .odometer-value {\n display: block;\n -webkit-transform: translateZ(0);\n}\n.odometer.odometer-auto-theme .odometer-digit .odometer-value.odometer-last-value, .odometer.odometer-theme-minimal .odometer-digit .odometer-value.odometer-last-value {\n position: absolute;\n}\n.odometer.odometer-auto-theme.odometer-animating-up .odometer-ribbon-inner, .odometer.odometer-theme-minimal.odometer-animating-up .odometer-ribbon-inner {\n -webkit-transition: -webkit-transform 2s;\n -moz-transition: -moz-transform 2s;\n -ms-transition: -ms-transform 2s;\n -o-transition: -o-transform 2s;\n transition: transform 2s;\n}\n.odometer.odometer-auto-theme.odometer-animating-up.odometer-animating .odometer-ribbon-inner, .odometer.odometer-theme-minimal.odometer-animating-up.odometer-animating .odometer-ribbon-inner {\n -webkit-transform: translateY(-100%);\n -moz-transform: translateY(-100%);\n -ms-transform: translateY(-100%);\n -o-transform: translateY(-100%);\n transform: translateY(-100%);\n}\n.odometer.odometer-auto-theme.odometer-animating-down .odometer-ribbon-inner, .odometer.odometer-theme-minimal.odometer-animating-down .odometer-ribbon-inner {\n -webkit-transform: translateY(-100%);\n -moz-transform: translateY(-100%);\n -ms-transform: translateY(-100%);\n -o-transform: translateY(-100%);\n transform: translateY(-100%);\n}\n.odometer.odometer-auto-theme.odometer-animating-down.odometer-animating .odometer-ribbon-inner, .odometer.odometer-theme-minimal.odometer-animating-down.odometer-animating .odometer-ribbon-inner {\n -webkit-transition: -webkit-transform 2s;\n -moz-transition: -moz-transform 2s;\n -ms-transition: -ms-transform 2s;\n -o-transition: -o-transform 2s;\n transition: transform 2s;\n -webkit-transform: translateY(0);\n -moz-transform: translateY(0);\n -ms-transform: translateY(0);\n -o-transform: translateY(0);\n transform: translateY(0);\n}\n";
}).call(globalThis);
// Shared helpers for the content script, the toolbar popup and the counter page.
// Plain script (no modules) so it also works as part of the userscript.
var RYTS = (() => {
// Count sources, best first. NextCounts' Unabbreviated Project has the real count for
// channels that connected YouTube Studio; everything else uses Mixerno's estimate.
const MIXERNO = "https://backend.mixerno.space/api/youtube/estv3/";
const NEXTCOUNTS_LIST = "https://api.nextcounts.com/api/youtube/studio/channels";
const NEXTCOUNTS_V2 = "https://api-v2.nextcounts.com/api/youtube/channel/";
const NEXTCOUNTS_REALTIME = (id) => `https://api.nextcounts.com/api/youtube/studio/channel/${encodeURIComponent(id)}/realtime`;
const SOURCES = {
nextcounts: {
name: "NextCounts", exact: true,
tooltip: "Real count from YouTube Studio, shared by the channel through NextCounts' Unabbreviated Project",
},
mixerno: { name: "Mixerno.space", exact: false, tooltip: "Estimated by Mixerno.space" },
};
const API = MIXERNO; // kept for older callers
const SOURCE = SOURCES.mixerno.name;
// Extension storage when running as an extension, localStorage in the userscript.
const ext = globalThis.browser?.storage?.local ? globalThis.browser
: globalThis.chrome?.storage?.local ? globalThis.chrome : null;
const store = {
async get(key, fallback) {
try {
if (ext) return (await ext.storage.local.get(key))[key] ?? fallback;
const raw = localStorage.getItem("ryts:" + key);
return raw ? JSON.parse(raw) : fallback;
} catch {
return fallback;
}
},
async set(key, value) {
try {
if (ext) await ext.storage.local.set({ [key]: value });
else localStorage.setItem("ryts:" + key, JSON.stringify(value));
} catch { /* storage full or blocked: features degrade, counts still show */ }
},
onChange(key, callback) {
ext?.storage?.onChanged?.addListener((changes, area) => {
if (area === "local" && changes[key]) callback(changes[key].newValue);
});
},
};
// ---------- settings ----------
const DEFAULT_SETTINGS = { format: "exact" };
const getSettings = async () => ({ ...DEFAULT_SETTINGS, ...(await store.get("settings", {})) });
const setSettings = async (patch) => store.set("settings", { ...(await getSettings()), ...patch });
const onSettings = (callback) => store.onChange("settings", (s) => callback({ ...DEFAULT_SETTINGS, ...s }));
// ---------- formatting ----------
const exactFormat = new Intl.NumberFormat("en-US");
// One more significant figure than YouTube's three: 452.3M, 1.284M, 34.01K.
const compactFormat = new Intl.NumberFormat("en-US", {
notation: "compact", maximumSignificantDigits: 4, roundingMode: "trunc",
});
const format = (n, mode = "exact") => (mode === "compact" && n >= 1000 ? compactFormat : exactFormat).format(n);
const exact = (n) => exactFormat.format(n);
const time = (t) => new Date(t).toLocaleTimeString([], { hour: "numeric", minute: "2-digit" });
// ---------- counts ----------
const cache = new Map(); // id -> { count, source, at, promise }
const CACHE_MS = 60_000;
const getJSON = (url) => fetch(url).then((r) => (r.ok ? r.json() : Promise.reject(new Error(r.status))));
const toCount = (v) => {
const n = typeof v === "number" ? v : parseInt(v, 10);
return Number.isFinite(n) && n >= 0 ? n : null;
};
// Channels in the Unabbreviated Project. Loaded at most once an hour, so lists of
// channels (search, featured) never send NextCounts one request per channel.
const LIST_MS = 60 * 60_000, LIST_RETRY_MS = 10 * 60_000;
let studio = null; // { ids: Set | null, at }
let studioLoading = null;
async function studioChannels() {
if (studio && Date.now() - studio.at < (studio.ids ? LIST_MS : LIST_RETRY_MS)) return studio.ids;
if (!studioLoading) {
studioLoading = (async () => {
const saved = await store.get("nextcountsStudio", null);
if (saved && Date.now() - saved.at < LIST_MS) return { ids: new Set(saved.ids), at: saved.at };
try {
const body = await getJSON(NEXTCOUNTS_LIST);
const ids = (Array.isArray(body?.data) ? body.data : []).map((c) => c?.id).filter((id) => /^UC[\w-]{22}$/.test(id || ""));
if (!ids.length) throw new Error("empty list");
await store.set("nextcountsStudio", { ids, at: Date.now() });
return { ids: new Set(ids), at: Date.now() };
} catch {
return { ids: null, at: Date.now() }; // unknown: try again in 10 minutes
}
})().finally(() => { studioLoading = null; });
}
studio = await studioLoading;
return studio.ids;
}
// The verified Studio count, or null when the channel isn't in the project.
async function nextcountsCount(id) {
try {
const v2 = await getJSON(NEXTCOUNTS_V2 + encodeURIComponent(id));
if (v2?.verifiedSubCount === false) return null;
if (v2?.verifiedSubCount === true && toCount(v2.subcount) !== null) return toCount(v2.subcount);
} catch { /* fall through to the older endpoint */ }
try {
const old = await getJSON(NEXTCOUNTS_REALTIME(id));
return old?.success === true ? toCount(old.data?.subscribers) : null;
} catch {
return null;
}
}
async function mixernoCount(id) {
try {
return toCount((await getJSON(MIXERNO + encodeURIComponent(id)))?.items?.[0]?.statistics?.subscriberCount);
} catch {
return null;
}
}
// `bulk` marks lookups for lists of channels: those only ask NextCounts when the
// participant list confirms the channel is in the project.
async function lookup(id, bulk) {
const ids = await studioChannels();
if (ids ? ids.has(id) : !bulk) {
const count = await nextcountsCount(id);
if (count !== null) return { count, source: "nextcounts" };
}
const count = await mixernoCount(id);
return count === null ? null : { count, source: "mixerno" };
}
async function fetchCount(id, { fresh = false, bulk = false } = {}) {
const hit = cache.get(id);
if (hit?.promise) return hit.promise;
if (!fresh && hit?.at && Date.now() - hit.at < CACHE_MS) return hit.count;
const promise = lookup(id, bulk).then((result) => {
if (result) cache.set(id, { ...result, at: Date.now() });
else cache.delete(id);
return result?.count ?? null;
});
cache.set(id, { ...hit, promise });
return promise;
}
// Which source the latest count for `id` came from: SOURCES.nextcounts or SOURCES.mixerno.
const sourceOf = (id) => SOURCES[cache.get(id)?.source] || SOURCES.mixerno;
const updatedAt = (id) => cache.get(id)?.at ?? Date.now();
// ---------- history (local only; powers growth, projections and the popup) ----------
const MAX_POINTS = 240;
const MIN_GAP_MS = 5 * 60_000;
let historyWrite = Promise.resolve();
function observe(id, count, meta = {}) {
historyWrite = historyWrite.then(async () => {
const history = await store.get("history", {});
const entry = history[id] || { points: [] };
if (meta.name) entry.name = meta.name;
if (meta.handle) entry.handle = meta.handle;
const now = Date.now();
const last = entry.points[entry.points.length - 1];
// Keep one point per five minutes; within that window just update the latest value.
if (last && now - last[0] < MIN_GAP_MS && entry.points.length > 1) entry.points[entry.points.length - 1] = [now, count];
else entry.points.push([now, count]);
entry.points = entry.points.slice(-MAX_POINTS);
entry.seen = now;
history[id] = entry;
await store.set("history", history);
});
return historyWrite;
}
const getHistory = () => store.get("history", {});
// Subscribers per day across the stored points; needs at least 30 minutes of data.
function growthPerDay(points = []) {
if (points.length < 2) return null;
const [t0, c0] = points[0];
const [t1, c1] = points[points.length - 1];
const days = (t1 - t0) / 86_400_000;
return days >= 1 / 48 ? (c1 - c0) / days : null;
}
// Next "round" milestone two significant figures up: 34,010 -> 35,000; 452,318,906 -> 460,000,000.
function nextMilestone(n) {
const step = 10 ** Math.max(2, String(Math.floor(n)).length - 2);
return (Math.floor(n / step) + 1) * step;
}
// ---------- digit roll (HubSpot's Odometer, bundled as odometer.js) ----------
// Renders `text` into `el` with the leading number as an Odometer, so a new count rolls
// from the old one. The rest of the text ("subscribers", "M") stays plain. A visually
// hidden copy is what screen readers read and what gets copied.
const canRoll = () => typeof Odometer === "function";
const ODO_CSS = `
.ryts-roll { white-space: pre; font-variant-numeric: tabular-nums; }
.ryts-roll .odometer.odometer-auto-theme { vertical-align: top; line-height: inherit; }
.ryts-roll .odometer .odometer-digit { vertical-align: top; }
.ryts-sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
@media (prefers-reduced-motion: reduce) { .ryts-roll .odometer .odometer-ribbon-inner { transition: none !important; } }`;
// Odometer's theme plus the rules above, added once to the document `el` belongs to.
function rollStyles(doc) {
if (doc.__rytsOdometerCss) return;
doc.__rytsOdometerCss = true;
const style = doc.createElement("style");
style.textContent = Odometer.themeCSS + ODO_CSS;
(doc.head || doc.documentElement).append(style);
}
const NUMBER = /^(\d{1,3}(?:,\d{3})*)([^]*)$/; // "452,318,906 subscribers", "452.3M subscribers"
const reduceMotion = () => typeof matchMedia === "function" && matchMedia("(prefers-reduced-motion: reduce)").matches;
function roll(el, text, prevText = "", animate = false) {
const m = text.match(NUMBER);
if (!m) return void (el.textContent = text);
rollStyles(el.ownerDocument);
const value = +m[1].replaceAll(",", "");
let wrap = el.querySelector(":scope > .ryts-roll");
const od = wrap?.__odometer;
if (od && animate && !reduceMotion()) {
od.update(value);
wrap.lastChild.data = m[2];
} else {
wrap = document.createElement("span");
wrap.className = "ryts-roll";
wrap.setAttribute("aria-hidden", "true");
const odo = document.createElement("span");
wrap.append(odo, m[2]);
wrap.__odometer = new Odometer({ el: odo, value, format: "(,ddd)" });
const sr = document.createElement("span");
sr.className = "ryts-sr";
el.replaceChildren(wrap, sr);
}
el.querySelector(":scope > .ryts-sr").textContent = text;
}
// ---------- extension pages ----------
const pageUrl = (page, params) => {
const getURL = (globalThis.browser || globalThis.chrome)?.runtime?.getURL;
if (!getURL || !ext) return null; // userscript: no extension pages
return getURL(page) + "?" + new URLSearchParams(params);
};
return {
API, SOURCE, SOURCES, store, getSettings, setSettings, onSettings,
format, exact, time, canRoll, roll, fetchCount, sourceOf, updatedAt, observe, getHistory, growthPerDay, nextMilestone, pageUrl,
};
})();
// Return YouTube Subscribers content script. Needs shared.js loaded first.
(() => {
const R = RYTS;
const SEL = {
owner: "#owner-sub-count",
header: "#page-header > yt-page-header-renderer > yt-page-header-view-model > div > div.ytPageHeaderViewModelHeadline > div > yt-content-metadata-view-model > div:nth-child(3) > span:nth-child(1)",
headerRoot: "#page-header",
about: "#additional-info-container > table > tbody > tr:nth-child(6) > td:nth-child(2)",
channelRenderer: "ytd-channel-renderer",
};
const ROUNDED = /^\s*[\d.,]+\s*[KMB]?\s+subscribers?\s*$/i;
const CHANNEL_HREF = /\/(?:channel\/(UC[\w-]{22})|(@[^/?#]+))/;
const LIVE_REFRESH_MS = 10_000;
const log = (...a) => console.log("[RYTS]", ...a);
let settings = { format: "exact" };
let page = null; // { url, id, name, handle, count, live }
const states = new Map(); // element -> { id, count, rounded, at, roll, live, prevText }
// ---------- styles (YouTube's own colour variables, so light/dark/ambient all match) ----------
const style = document.createElement("style");
style.textContent = `
.ryts-live::before { content: ""; display: inline-block; width: .5em; height: .5em; margin-right: .4em; border-radius: 50%;
background: #ff0033; vertical-align: .1em; animation: ryts-pulse 1.6s ease-in-out infinite; }
@keyframes ryts-pulse { 50% { opacity: .35; } }
.ryts-open { display: inline-flex; align-items: center; justify-content: center; width: 24px; height: 24px; margin-left: 6px;
border-radius: 50%; vertical-align: middle; color: var(--yt-spec-text-secondary, #606060); text-decoration: none; }
.ryts-open:hover { background: var(--yt-spec-10-percent-layer, rgba(0, 0, 0, .1)); color: var(--yt-spec-text-primary, #0f0f0f); }
.ryts-open svg { width: 16px; height: 16px; fill: currentColor; }
.ryts-chip { font: 500 14px/36px Roboto, Arial, sans-serif; height: 36px; padding: 0 16px; border: 0; border-radius: 18px;
cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; gap: 8px;
color: var(--yt-spec-text-primary, #0f0f0f); background: var(--yt-spec-badge-chip-background, rgba(0, 0, 0, .05)); }
.ryts-chip:hover { background: var(--yt-spec-button-chip-background-hover, rgba(0, 0, 0, .1)); }
.ryts-chip[aria-pressed="true"] { color: var(--yt-spec-text-primary-inverse, #fff); background: var(--yt-spec-text-primary, #0f0f0f); }
.ryts-chip:focus-visible, .ryts-open:focus-visible { outline: 2px solid var(--yt-spec-call-to-action, #065fd4); outline-offset: 2px; }
.ryts-bar { display: flex; align-items: center; gap: 12px; margin: 12px 0 4px; font: 400 12px/18px Roboto, Arial, sans-serif;
color: var(--yt-spec-text-secondary, #606060); }
.ryts-panel { display: flex; flex-wrap: wrap; align-items: center; gap: 12px 32px; margin: 16px 0 8px; padding: 16px 20px;
border-radius: 12px; font: 400 14px/20px Roboto, Arial, sans-serif; color: var(--yt-spec-text-secondary, #606060);
background: var(--yt-spec-badge-chip-background, rgba(0, 0, 0, .05)); }
.ryts-panel b { display: block; font-size: 16px; line-height: 22px; font-weight: 500; color: var(--yt-spec-text-primary, #0f0f0f); }
.ryts-panel strong { display: block; font-size: 20px; line-height: 28px; font-weight: 700; color: var(--yt-spec-text-primary, #0f0f0f); }
.ryts-panel .ryts-chip:first-of-type { margin-left: auto; }
.ryts-tip { position: fixed; z-index: 9999; max-width: 280px; padding: 8px 10px; border-radius: 4px; pointer-events: none;
font: 400 12px/16px Roboto, Arial, sans-serif; color: #fff; background: rgba(97, 97, 97, .95); }
@media (prefers-reduced-motion: reduce) { .ryts-live::before { animation: none; } }
`;