Youtube removes clickbait from thumbnails

Removes clickbait from thumbnails changing to start/middle/end thumb of video

  1. // ==UserScript==
  2. // @name Youtube removes clickbait from thumbnails
  3. // @namespace https://greasyfork.org/users/821661
  4. // @match https://www.youtube.com/*
  5. // @grant GM_registerMenuCommand
  6. // @grant GM_setValue
  7. // @grant GM_getValue
  8. // @version 0.2
  9. // @author hdyzen
  10. // @description Removes clickbait from thumbnails changing to start/middle/end thumb of video
  11. // @license MIT
  12. // ==/UserScript==
  13. 'use strict';
  14.  
  15. const optionsMenu = {
  16. start: 'hq1',
  17. middle: 'hq2',
  18. end: 'hq3',
  19. default: 'hqdefault',
  20. };
  21.  
  22. let optionSelected = GM_getValue('optionSelected', optionsMenu['start']);
  23.  
  24. const regexThumbName = /(?<=\/)hq.*(?=\.)/;
  25.  
  26. function createMenu() {
  27. Object.keys(optionsMenu).forEach(id => {
  28. let optionAtual = optionsMenu[id];
  29. GM_registerMenuCommand(
  30. `${optionAtual === optionSelected ? '[⬤]' : '[◯]'} Use thumbnail from ${id}`,
  31. e => {
  32. GM_setValue('optionSelected', optionAtual);
  33. optionSelected = optionAtual;
  34. createMenu();
  35. changeThumbsAfter();
  36. },
  37. { autoClose: false, id: optionAtual },
  38. );
  39. });
  40. }
  41.  
  42. function changeThumbsAfter() {
  43. const thumbs = document.querySelectorAll('a#thumbnail > .ytd-thumbnail > img[src]');
  44. thumbs.forEach(thumb => {
  45. thumb.src = thumb.src.replace(regexThumbName, optionSelected);
  46. });
  47. }
  48.  
  49. function changeThumbsOnInit() {
  50. document.addEventListener('image-loaded', e => {
  51. if (!e.target.src.includes(`${optionSelected}.`)) {
  52. e.target.src = e.target.src.replace(regexThumbName, optionSelected);
  53. }
  54. });
  55. }
  56.  
  57. createMenu();
  58. changeThumbsOnInit();