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 提交的版本,查看 最新版本

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Youtube Gray-Out
// @namespace    http://do20c2oidj11xsy0ujgb2.com
// @version      0.4
// @description  Overlay thumbnails of already watched videos with white layer and view counter. Aims to counteract Youtube's clickbait design.
// @author       BakaChan777
// @run-at       document-end
// @match        https://*.youtube.com/*
// @grant        GM_getValue
// @grant        GM_setValue
// @grant        GM_log
// ==/UserScript==

(function( A, B, C, D, E, F, X, T ){
    'use strict';

    E = document.createElement('div');
    E.style.width = '100%';
    E.style.height = '100%';
    E.style.position = 'absolute';
    E.style.backgroundColor = 'white';
    E.style.opacity = 0.8;
    E.style.top = '0px';
    E.style.lineHeight = '100%';
    E.style.fontSize = '50px';
    E.style.display = 'flex';
    E.style.alignItems = 'center';
    E.style.justifyContent = 'center';
    E.className = 'yt-gray-out';

    function check(){

        A = GM_getValue('YoutubeSeenVideos', {});

        window.location.href==X || evaluate();
        fix_thumbnails(); setTimeout(fix_thumbnails,3000);
    }

    function fix_thumbnails(){
        D = Object.getOwnPropertyNames(A);

        C = document.getElementsByTagName('img');

        for(var x=0; x<C.length; x++){
            for(var y=0; y<D.length; y++) if(C[x].src.indexOf(D[y])!=-1){
                if(is_fixed(C[x])) break;
                F = C[x].parentNode.appendChild(E.cloneNode());
                F.innerHTML = A[D[y]]; break;
            }
        }
    }

    function is_fixed(e){
        for(var x=0, y=e.parentNode.children; x<y.length; x++)
            if(y[x].className=='yt-gray-out') return true;
        return false;
    }

    function is_video_page(){
        return window.location.href.indexOf('watch') != -1;
    }

    function update_video_list(){
        B=/v=([a-zA-Z0-9-_]+)/g.exec(window.location.href)[1];
        A[B]===undefined && (A[B]=0); A[B]++;
    }

    function evaluate() {

        X = window.location.href;

        is_video_page() && update_video_list();
        GM_setValue('YoutubeSeenVideos', A);
    }

    //window.addEventListener("spfdone", check);
    //check();

    T = new MutationObserver(check);
    T.observe(document.getElementById('page'),{attributes:false, childList:true, subtree:true}); check();
})();