Skip to content

Instantly share code, notes, and snippets.

@Osmose
Last active December 22, 2023 18:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Osmose/eecbfdcfa534489c3a6f4b7ac97c7e25 to your computer and use it in GitHub Desktop.
Save Osmose/eecbfdcfa534489c3a6f4b7ac97c7e25 to your computer and use it in GitHub Desktop.
A Tampermonkey script that makes Youtube metrics healthier
// ==UserScript==
// @name Youtube Severals
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Replace like and subscribe and comment counts with severals
// @author Osmose
// @updateUrl https://gist.github.com/Osmose/eecbfdcfa534489c3a6f4b7ac97c7e25/raw/youtube_severals.user.js
// @downloadUrl https://gist.github.com/Osmose/eecbfdcfa534489c3a6f4b7ac97c7e25/raw/youtube_severals.user.js
// @match https://www.youtube.com/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=youtube.com
// @grant none
// @run-at document-end
// @noframes
// ==/UserScript==
(function() {
'use strict';
function replaceXpath(tagName, text, replacement) {
const result = document.evaluate(`//${tagName}[contains(text(), "${text}")]`, document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
for (let k = 0; k < result.snapshotLength; k++) {
const node = result.snapshotItem(k);
node.textContent = replacement;
}
}
function replaceSelectorText(selector, newText) {
for (const node of document.querySelectorAll(selector)) {
node.textContent = newText;
}
}
function replaceSelectorHTML(selector, newHTML) {
for (const node of document.querySelectorAll(selector)) {
node.innerHTML = newHTML;
}
}
function applySeverals() {
replaceXpath('span', 'views', 'several views ');
replaceXpath('span', 'replies', 'several replies');
replaceXpath('span', 'watching', 'several watching');
replaceSelectorText('#owner-sub-count', 'several subscribers');
document.querySelector('ytd-watch-info-text')?.setAttribute('view-count-props', '{"numberText":" ","heightPx":20,"shouldAnimate":false}')
replaceSelectorText('#comments #count .count-text', 'Several Comments');
replaceSelectorText('like-button-view-model .yt-spec-button-shape-next__button-text-content', 'several');
replaceSelectorText('#vote-count-middle', 'several');
}
window.setTimeout(applySeverals, 500);
window.setInterval(applySeverals, 5000);
window.history.pushState = new Proxy(window.history.pushState, {
apply: (target, thisArg, argArray) => {
setTimeout(applySeverals, 500);
return target.apply(thisArg, argArray);
},
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment