diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c0a1a96..157ae26 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -33,7 +33,7 @@ jobs: - name: Generated files are committed run: | - if ! git diff --exit-code -- userscript.js return-youtube-subscribers.user.js store/listings; then + if ! git diff --exit-code -- userscript.js return-youtube-subscribers.user.js assets/odometer.js store/listings; then echo "::error::Generated files are out of date. Run 'npm run build' and commit the result." exit 1 fi diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 529c413..c2901e9 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -52,7 +52,7 @@ jobs: run: npm run lint - name: Generated files are committed - run: git diff --exit-code -- userscript.js return-youtube-subscribers.user.js store/listings + run: git diff --exit-code -- userscript.js return-youtube-subscribers.user.js assets/odometer.js store/listings - name: Smoke test run: npx playwright install --with-deps chromium firefox webkit && npm run test:smoke && npm run test:e2e diff --git a/CHANGELOG.md b/CHANGELOG.md index bf6b874..ec0699b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,13 @@ Release notes for each version. The release workflow copies the section for the tagged version into the GitHub release and the Firefox Add-ons version notes. +## 4.4.1 + +- Fixed: opening a video from a channel page, or switching quickly between videos and channels, could leave YouTube's rounded count under the video. YouTube keeps the previous page hidden in the background, and the extension now only updates the page you're looking at. +- Counts now roll with HubSpot's Odometer, in the extension, the userscript and on the website. +- The userscript no longer also runs inside YouTube's live chat and ad frames. +- Store and website screenshots are now real captures of YouTube with the extension, not mock-ups. + ## 4.4.0 - Real subscriber counts for channels in NextCounts' Unabbreviated Project, which share their count straight from YouTube Studio. Every other channel still shows Mixerno.space's estimate, and so does any channel if NextCounts is unavailable. diff --git a/assets/odometer.js b/assets/odometer.js new file mode 100644 index 0000000..51043f4 --- /dev/null +++ b/assets/odometer.js @@ -0,0 +1,675 @@ +// 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 text only. + function rytsSpans(html) { + var root = document.createDocumentFragment(), cur = root; + String(html).match(/<\/span>||[^<]+/g).forEach(function (tok) { + if (tok === "") 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 = ''; + + RIBBON_HTML = '' + VALUE_HTML + ''; + + DIGIT_HTML = '8' + RIBBON_HTML + ''; + + FORMAT_MARK_HTML = ''; + + 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 : '.', ''); + val = val.replace(/[.,]/g, ''); + val = val.replace('', '.'); + 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); diff --git a/assets/screens/captured.json b/assets/screens/captured.json new file mode 100644 index 0000000..c893e4f --- /dev/null +++ b/assets/screens/captured.json @@ -0,0 +1,22 @@ +{ + "channel": { + "exact": "526,594,749 subscribers", + "tip": "Estimated by Mixerno.space, updated 1:46 PM. YouTube shows 526M subscribers." + }, + "search": [ + "MrBeast 526,594,757 subscribers", + "MrBeast 2 63,255,100 subscribers", + "MrBeast Gaming 62,137,232 subscribers" + ], + "race": "MrBeast leads by 416,720,342 subscribers", + "live": { + "exact": "15,872,783 subscribers", + "tip": "Estimated by Mixerno.space, updated 1:47 PM. YouTube shows 15.8M subscribers. Live: refreshes every 10 seconds." + }, + "rounded": "526M subscribers", + "watch": { + "exact": "526,594,811 subscribers", + "tip": "Estimated by Mixerno.space, updated 1:47 PM. YouTube shows 526M subscribers." + }, + "at": "2026-11-13T19:48:12.345Z" +} diff --git a/assets/screens/screenshot-1-channel.webp b/assets/screens/screenshot-1-channel.webp index 7dfbf48..c1a1241 100644 Binary files a/assets/screens/screenshot-1-channel.webp and b/assets/screens/screenshot-1-channel.webp differ diff --git a/assets/screens/screenshot-2-search.webp b/assets/screens/screenshot-2-search.webp index 9e2550c..1745da6 100644 Binary files a/assets/screens/screenshot-2-search.webp and b/assets/screens/screenshot-2-search.webp differ diff --git a/assets/screens/screenshot-3-race.webp b/assets/screens/screenshot-3-race.webp index 27d612a..67f5ec1 100644 Binary files a/assets/screens/screenshot-3-race.webp and b/assets/screens/screenshot-3-race.webp differ diff --git a/assets/screens/screenshot-4-live.webp b/assets/screens/screenshot-4-live.webp new file mode 100644 index 0000000..a20c2f3 Binary files /dev/null and b/assets/screens/screenshot-4-live.webp differ diff --git a/assets/screens/screenshot-4-your-channel.webp b/assets/screens/screenshot-4-your-channel.webp deleted file mode 100644 index aa7509d..0000000 Binary files a/assets/screens/screenshot-4-your-channel.webp and /dev/null differ diff --git a/assets/screens/screenshot-5-before-after.webp b/assets/screens/screenshot-5-before-after.webp index da1c3bd..3e5b708 100644 Binary files a/assets/screens/screenshot-5-before-after.webp and b/assets/screens/screenshot-5-before-after.webp differ diff --git a/assets/screens/screenshot-6-watch.webp b/assets/screens/screenshot-6-watch.webp index 6f38d03..fff3eb5 100644 Binary files a/assets/screens/screenshot-6-watch.webp and b/assets/screens/screenshot-6-watch.webp differ diff --git a/assets/screens/screenshot-7-popup.webp b/assets/screens/screenshot-7-popup.webp new file mode 100644 index 0000000..5a41797 Binary files /dev/null and b/assets/screens/screenshot-7-popup.webp differ diff --git a/assets/screens/screenshot-7-privacy.webp b/assets/screens/screenshot-7-privacy.webp deleted file mode 100644 index 4454ae8..0000000 Binary files a/assets/screens/screenshot-7-privacy.webp and /dev/null differ diff --git a/docs/RELEASING.md b/docs/RELEASING.md index d2f13ab..2ec8535 100644 --- a/docs/RELEASING.md +++ b/docs/RELEASING.md @@ -156,7 +156,7 @@ This needs Playwright and the Inter font. The outputs are committed, so CI never | --- | --- | | `icon-128.png` | Chrome, Firefox and Opera store icon (96px artwork in a 128px canvas, as Chrome asks) | | `logo-300.png` | Edge extension logo | -| `screenshot-1…5-*.png` (1280x800) | Screenshots on every store, same set and order everywhere | +| `screenshot-1…7-*.png` (1280x800) | Screenshots on every store, same set and order everywhere. Captured from real YouTube with `npm run screenshots`, never drawn | | `promo-small-440x280.png` | Chrome and Edge small promo tile | | `promo-marquee-1400x560.png` | Chrome marquee and Edge large promo tile | | `app-icon-1024.png`, `safari-appicon/` | Mac app icon (the workflow installs it into the Xcode project) | diff --git a/index.html b/index.html index 0e46ee0..8fb8210 100644 --- a/index.html +++ b/index.html @@ -123,15 +123,13 @@ .demo .name { font-size: 1.375rem; font-weight: 700; letter-spacing: -0.01em; } .demo .handle { color: var(--yt-muted); font-size: .9375rem; } .counter { margin-top: 32px; font-weight: 800; letter-spacing: -0.04em; line-height: 1; font-size: clamp(3rem, 7.4vw, 5.25rem); display: flex; white-space: nowrap; } - .counter .digit { display: inline-block; height: 1em; overflow: hidden; } - .counter .reel { display: flex; flex-direction: column; transition: transform 1.1s cubic-bezier(.2, .8, .2, 1); } - .counter .reel span { height: 1em; } + .counter .odometer.odometer-auto-theme, .counter .odometer .odometer-digit { vertical-align: top; } .counter-label { margin-top: 14px; color: var(--yt-muted); display: flex; gap: 10px; align-items: center; flex-wrap: wrap; } .counter-label .was { background: var(--red); color: #fff; font-size: .8125rem; font-weight: 700; padding: 3px 10px; border-radius: 999px; } .counter-label .was s { opacity: .8; } .demo .bar { height: 4px; border-radius: 2px; margin-top: 26px; background: var(--red); transform-origin: left; transform: scaleX(0); transition: transform 1.1s cubic-bezier(.2, .8, .2, 1); } .demo.done .bar { transform: scaleX(1); } - @media (prefers-reduced-motion: reduce) { .counter .reel, .demo .bar { transition: none; } } + @media (prefers-reduced-motion: reduce) { .counter .odometer .odometer-ribbon-inner, .demo .bar { transition: none !important; } } section { padding-block: clamp(56px, 8vw, 104px); } .section-head { display: grid; grid-template-columns: 1fr 1fr; gap: 24px 64px; align-items: end; margin-bottom: 44px; } @@ -222,13 +220,13 @@

See the real subscriber count.

Free and open source. No account, no tracking.

-
+
MrBeast
@MrBeast
- -
subscribersYouTube shows 452M
+ +
subscribersYouTube shows 526M
@@ -240,17 +238,17 @@

Everywhere YouTube rounds, you get the full number.

It keeps working as you click around YouTube, with no reloads and nothing to set up.

- - - - - - + + + + + +
- MrBeast's channel page showing 452,318,906 subscribers where YouTube shows 452M + MrBeast's channel page showing 526,594,749 subscribers where YouTube shows 526M
-

Exact counts in these screenshots are illustrative; the extension shows the live estimate.

+

Real screenshots of YouTube with the extension, captured on 13 November 2026. The counts have grown since.

@@ -327,7 +325,7 @@

Questions

Why did YouTube start rounding? -

In September 2019 YouTube began abbreviating every public subscriber count, on the site and in its API, to three significant figures. A channel showing 452M could have anywhere from 452,000,000 to 452,999,999 subscribers.

+

In September 2019 YouTube began abbreviating every public subscriber count, on the site and in its API, to three significant figures. A channel showing 526M could have anywhere from 526,000,000 to 526,999,999 subscribers.

What data does the extension send? @@ -376,6 +374,7 @@

Comments

+ diff --git a/src/main.js b/src/main.js index 7cecd05..80e73e7 100644 --- a/src/main.js +++ b/src/main.js @@ -22,13 +22,6 @@ const style = document.createElement("style"); style.textContent = ` - .ryts-roll { white-space: pre; font-variant-numeric: tabular-nums; } - .ryts-d, .ryts-t { display: inline-block; vertical-align: top; height: 1lh; } - .ryts-d { overflow: hidden; } - .ryts-reel { display: block; transition: transform .8s cubic-bezier(.2, .8, .2, 1); } - .ryts-reel > span { display: block; height: 1lh; } - .ryts-reel > span::before { content: attr(data-d); } - .ryts-sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; } .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; } } @@ -52,7 +45,7 @@ .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-reel { transition: none; } .ryts-live::before { animation: none; } } + @media (prefers-reduced-motion: reduce) { .ryts-live::before { animation: none; } } `; // Added in start(): at document-start (userscripts) may not exist yet. @@ -197,7 +190,13 @@ page = null; if (!/\/(channel\/|c\/|user\/|watch\?|@)/.test(url)) return; - const target = await waitFor(() => document.querySelector(SEL.header) || document.querySelector(SEL.owner)); + // YouTube keeps the previous page in the DOM, hidden, after in-app navigation, so only + // count elements that are on screen, and only the kind this URL shows: a channel + // header from a channel page visited earlier must not stand in for a video's owner count. + const shown = (sel) => [...document.querySelectorAll(sel)].find((el) => el.getClientRects().length) || null; + const kind = /\/watch\?/.test(url) ? "watch" : /\/live(?:[/?#]|$)/.test(url) ? "live" : "channel"; + const target = await waitFor(() => kind === "channel" ? shown(SEL.header) + : kind === "watch" ? shown(SEL.owner) : shown(SEL.owner) || shown(SEL.header)); if (!target || url !== location.href) return; const isChannel = target.matches(SEL.header); const id = await idForUrl(url); diff --git a/src/manifest.json b/src/manifest.json index 2ac0cc2..1e7aab4 100644 --- a/src/manifest.json +++ b/src/manifest.json @@ -23,7 +23,7 @@ "content_scripts": [ { "matches": ["https://*.youtube.com/*"], - "js": ["shared.js", "main.js"] + "js": ["odometer.js", "shared.js", "main.js"] } ], "permissions": ["storage"], diff --git a/src/pages.css b/src/pages.css index fb81d10..6c89fbf 100644 --- a/src/pages.css +++ b/src/pages.css @@ -20,15 +20,7 @@ button, select { font: inherit; color: inherit; } .btn-quiet:hover { background: transparent; border-color: var(--slate); } select { background: var(--surface); border: 2px solid var(--mist); border-radius: 8px; padding: 6px 8px; min-width: 0; } -/* digit roll (same as the content script) */ -.ryts-roll { white-space: pre; font-variant-numeric: tabular-nums; } -.ryts-d, .ryts-t { display: inline-block; vertical-align: top; height: 1lh; } -.ryts-d { overflow: hidden; } -.ryts-reel { display: block; transition: transform .8s cubic-bezier(.2, .8, .2, 1); } -.ryts-reel > span { display: block; height: 1lh; } -.ryts-reel > span::before { content: attr(data-d); } -.ryts-sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; } -@media (prefers-reduced-motion: reduce) { .ryts-reel { transition: none; } } +/* rolling digits: Odometer, styled from shared.js */ /* ---------- popup ---------- */ .popup { width: 360px; padding: 16px; } diff --git a/src/popup.html b/src/popup.html index e69fcc3..b1ccb0a 100644 --- a/src/popup.html +++ b/src/popup.html @@ -27,11 +27,12 @@

Race two channels

Number format

- - + +

Growth is measured from counts the extension sees while you browse YouTube, and is stored only on this device.

+ diff --git a/src/shared.js b/src/shared.js index d50cc3b..f3512a6 100644 --- a/src/shared.js +++ b/src/shared.js @@ -194,53 +194,51 @@ var RYTS = (() => { return (Math.floor(n / step) + 1) * step; } - // ---------- digit roll ---------- + // ---------- digit roll (HubSpot's Odometer, bundled as odometer.js) ---------- - // Renders `text` into `el` as rolling digits. Digits are drawn by CSS from data - // attributes, so the element's text stays clean; a visually hidden copy is what - // screen readers read and what gets copied. - const canRoll = () => typeof CSS !== "undefined" && CSS.supports("height", "1lh"); + // 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 wrap = document.createElement("span"); - wrap.className = "ryts-roll"; - wrap.setAttribute("aria-hidden", "true"); - const chars = [...text]; - const offset = chars.length - [...prevText].length; // align digits from the right - const moves = []; - let run = null; // consecutive non-digits share one box, aligned like the digits - chars.forEach((ch, i) => { - if (!/\d/.test(ch)) { - if (!run) wrap.append(run = Object.assign(document.createElement("span"), { className: "ryts-t" })); - run.textContent += ch; - return; - } - run = null; - const to = +ch; - const before = [...prevText][i - offset]; - const from = animate && /\d/.test(before || "") ? +before : to; - const box = document.createElement("span"); - box.className = "ryts-d"; - const reel = document.createElement("span"); - reel.className = "ryts-reel"; - for (let d = 0; d < 10; d++) { - const face = document.createElement("span"); - face.dataset.d = d; - reel.append(face); - } - reel.style.transform = `translateY(calc(-1lh * ${from}))`; - box.append(reel); - wrap.append(box); - if (from !== to) moves.push([reel, to]); - }); - const sr = document.createElement("span"); - sr.className = "ryts-sr"; - sr.textContent = text; - el.replaceChildren(wrap, sr); - if (moves.length) { - wrap.getBoundingClientRect(); // commit start positions - requestAnimationFrame(() => moves.forEach(([reel, to]) => { reel.style.transform = `translateY(calc(-1lh * ${to}))`; })); + 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 ---------- diff --git a/store/assets/screenshot-1-channel.png b/store/assets/screenshot-1-channel.png index 7554c0b..6f4546e 100644 Binary files a/store/assets/screenshot-1-channel.png and b/store/assets/screenshot-1-channel.png differ diff --git a/store/assets/screenshot-2-search.png b/store/assets/screenshot-2-search.png index ce6742d..01507f5 100644 Binary files a/store/assets/screenshot-2-search.png and b/store/assets/screenshot-2-search.png differ diff --git a/store/assets/screenshot-3-race.png b/store/assets/screenshot-3-race.png index 0a28354..f09e6c4 100644 Binary files a/store/assets/screenshot-3-race.png and b/store/assets/screenshot-3-race.png differ diff --git a/store/assets/screenshot-4-live.png b/store/assets/screenshot-4-live.png new file mode 100644 index 0000000..918388f Binary files /dev/null and b/store/assets/screenshot-4-live.png differ diff --git a/store/assets/screenshot-4-your-channel.png b/store/assets/screenshot-4-your-channel.png deleted file mode 100644 index 3dab527..0000000 Binary files a/store/assets/screenshot-4-your-channel.png and /dev/null differ diff --git a/store/assets/screenshot-5-before-after.png b/store/assets/screenshot-5-before-after.png index 41d1a2d..1e069e4 100644 Binary files a/store/assets/screenshot-5-before-after.png and b/store/assets/screenshot-5-before-after.png differ diff --git a/store/assets/screenshot-6-watch.png b/store/assets/screenshot-6-watch.png index fdeb561..900249a 100644 Binary files a/store/assets/screenshot-6-watch.png and b/store/assets/screenshot-6-watch.png differ diff --git a/store/assets/screenshot-7-popup.png b/store/assets/screenshot-7-popup.png new file mode 100644 index 0000000..09bfde2 Binary files /dev/null and b/store/assets/screenshot-7-popup.png differ diff --git a/store/assets/screenshot-7-privacy.png b/store/assets/screenshot-7-privacy.png deleted file mode 100644 index 600a25f..0000000 Binary files a/store/assets/screenshot-7-privacy.png and /dev/null differ diff --git a/store/listing.json b/store/listing.json index ebcd788..f9bc343 100644 --- a/store/listing.json +++ b/store/listing.json @@ -20,7 +20,7 @@ "Since September 2019 YouTube has rounded every subscriber count: \"1.2M subscribers\" could mean anything from 1,200,000 to 1,299,999. Return YouTube Subscribers puts the full number back.", "", "WHAT IT DOES", - "• Channel pages: \"452M subscribers\" becomes \"452,318,906 subscribers\"", + "• Channel pages: \"526M subscribers\" becomes \"526,594,749 subscribers\"", "• Watch pages: the exact count appears under the channel name on every video", "• Search results: exact counts on channel results", "• Real counts for creators in NextCounts' Unabbreviated Project, estimates for everyone else", @@ -32,7 +32,7 @@ "• Save a shareable image of any count or race", "• On your own channel: next milestone, subscribers to go and a projected date", "• Toolbar popup ranking the channels you've viewed by how fast they're growing", - "• Choose exact (452,318,906) or compact (452.3M) numbers", + "• Choose exact (526,594,749) or compact (526.5M) numbers", "• Hover any count to see where it came from and when it was updated", "", "HOW IT WORKS", @@ -90,20 +90,20 @@ "caption": "Race any two channels, live" }, { - "file": "screenshot-4-your-channel.png", - "caption": "Your next milestone, with real Studio counts via NextCounts" + "file": "screenshot-4-live.png", + "caption": "On live streams the count refreshes every 10 seconds" }, { "file": "screenshot-5-before-after.png", - "caption": "452M becomes 452,318,906" + "caption": "526M becomes 526,594,749" }, { "file": "screenshot-6-watch.png", "caption": "The full number under every video" }, { - "file": "screenshot-7-privacy.png", - "caption": "Lightweight, open source, no tracking" + "file": "screenshot-7-popup.png", + "caption": "See which channels you visit are growing fastest" } ] } diff --git a/store/listings/amo-metadata.json b/store/listings/amo-metadata.json index b559797..abac5a2 100644 --- a/store/listings/amo-metadata.json +++ b/store/listings/amo-metadata.json @@ -6,7 +6,7 @@ "en-US": "See exact subscriber counts on YouTube again: on channel pages, under videos, and in search results." }, "description": { - "en-US": "Since September 2019 YouTube has rounded every subscriber count: \"1.2M subscribers\" could mean anything from 1,200,000 to 1,299,999. Return YouTube Subscribers puts the full number back.\n\nWHAT IT DOES\n• Channel pages: \"452M subscribers\" becomes \"452,318,906 subscribers\"\n• Watch pages: the exact count appears under the channel name on every video\n• Search results: exact counts on channel results\n• Real counts for creators in NextCounts' Unabbreviated Project, estimates for everyone else\n• Keeps working as you browse; no page reloads needed\n• Sort channel search results by exact subscriber count\n• Exact counts on featured channels and channel lists\n• Live streams: the count refreshes every 10 seconds, with rolling digits\n• Full-screen live counter, and race mode to watch two channels side by side\n• Save a shareable image of any count or race\n• On your own channel: next milestone, subscribers to go and a projected date\n• Toolbar popup ranking the channels you've viewed by how fast they're growing\n• Choose exact (452,318,906) or compact (452.3M) numbers\n• Hover any count to see where it came from and when it was updated\n\nHOW IT WORKS\nYouTube no longer publishes exact counts. The extension reads the ID of the channel you are viewing. If the channel is in NextCounts' Unabbreviated Project, you see its real count from YouTube Studio. Otherwise you see a live estimate from Mixerno.space, which can differ slightly from YouTube's internal figure. Hover a count to see which one it is.\n\nPRIVACY\n• No account, no sign-in, nothing to configure\n• No analytics, ads or tracking inside the extension\n• Growth history stays on your device\n• The only data sent anywhere is the public ID of the channel you are viewing, to NextCounts or Mixerno.space, to look up its count\n• Open source on GitHub\n\nLINKS\nWebsite: https://ryts.mgcounts.com\nSource code: https://github.com/returnyoutubesubscribers/returnyoutubesubscribers.github.io\nDiscord: https://discord.gg/RRwzccVWfD\n\nReturn YouTube Subscribers is an independent project and is not affiliated with YouTube or Google." + "en-US": "Since September 2019 YouTube has rounded every subscriber count: \"1.2M subscribers\" could mean anything from 1,200,000 to 1,299,999. Return YouTube Subscribers puts the full number back.\n\nWHAT IT DOES\n• Channel pages: \"526M subscribers\" becomes \"526,594,749 subscribers\"\n• Watch pages: the exact count appears under the channel name on every video\n• Search results: exact counts on channel results\n• Real counts for creators in NextCounts' Unabbreviated Project, estimates for everyone else\n• Keeps working as you browse; no page reloads needed\n• Sort channel search results by exact subscriber count\n• Exact counts on featured channels and channel lists\n• Live streams: the count refreshes every 10 seconds, with rolling digits\n• Full-screen live counter, and race mode to watch two channels side by side\n• Save a shareable image of any count or race\n• On your own channel: next milestone, subscribers to go and a projected date\n• Toolbar popup ranking the channels you've viewed by how fast they're growing\n• Choose exact (526,594,749) or compact (526.5M) numbers\n• Hover any count to see where it came from and when it was updated\n\nHOW IT WORKS\nYouTube no longer publishes exact counts. The extension reads the ID of the channel you are viewing. If the channel is in NextCounts' Unabbreviated Project, you see its real count from YouTube Studio. Otherwise you see a live estimate from Mixerno.space, which can differ slightly from YouTube's internal figure. Hover a count to see which one it is.\n\nPRIVACY\n• No account, no sign-in, nothing to configure\n• No analytics, ads or tracking inside the extension\n• Growth history stays on your device\n• The only data sent anywhere is the public ID of the channel you are viewing, to NextCounts or Mixerno.space, to look up its count\n• Open source on GitHub\n\nLINKS\nWebsite: https://ryts.mgcounts.com\nSource code: https://github.com/returnyoutubesubscribers/returnyoutubesubscribers.github.io\nDiscord: https://discord.gg/RRwzccVWfD\n\nReturn YouTube Subscribers is an independent project and is not affiliated with YouTube or Google." }, "homepage": { "en-US": "https://ryts.mgcounts.com" diff --git a/store/listings/chrome-web-store.md b/store/listings/chrome-web-store.md index 75b15c0..950a0bf 100644 --- a/store/listings/chrome-web-store.md +++ b/store/listings/chrome-web-store.md @@ -1,7 +1,7 @@ # Chrome Web Store listing -Version 4.4.0. Paste each field into the dashboard as-is. +Version 4.4.1. Paste each field into the dashboard as-is. ## Name (26/75) @@ -21,7 +21,7 @@ See exact subscriber counts on YouTube again: on channel pages, under videos, an Since September 2019 YouTube has rounded every subscriber count: "1.2M subscribers" could mean anything from 1,200,000 to 1,299,999. Return YouTube Subscribers puts the full number back. WHAT IT DOES -• Channel pages: "452M subscribers" becomes "452,318,906 subscribers" +• Channel pages: "526M subscribers" becomes "526,594,749 subscribers" • Watch pages: the exact count appears under the channel name on every video • Search results: exact counts on channel results • Real counts for creators in NextCounts' Unabbreviated Project, estimates for everyone else @@ -33,7 +33,7 @@ WHAT IT DOES • Save a shareable image of any count or race • On your own channel: next milestone, subscribers to go and a projected date • Toolbar popup ranking the channels you've viewed by how fast they're growing -• Choose exact (452,318,906) or compact (452.3M) numbers +• Choose exact (526,594,749) or compact (526.5M) numbers • Hover any count to see where it came from and when it was updated HOW IT WORKS @@ -72,10 +72,10 @@ Screenshots, in order: 1. `store/assets/screenshot-1-channel.png`: Exact subscriber counts on every channel page 2. `store/assets/screenshot-2-search.png`: Exact counts in search results, sortable by subscribers 3. `store/assets/screenshot-3-race.png`: Race any two channels, live -4. `store/assets/screenshot-4-your-channel.png`: Your next milestone, with real Studio counts via NextCounts -5. `store/assets/screenshot-5-before-after.png`: 452M becomes 452,318,906 +4. `store/assets/screenshot-4-live.png`: On live streams the count refreshes every 10 seconds +5. `store/assets/screenshot-5-before-after.png`: 526M becomes 526,594,749 6. `store/assets/screenshot-6-watch.png`: The full number under every video -7. `store/assets/screenshot-7-privacy.png`: Lightweight, open source, no tracking +7. `store/assets/screenshot-7-popup.png`: See which channels you visit are growing fastest ## Privacy practices tab diff --git a/store/listings/edge-add-ons.md b/store/listings/edge-add-ons.md index 403843c..e5e3bfe 100644 --- a/store/listings/edge-add-ons.md +++ b/store/listings/edge-add-ons.md @@ -1,7 +1,7 @@ # Microsoft Edge Add-ons listing -Version 4.4.0. Paste each field into the dashboard as-is. +Version 4.4.1. Paste each field into the dashboard as-is. ## Name (26/45) @@ -21,7 +21,7 @@ See exact subscriber counts on YouTube again: on channel pages, under videos, an Since September 2019 YouTube has rounded every subscriber count: "1.2M subscribers" could mean anything from 1,200,000 to 1,299,999. Return YouTube Subscribers puts the full number back. WHAT IT DOES -• Channel pages: "452M subscribers" becomes "452,318,906 subscribers" +• Channel pages: "526M subscribers" becomes "526,594,749 subscribers" • Watch pages: the exact count appears under the channel name on every video • Search results: exact counts on channel results • Real counts for creators in NextCounts' Unabbreviated Project, estimates for everyone else @@ -33,7 +33,7 @@ WHAT IT DOES • Save a shareable image of any count or race • On your own channel: next milestone, subscribers to go and a projected date • Toolbar popup ranking the channels you've viewed by how fast they're growing -• Choose exact (452,318,906) or compact (452.3M) numbers +• Choose exact (526,594,749) or compact (526.5M) numbers • Hover any count to see where it came from and when it was updated HOW IT WORKS @@ -78,10 +78,10 @@ Screenshots, in order: 1. `store/assets/screenshot-1-channel.png`: Exact subscriber counts on every channel page 2. `store/assets/screenshot-2-search.png`: Exact counts in search results, sortable by subscribers 3. `store/assets/screenshot-3-race.png`: Race any two channels, live -4. `store/assets/screenshot-4-your-channel.png`: Your next milestone, with real Studio counts via NextCounts -5. `store/assets/screenshot-5-before-after.png`: 452M becomes 452,318,906 +4. `store/assets/screenshot-4-live.png`: On live streams the count refreshes every 10 seconds +5. `store/assets/screenshot-5-before-after.png`: 526M becomes 526,594,749 6. `store/assets/screenshot-6-watch.png`: The full number under every video -7. `store/assets/screenshot-7-privacy.png`: Lightweight, open source, no tracking +7. `store/assets/screenshot-7-popup.png`: See which channels you visit are growing fastest ## Notes for certification diff --git a/store/listings/firefox-amo.md b/store/listings/firefox-amo.md index ce06e03..4a246c1 100644 --- a/store/listings/firefox-amo.md +++ b/store/listings/firefox-amo.md @@ -1,7 +1,7 @@ # Firefox Add-ons (AMO) listing -Version 4.4.0. Paste each field into the dashboard as-is. +Version 4.4.1. Paste each field into the dashboard as-is. Name, summary, description, homepage, support URL and category are pushed automatically by the release workflow (`store/listings/amo-metadata.json`). Upload images by hand. @@ -23,7 +23,7 @@ See exact subscriber counts on YouTube again: on channel pages, under videos, an Since September 2019 YouTube has rounded every subscriber count: "1.2M subscribers" could mean anything from 1,200,000 to 1,299,999. Return YouTube Subscribers puts the full number back. WHAT IT DOES -• Channel pages: "452M subscribers" becomes "452,318,906 subscribers" +• Channel pages: "526M subscribers" becomes "526,594,749 subscribers" • Watch pages: the exact count appears under the channel name on every video • Search results: exact counts on channel results • Real counts for creators in NextCounts' Unabbreviated Project, estimates for everyone else @@ -35,7 +35,7 @@ WHAT IT DOES • Save a shareable image of any count or race • On your own channel: next milestone, subscribers to go and a projected date • Toolbar popup ranking the channels you've viewed by how fast they're growing -• Choose exact (452,318,906) or compact (452.3M) numbers +• Choose exact (526,594,749) or compact (526.5M) numbers • Hover any count to see where it came from and when it was updated HOW IT WORKS @@ -72,10 +72,10 @@ Screenshots, in order: 1. `store/assets/screenshot-1-channel.png`: Exact subscriber counts on every channel page 2. `store/assets/screenshot-2-search.png`: Exact counts in search results, sortable by subscribers 3. `store/assets/screenshot-3-race.png`: Race any two channels, live -4. `store/assets/screenshot-4-your-channel.png`: Your next milestone, with real Studio counts via NextCounts -5. `store/assets/screenshot-5-before-after.png`: 452M becomes 452,318,906 +4. `store/assets/screenshot-4-live.png`: On live streams the count refreshes every 10 seconds +5. `store/assets/screenshot-5-before-after.png`: 526M becomes 526,594,749 6. `store/assets/screenshot-6-watch.png`: The full number under every video -7. `store/assets/screenshot-7-privacy.png`: Lightweight, open source, no tracking +7. `store/assets/screenshot-7-popup.png`: See which channels you visit are growing fastest ## Notes to reviewer diff --git a/store/listings/opera-add-ons.md b/store/listings/opera-add-ons.md index d8657c3..52ac661 100644 --- a/store/listings/opera-add-ons.md +++ b/store/listings/opera-add-ons.md @@ -1,7 +1,7 @@ # Opera Add-ons listing -Version 4.4.0. Paste each field into the dashboard as-is. +Version 4.4.1. Paste each field into the dashboard as-is. Upload `dist/return-youtube-subscribers--chrome.zip`. Opera has no publishing API, so updates are manual. @@ -23,7 +23,7 @@ See exact subscriber counts on YouTube again: on channel pages, under videos, an Since September 2019 YouTube has rounded every subscriber count: "1.2M subscribers" could mean anything from 1,200,000 to 1,299,999. Return YouTube Subscribers puts the full number back. WHAT IT DOES -• Channel pages: "452M subscribers" becomes "452,318,906 subscribers" +• Channel pages: "526M subscribers" becomes "526,594,749 subscribers" • Watch pages: the exact count appears under the channel name on every video • Search results: exact counts on channel results • Real counts for creators in NextCounts' Unabbreviated Project, estimates for everyone else @@ -35,7 +35,7 @@ WHAT IT DOES • Save a shareable image of any count or race • On your own channel: next milestone, subscribers to go and a projected date • Toolbar popup ranking the channels you've viewed by how fast they're growing -• Choose exact (452,318,906) or compact (452.3M) numbers +• Choose exact (526,594,749) or compact (526.5M) numbers • Hover any count to see where it came from and when it was updated HOW IT WORKS @@ -72,10 +72,10 @@ Screenshots, in order: 1. `store/assets/screenshot-1-channel.png`: Exact subscriber counts on every channel page 2. `store/assets/screenshot-2-search.png`: Exact counts in search results, sortable by subscribers 3. `store/assets/screenshot-3-race.png`: Race any two channels, live -4. `store/assets/screenshot-4-your-channel.png`: Your next milestone, with real Studio counts via NextCounts -5. `store/assets/screenshot-5-before-after.png`: 452M becomes 452,318,906 +4. `store/assets/screenshot-4-live.png`: On live streams the count refreshes every 10 seconds +5. `store/assets/screenshot-5-before-after.png`: 526M becomes 526,594,749 6. `store/assets/screenshot-6-watch.png`: The full number under every video -7. `store/assets/screenshot-7-privacy.png`: Lightweight, open source, no tracking +7. `store/assets/screenshot-7-popup.png`: See which channels you visit are growing fastest ## Links diff --git a/store/listings/safari-app-store.md b/store/listings/safari-app-store.md index 699d45c..edc606a 100644 --- a/store/listings/safari-app-store.md +++ b/store/listings/safari-app-store.md @@ -1,7 +1,7 @@ # Safari (Mac App Store) listing -Version 4.4.0. Paste each field into the dashboard as-is. +Version 4.4.1. Paste each field into the dashboard as-is. Builds are uploaded to App Store Connect by `.github/workflows/safari.yml`. Fill these fields in App Store Connect once. @@ -29,7 +29,7 @@ YouTube rounds every subscriber count. Return YouTube Subscribers puts the full Since September 2019 YouTube has rounded every subscriber count: "1.2M subscribers" could mean anything from 1,200,000 to 1,299,999. Return YouTube Subscribers puts the full number back. WHAT IT DOES -• Channel pages: "452M subscribers" becomes "452,318,906 subscribers" +• Channel pages: "526M subscribers" becomes "526,594,749 subscribers" • Watch pages: the exact count appears under the channel name on every video • Search results: exact counts on channel results • Real counts for creators in NextCounts' Unabbreviated Project, estimates for everyone else @@ -41,7 +41,7 @@ WHAT IT DOES • Save a shareable image of any count or race • On your own channel: next milestone, subscribers to go and a projected date • Toolbar popup ranking the channels you've viewed by how fast they're growing -• Choose exact (452,318,906) or compact (452.3M) numbers +• Choose exact (526,594,749) or compact (526.5M) numbers • Hover any count to see where it came from and when it was updated HOW IT WORKS @@ -84,10 +84,10 @@ Screenshots, in order: 1. `store/assets/screenshot-1-channel.png`: Exact subscriber counts on every channel page 2. `store/assets/screenshot-2-search.png`: Exact counts in search results, sortable by subscribers 3. `store/assets/screenshot-3-race.png`: Race any two channels, live -4. `store/assets/screenshot-4-your-channel.png`: Your next milestone, with real Studio counts via NextCounts -5. `store/assets/screenshot-5-before-after.png`: 452M becomes 452,318,906 +4. `store/assets/screenshot-4-live.png`: On live streams the count refreshes every 10 seconds +5. `store/assets/screenshot-5-before-after.png`: 526M becomes 526,594,749 6. `store/assets/screenshot-6-watch.png`: The full number under every video -7. `store/assets/screenshot-7-privacy.png`: Lightweight, open source, no tracking +7. `store/assets/screenshot-7-popup.png`: See which channels you visit are growing fastest ## App Privacy diff --git a/userscript.js b/userscript.js index 3cff7bd..6385ca0 100644 --- a/userscript.js +++ b/userscript.js @@ -1,7 +1,7 @@ // ==UserScript== // @name Return YouTube Subscribers // @namespace ryts.mgcounts.com -// @version 4.4.0 +// @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 @@ -11,9 +11,686 @@ // @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 src/shared.js and src/main.js by scripts/build.mjs. Do not edit by hand. +// 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 text only. + function rytsSpans(html) { + var root = document.createDocumentFragment(), cur = root; + String(html).match(/<\/span>||[^<]+/g).forEach(function (tok) { + if (tok === "") 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 = ''; + + RIBBON_HTML = '' + VALUE_HTML + ''; + + DIGIT_HTML = '8' + RIBBON_HTML + ''; + + FORMAT_MARK_HTML = ''; + + 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 : '.', ''); + val = val.replace(/[.,]/g, ''); + val = val.replace('', '.'); + 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. @@ -211,53 +888,51 @@ var RYTS = (() => { return (Math.floor(n / step) + 1) * step; } - // ---------- digit roll ---------- + // ---------- digit roll (HubSpot's Odometer, bundled as odometer.js) ---------- - // Renders `text` into `el` as rolling digits. Digits are drawn by CSS from data - // attributes, so the element's text stays clean; a visually hidden copy is what - // screen readers read and what gets copied. - const canRoll = () => typeof CSS !== "undefined" && CSS.supports("height", "1lh"); + // 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 wrap = document.createElement("span"); - wrap.className = "ryts-roll"; - wrap.setAttribute("aria-hidden", "true"); - const chars = [...text]; - const offset = chars.length - [...prevText].length; // align digits from the right - const moves = []; - let run = null; // consecutive non-digits share one box, aligned like the digits - chars.forEach((ch, i) => { - if (!/\d/.test(ch)) { - if (!run) wrap.append(run = Object.assign(document.createElement("span"), { className: "ryts-t" })); - run.textContent += ch; - return; - } - run = null; - const to = +ch; - const before = [...prevText][i - offset]; - const from = animate && /\d/.test(before || "") ? +before : to; - const box = document.createElement("span"); - box.className = "ryts-d"; - const reel = document.createElement("span"); - reel.className = "ryts-reel"; - for (let d = 0; d < 10; d++) { - const face = document.createElement("span"); - face.dataset.d = d; - reel.append(face); - } - reel.style.transform = `translateY(calc(-1lh * ${from}))`; - box.append(reel); - wrap.append(box); - if (from !== to) moves.push([reel, to]); - }); - const sr = document.createElement("span"); - sr.className = "ryts-sr"; - sr.textContent = text; - el.replaceChildren(wrap, sr); - if (moves.length) { - wrap.getBoundingClientRect(); // commit start positions - requestAnimationFrame(() => moves.forEach(([reel, to]) => { reel.style.transform = `translateY(calc(-1lh * ${to}))`; })); + 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 ---------- @@ -298,13 +973,6 @@ var RYTS = (() => { const style = document.createElement("style"); style.textContent = ` - .ryts-roll { white-space: pre; font-variant-numeric: tabular-nums; } - .ryts-d, .ryts-t { display: inline-block; vertical-align: top; height: 1lh; } - .ryts-d { overflow: hidden; } - .ryts-reel { display: block; transition: transform .8s cubic-bezier(.2, .8, .2, 1); } - .ryts-reel > span { display: block; height: 1lh; } - .ryts-reel > span::before { content: attr(data-d); } - .ryts-sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; } .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; } } @@ -328,7 +996,7 @@ var RYTS = (() => { .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-reel { transition: none; } .ryts-live::before { animation: none; } } + @media (prefers-reduced-motion: reduce) { .ryts-live::before { animation: none; } } `; // Added in start(): at document-start (userscripts) may not exist yet. @@ -473,7 +1141,13 @@ var RYTS = (() => { page = null; if (!/\/(channel\/|c\/|user\/|watch\?|@)/.test(url)) return; - const target = await waitFor(() => document.querySelector(SEL.header) || document.querySelector(SEL.owner)); + // YouTube keeps the previous page in the DOM, hidden, after in-app navigation, so only + // count elements that are on screen, and only the kind this URL shows: a channel + // header from a channel page visited earlier must not stand in for a video's owner count. + const shown = (sel) => [...document.querySelectorAll(sel)].find((el) => el.getClientRects().length) || null; + const kind = /\/watch\?/.test(url) ? "watch" : /\/live(?:[/?#]|$)/.test(url) ? "live" : "channel"; + const target = await waitFor(() => kind === "channel" ? shown(SEL.header) + : kind === "watch" ? shown(SEL.owner) : shown(SEL.owner) || shown(SEL.header)); if (!target || url !== location.href) return; const isChannel = target.matches(SEL.header); const id = await idForUrl(url);