Google Shut Up!

Remove annoying cookies popup on google and youtube login popup on youtube! Thanks to him https://github.com/uBlockOrigin/uAssets/issues/7842#issuecomment-694298400

当前为 2021-02-13 提交的版本,查看 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Google Shut Up!
// @namespace    http://tampermonkey.net/
// @version      0.1.9.3
// @description  Remove annoying cookies popup on google and youtube login popup on youtube! Thanks to him https://github.com/uBlockOrigin/uAssets/issues/7842#issuecomment-694298400
// @author       You
// @include      /^https\:\/\/[a-z]*\.(google|youtube)\.[a-z]*/
// @grant        none
// @run-at       document-start
// ==/UserScript==

(function() {
    //console.log("Google Shut Up: Start");

    //https://stackoverflow.com/a/45956628----
    //youtube wtf events
    //new layout > 2017
    window.addEventListener("yt-navigate-finish", function(event) {
        window.dispatchEvent(new Event('locationchange'))
    });

    //old layout < 2017
    window.addEventListener("spfdone", function(e) {
        window.dispatchEvent(new Event('locationchange'))
    });

    window.addEventListener("load",function(){
        dismissLogin();
    },{once:true});

    function cookieIsSet(){
        return document.cookie.match(/CONSENT\=YES\+EN\.en\+V13\+BX/) !== null;
    }

    function siteIsRefreshable(){
        return document.URL.match(/^https\:\/\/(accounts\.(google|youtube)\.com|www\.google\.com\/recaptcha)/i) === null;
    }

    function isYoutube(){
        return document.URL.match(/^https\:\/\/www\.youtube\.com/i) !== null;
    }
    function isEmbedded(){
        return document.URL.match(/\/embed\//i) !== null;
    }
    
    window.addEventListener('locationchange', function(){
        if(!cookieIsSet() && !isEmbedded()){
            cookieInjection();
        }
        dismissLogin();
    });

    //if cookie is unset then inject it
    if(!cookieIsSet() && !isEmbedded()){
        cookieInjection();
    }
    dismissLogin();

    function cookieInjection(){
        //cookie injection
        document.cookie = "CONSENT=YES+EN.en+V13+BX; expires=Fri, 01 Jan 2038 00:00:00 GMT; domain="+document.URL.match(/^https\:\/\/[a-z]*\.((google|youtube)\.[\.a-z]*)/)[1]+"; path =/; Secure";

        //reload on accounts.google.com pages causes infinite loop
        if(siteIsRefreshable()){
            //refresh page to avoid cookie's popup
            //console.log("Google Shut Up: cookie refresh");
            location.reload();
        }
    }

    //Link: https://github.com/uBlockOrigin/uAssets/issues/7842#issuecomment-694298400
    //Source: https://gist.githubusercontent.com/pixeltris/b79707fa8a704e0058c7f1af83d5935a/raw/Yt.js
    //Thanks to this guy!
    function dismissLogin(){
        try {
            window.ytInitialPlayerResponse.auxiliaryUi.messageRenderers.upsellDialogRenderer.isVisible = false;
            //console.log("Google Shut Up: dismissed login popup");
        } catch (e){
        }
    }

})();