Reddit Mobile Banner Kill

Removes the banner prompting to open reddit in the mobile app. This script only does anything on mobile browsers that support Tampermonkey

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Reddit Mobile Banner Kill
// @namespace    http://tampermonkey.net/
// @version      0.7
// @description  Removes the banner prompting to open reddit in the mobile app. This script only does anything on mobile browsers that support Tampermonkey
// @author       Zoidy
// @license      MIT
// @match        *://*.reddit.com/*
// @match        *://reddit.com/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=tampermonkey.net
// @require      https://code.jquery.com/jquery-3.4.1.slim.min.js
// @grant        none
// ==/UserScript==

(function() {
    console.log("Reddit mobile app banner kill loaded!");

    //Top button on homepage
    $(".TopNav__useAppButton").hide();
    $("#get-app").hide();
    $("li.TopNav__promoButton").hide();

    var id = setInterval(function() {
        //View in app or continue in browser (version A)
        $("button.XPromoPopupRpl__actionButton:contains('Continue')").click(); //click the continue button. Should hide banner for the rest of the session
        $("div.XPromoPopupRpl").parent().hide();                               //Hide the banner in case clicking continue doesn't work
        $("div.XPromoBottomBar").hide();                                       //hide the other 'open in app' banner
        $("body").removeClass("scroll-disabled");

        //View in app or continue in browser (version B - a different popup appears sometimes)
        try{
            $("#secondary-button",
				$("xpromo-bottom-sheet",
					$("xpromo-app-selector",
						$("shreddit-async-loader",
							$("shreddit-experience-tree.theme-beta")[0].shadowRoot
						)[0].shadowRoot
					)[0].shadowRoot
				)[0].shadowRoot
            ).click();
        }catch(e){}

        //View in app or continue in browser (version B)
        try{
            $("#secondary-button",
				$("xpromo-bottom-sheet",
					$("xpromo-app-selector",
						$("shreddit-async-loader",
							$("shreddit-experience-tree.theme-beta")[0].shadowRoot
						)[0].shadowRoot
					)[0].shadowRoot
				)[0]
             ).click();
        }catch(e){}

        //See Reddit in... (new version C)
        try{
            $('button#secondary-button',
				$('xpromo-app-selector',
					$('shreddit-async-loader[paint-group="xpromo"][bundlename="app_selector"]')[0].shadowRoot
				)[0].shadowRoot
             ).click()
        }catch(e){}

        //Top button on homepage. hide again, they sometimes reappear
        $(".TopNav__useAppButton").hide();
        $("#get-app").hide();

        //Top button on child pages
        $("shreddit-async-loader[bundlename='top_button'][paint-group='xpromo']").hide();

        //"This Page looks better in the app"
        try{
            $("xpromo-bottom-bar",
				$("shreddit-async-loader[bundlename='bottom_bar_xpromo']")[0].shadowRoot
			).hide();
        }catch(e){}

        //"View Reddit in app bottom banner"
        try{
            $("#xpromo-bottom-sheet button").click();
        }catch(e){}
    }, 200);

    //keep the hiding code running for a while since things reappear.
    setTimeout(function(){
        clearInterval(id);
        console.log("Reddit mobile app banner kill ended!");
    },7000);
})();