Last active
December 22, 2023 18:07
-
-
Save Osmose/eecbfdcfa534489c3a6f4b7ac97c7e25 to your computer and use it in GitHub Desktop.
A Tampermonkey script that makes Youtube metrics healthier
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==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