Youtube Gray-Out

Overlay thumbnails of already watched videos with white layer and view counter. Aims to counteract Youtube's clickbait design.

当前为 2016-08-08 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Youtube Gray-Out
  3. // @namespace http://do20c2oidj11xsy0ujgb2.com
  4. // @version 0.2
  5. // @description Overlay thumbnails of already watched videos with white layer and view counter. Aims to counteract Youtube's clickbait design.
  6. // @author BakaChan777
  7. // @run-at document-end
  8. // @match https://*.youtube.com/*
  9. // @grant GM_getValue
  10. // @grant GM_setValue
  11. // @grant GM_log
  12. // ==/UserScript==
  13.  
  14. (function( A, B, C, D, E, F, X, T ){
  15. 'use strict';
  16.  
  17. A = GM_getValue('YoutubeSeenVideos', {});
  18.  
  19. E = document.createElement('div');
  20. E.style.width = '100%';
  21. E.style.height = '100%';
  22. E.style.position = 'absolute';
  23. E.style.backgroundColor = 'white';
  24. E.style.opacity = 0.8;
  25. E.style.top = '0px';
  26. E.style.lineHeight = '100%';
  27. E.style.fontSize = '50px';
  28. E.style.display = 'flex';
  29. E.style.alignItems = 'center';
  30. E.style.justifyContent = 'center';
  31. E.className = 'yt-gray-out';
  32.  
  33. function check(){
  34. window.location.href==X || evaluate();
  35. fix_thumbnails(); setTimeout(fix_thumbnails,3000);
  36. }
  37.  
  38. function fix_thumbnails(){
  39. D = Object.getOwnPropertyNames(A);
  40.  
  41. C = document.getElementsByTagName('img');
  42.  
  43. for(var x=0; x<C.length; x++){
  44. for(var y=0; y<D.length; y++) if(C[x].src.indexOf(D[y])!=-1){
  45. if(is_fixed(C[x])) break;
  46. F = C[x].parentNode.appendChild(E.cloneNode());
  47. F.innerHTML = A[D[y]]; break;
  48. }
  49. }
  50. }
  51.  
  52. function is_fixed(e){
  53. for(var x=0, y=e.parentNode.children; x<y.length; x++)
  54. if(y[x].className=='yt-gray-out') return true;
  55. return false;
  56. }
  57.  
  58. function is_video_page(){
  59. return window.location.href.indexOf('watch') != -1;
  60. }
  61.  
  62. function update_video_list(){
  63. B=/v=([a-zA-Z0-9-]+)/g.exec(window.location.href)[1];
  64. A[B]===undefined && (A[B]=0); A[B]++;
  65. }
  66.  
  67. function evaluate() {
  68.  
  69. X = window.location.href;
  70.  
  71. is_video_page() && update_video_list();
  72. GM_setValue('YoutubeSeenVideos', A);
  73. }
  74.  
  75. //window.addEventListener("spfdone", check);
  76. //check();
  77.  
  78. T = new MutationObserver(check);
  79. T.observe(document.getElementById('page'),{attributes:false, childList:true, subtree:true}); check();
  80. })();