0

I'm trying basically, what is done here: Calling a Javascript Function from Console

Just in another way that I can't find out.

At reddit.com I'm trying to remove that Try the Redesign button. If you F12 using Google Chrome while in reddit.com you should be able to see Application, you click that and then go to scripts and search for OptIn using CTRL+F. Then you find the code, I'll just put some part of it in here.

    function f() {
        a("redesignbanner", "click", "r2banner_dismiss")
    }

this

e.actions.on("onboarding:redesignbetabarClose", f),
e.actions.on("onboarding:redesignbetabarClickOptIn", c),

and this

        initBanner: function() {
            var n = $(".redesignbetabar");
            if (!n.length)
                return;
            $("#redesign-beta-optin").on("click", function() {
                e.actions.trigger("onboarding:redesignbetabarClickOptIn"),
                t(function() {
                    e.onboardingBar.setDismissed(n.data(), !0),
                    window.location.reload(!0)
                }, function(t, n, i) {
                    e.warn("Error opting in to redesign", n, ";", i)
                })
            })
        }

Do you see that e.onboardingBar.setDismissed(n.data(), !0)? Basically, I tried to run this too, but I couldn't figure out how.

My point is to remove that button on the top right, which looks like this.

Try the Redesign

If you don't know how to get that button, I'll tried to figure out how and found out how to get it.

You go to the reddit account settings on the top right > scroll down and check, Use the redesign as my default experience > then you click on save

and then you go again to settings or if you are still there, just uncheck it and the button should appear, which is annoying and I can't get rid of it, seems that I didn't had this problem before also others have it but not all and thats weird.

Developer Guy
  • 2,318
  • 6
  • 19
  • 37
jepjep40
  • 181
  • 1
  • 2
  • 12
  • Looks like a method (function inside an object) which you might access via objectname.initBanner() though there maybe more nestings (I didn't check the source). If all is inside $.ready you can forget it (like with a closure). Even if it works you only access a click handler.. that triggers a custom event... in other words this will get you nowhere. You 're better off removing the element with a selector... ie try something similar to `jQuery("#header").remove()` – yezzz May 06 '18 at 19:33
  • I tried to get rid of it permanently but its just temporary, not sure how google chrome cache thing works. – jepjep40 May 07 '18 at 00:22
  • Of course it comes back when you reload the page... only way to get rid of it permanently is if reddit changes their source code – yezzz May 07 '18 at 00:28

1 Answers1

2

Since Reddit wraps almost all of their JavaScript code in anonymous functions, you are unable to access the variables and functions defined within them. For example, see the following code:

(function() {
  var x = 2;
})();

The variable x can not be accessed from anywhere except inside that anonymous function, and since that function has no name, there is no way to refer to it or access anything inside of it.

Reddit does the same thing with their code, meaning you can't call any of those methods. However, there is another way to hide the button using CSS. The button has the class "redesign-beta-optin", so the following CSS will hide the button:

.redesign-beta-optin { display: none }

This can be done with JavaScript like so:

document.getElementsByClassName("redesign-beta-optin")[0].style.display = "none"

EDIT

To get rid of the button permanently, you can use a Chrome extension such as Tampermonkey or Stylish that allows you to run JavaScript and CSS on certain web pages.

To do this with Tampermonkey, create a UserScript with the following contents:

// ==UserScript==
// @name Reddit Redesign Button Remover
// @description  Remove reddit redesign button
// @author       kmh
// @match        https://*.reddit.com/*
// ==/UserScript==

document.getElementsByClassName("redesign-beta-optin")[0].style.display = "none";

With Stylish, you can create a new style for the domain reddit.com with the contents:

.redesign-beta-optin { display: none }

You will notice a small period of time as the site is loading with the button there if you use Tampermonkey, since it takes some time to initialize. This does not happen with Stylish.

kmh
  • 56
  • 4
  • What is the [0] for? – jepjep40 May 07 '18 at 00:21
  • document.getElementsByClassName returns an array of elements because multiple elements can share the same class name. [0] gets the first element of the array, which we know is the element we want since there is only one element with that class. – kmh May 07 '18 at 00:29
  • If you create a new account on reddit it will not show that thing, and not sure how, but maybe if I manipulate the cookies it will make it go away? – jepjep40 Jun 15 '18 at 15:37