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-04-04 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Google Shut Up!
// @namespace    http://tampermonkey.net/
// @version      0.2.1
// @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");

    //Set your consent!
    //I'm not sure about this, it seems random to me
    var consent = {
        "Old" : "YES+EN.en+V13+BX",
        "Deny All" : "YES+cb.20210328-17-p0.it+F+654",
        "Allow Search Only" : "YES+cb.20210328-17-p0.it+F+709",
        "Allow Youtube History Only" : "YES+cb.20210328-17-p0.it+F+383",
        "Allow Ads Only" : "YES+cb.20210328-17-p0.it+F+503",
        "Allow Search + Youtube History" : "YES+cb.20210328-17-p0.it+F+193",
        "Allow Youtube History + Ads" : "YES+cb.20210328-17-p0.it+F+773",
        "Allow Search + Ads" : "YES+cb.20210328-17-p0.it+F+418",
        "Allow All" : "YES+cb.20210328-17-p0.it+F+175"
    };

    var setConsent = consent["Deny All"];
    
    //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\+/) !== null;
    }

    function siteIsRefreshable(){
        return document.URL.match(/^https\:\/\/(accounts\.(google|youtube)\.[\.a-z]*|www\.google\.[\.a-z]*\/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="+setConsent+"; 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");
            if(document.URL.match(/^https\:\/\/consent\.(?:google|youtube)\.[\.a-z]*\/m\?continue\=([^&]*)/) !== null){
                location.href=decodeURIComponent(document.URL.match(/^https\:\/\/consent\.(?:google|youtube)\.[\.a-z]*\/m\?continue\=([^&]*)/)[1])
            }else{
                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){
        }
        
        //this is new
        try {
            window.ytInitialData.overlay.upsellDialogRenderer.isVisible = false;
            //console.log("Google Shut Up: dismissed login popup");
        } catch (e){
        }
    }

})();