Advertisement
Guest User

Untitled

a guest
Nov 3rd, 2022
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.38 KB | None | 0 0
  1. function processNode(node) {
  2. const channelName = node
  3. .closest('ytd-thumbnail')
  4. ?.parentElement?.querySelector('.ytd-channel-name')
  5. ?.querySelector('yt-formatted-string');
  6.  
  7. if (channelName?.textContent) node.textContent = channelName?.textContent;
  8. }
  9.  
  10. async function replaceCurrentThumbnailTimes() {
  11. for (const node of document.querySelectorAll(
  12. 'span.ytd-thumbnail-overlay-time-status-renderer',
  13. )) {
  14. processNode(node);
  15. }
  16. }
  17.  
  18. void replaceCurrentThumbnailTimes();
  19.  
  20. async function replaceFutureThumbnailTimes() {
  21. const observer = new MutationObserver((mutations) => {
  22. // For each new node added, check if it's a video thumbnail time
  23. for (const mutation of mutations) {
  24. for (const node of mutation.addedNodes) {
  25. if (
  26. node instanceof HTMLElement &&
  27. node.classList.contains(
  28. 'ytd-thumbnail-overlay-time-status-renderer',
  29. ) &&
  30. node.getAttribute('id') === 'text'
  31. ) {
  32. processNode(node);
  33. }
  34. }
  35. }
  36. });
  37.  
  38. observer.observe(document.body, {
  39. childList: true,
  40. subtree: true,
  41. characterData: true,
  42. attributes: true,
  43. });
  44. }
  45.  
  46. void replaceFutureThumbnailTimes();
  47.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement