Replaces a number in the end of youtube videos duration.
当前为
// ==UserScript==
// @name Youtube OCD number replacer
// @namespace https://www.nexusmods.com/palworld/mods/1134
// @version 2024-03-16
// @description Replaces a number in the end of youtube videos duration.
// @author Deli Almendra
// @match https://www.youtube.com/*
// @icon https://external-content.duckduckgo.com/iu/?u=https%3A%2F%2Fcdn.iconscout.com%2Ficon%2Ffree%2Fpng-256%2Focd-file-913037.png
// @grant none
// @license MIT
// ==/UserScript==
let number_to_replace = '3'
let replace_to = 'B'
function durationEndsWithThreeOrFour(duration) {
const lastChar = duration.slice(-1);
return lastChar === number_to_replace;
}
function updateDurationAttributeAndStyle(element) {
const duration = element.textContent.trim();
if (durationEndsWithThreeOrFour(duration)) {
element.setAttribute('data-duration-ends-with', duration.slice(-1));
const modifiedDuration = duration.slice(0, -1) + replace_to;
element.textContent = modifiedDuration;
} else {
element.removeAttribute('data-duration-ends-with');
}
}
function processDurationElements() {
const durationElements = document.querySelectorAll('.ytp-time-duration, .ytd-thumbnail-overlay-time-status-renderer');
durationElements.forEach(updateDurationAttributeAndStyle);
}
const observer = new MutationObserver(processDurationElements);
observer.observe(document.body, { childList: true, subtree: true });