如何通过Google Chrome控制台调用JS脚本移除Reddit的Try the Redesign按钮?
Hey there! Let's get that annoying "Try the Redesign" banner off your Reddit for good, whether you want a one-click fix or something that works automatically—both will replicate the exact effect as running code in the console.
One-Click Quick Fix (Bookmarklet)
This lets you dismiss the banner with a single click whenever it pops up, no need to open the console every time:
- Right-click your browser's bookmarks bar and select Add Page (or Add Bookmark).
- For the name, use something like Dismiss Reddit Redesign Banner.
- For the URL, paste this code:
javascript:(function(){ // Try clicking the dismiss button first (matches the console function's effect) const dismissBtn = document.querySelector('[data-event-action="r2banner_dismiss"]'); if (dismissBtn) { dismissBtn.click(); } else { // Fallback: Hide the banner entirely if the button isn't found const banner = document.getElementById('redesignbanner'); if (banner) banner.style.display = 'none'; } })(); - Save the bookmark. Now whenever you see the banner, just click this bookmark and it'll be gone instantly.
Permanent Auto-Fix (User Script)
If you want the banner to disappear automatically every time you load Reddit, use a user script manager like Tampermonkey (Chrome/Firefox):
- Install Tampermonkey if you haven't already.
- Click the Tampermonkey icon and select Create a new script.
- Replace the default code with this:
// ==UserScript== // @name Auto-Remove Reddit Redesign Banner // @namespace Tampermonkey Scripts // @version 0.1 // @description Automatically gets rid of Reddit's "Try the Redesign" banner on page load // @match *://*.reddit.com/* // @grant none // ==/UserScript== (function() { 'use strict'; // Check for the banner every half second until it loads const bannerChecker = setInterval(() => { const dismissBtn = document.querySelector('[data-event-action="r2banner_dismiss"]'); const banner = document.getElementById('redesignbanner'); if (dismissBtn) { dismissBtn.click(); // Replicates the console function's click action clearInterval(bannerChecker); } else if (banner) { banner.style.display = 'none'; // Fallback if button isn't accessible clearInterval(bannerChecker); } }, 500); })(); - Save the script (Ctrl+S or Cmd+S). From now on, Reddit will load without that banner ever appearing.
Note About the Console Function You Found
The f() function you spotted (function f() { a("redesignbanner", "click", "r2banner_dismiss") }) is tied to the banner's dismiss action, but it's probably wrapped in a closure (meaning you can't call it directly from outside the site's script). That's why using DOM selection to click the button or hide the banner is more reliable—it doesn't depend on accessing internal site functions.
内容的提问来源于stack exchange,提问作者jepjep40

