Skip to content

Instantly share code, notes, and snippets.

@rohenaz
Last active October 4, 2023 15:54
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save rohenaz/8b0528add5c03c1788af46cbf97f4089 to your computer and use it in GitHub Desktop.
Save rohenaz/8b0528add5c03c1788af46cbf97f4089 to your computer and use it in GitHub Desktop.
UserScript - Remove Reddit Promoted Post
// ==UserScript==
// @name Reddit Hide Promoted Links (New Design)
// @namespace http://github.com/rohenaz
// @version 0.1
// @description remove promoted posts and advertisements
// @author Satchmo
// @match https://www.reddit.com/*
// @grant none
// ==/UserScript==
(function() {
'use strict';
let els = document.getElementsByClassName('promotedlink')
clean(els)
setInterval(() => {
let adEls = document.querySelectorAll('[data-google-query-id]')
clean(adEls)
}, 2000)
})();
function clean(els) {
if(els) {
let x = els.length
while(x--) {
if (els[x].getAttribute('data-slot')) {
els[x] = els[x].parentElement.parentElement.parentElement
}
els[x].style.display = 'none'
}
}
}
@neoOpus
Copy link

neoOpus commented Dec 19, 2022

rename to .user.js

@Jakesta13
Copy link

Jakesta13 commented Jan 29, 2023

rename to .user.js

Forked this and renamed it myself for simplicity

Edit: Needs a code update it appears. I haven't got any made userscripts to work before so don't think I'll be able to fix it myself as I don't fully understand userscripts enough

@neoOpus
Copy link

neoOpus commented Jan 29, 2023

rename to .user.js

Forked this and renamed it myself for simplicity

Edit: Needs a code update it appears. I haven't got any made userscripts to work before so don't think I'll be able to fix it myself as I don't fully understand userscripts enough

You must install TamperMonkey extension then you are ready to go, after that, you look into your extension if you have this userscript installed (and remove it) now redo the addition from your fork and TM will catch it and everything should work just fine, if it doesn't then try some other userscripts from GreaseMonkey that you can obviously tell if they are active on the webpage… once done and this userscript still doesn't work for you then let me know.

@Jakesta13
Copy link

rename to .user.js

Forked this and renamed it myself for simplicity
Edit: Needs a code update it appears. I haven't got any made userscripts to work before so don't think I'll be able to fix it myself as I don't fully understand userscripts enough

You must install TamperMonkey extension then you are ready to go, after that, you look into your extension if you have this userscript installed (and remove it) now redo the addition from your fork and TM will catch it and everything should work just fine, if it doesn't then try some other userscripts from GreaseMonkey that you can obviously tell if they are active on the webpage… once done and this userscript still doesn't work for you then let me know.

I have tampermonkey.

I found this script to work instead:
https://old.reddit.com/r/javascript/comments/8vmz0k/hide_promoted_posts_on_reddit/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment