Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function processNode(node) {
- const channelName = node
- .closest('ytd-thumbnail')
- ?.parentElement?.querySelector('.ytd-channel-name')
- ?.querySelector('yt-formatted-string');
- if (channelName?.textContent) node.textContent = channelName?.textContent;
- }
- async function replaceCurrentThumbnailTimes() {
- for (const node of document.querySelectorAll(
- 'span.ytd-thumbnail-overlay-time-status-renderer',
- )) {
- processNode(node);
- }
- }
- void replaceCurrentThumbnailTimes();
- async function replaceFutureThumbnailTimes() {
- const observer = new MutationObserver((mutations) => {
- // For each new node added, check if it's a video thumbnail time
- for (const mutation of mutations) {
- for (const node of mutation.addedNodes) {
- if (
- node instanceof HTMLElement &&
- node.classList.contains(
- 'ytd-thumbnail-overlay-time-status-renderer',
- ) &&
- node.getAttribute('id') === 'text'
- ) {
- processNode(node);
- }
- }
- }
- });
- observer.observe(document.body, {
- childList: true,
- subtree: true,
- characterData: true,
- attributes: true,
- });
- }
- void replaceFutureThumbnailTimes();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement