There are many easily found examples of removing a single element from a page's DOM.
A good example here is How to use greasemonkey to selectively remove content from a website
I've tried to write scripts that will remove multiple DIVs and only the first is removed;
// ==UserScript==
// @name Clean CreativeMarket
// @namespace Fred
// @include http://creativemarket.com*
// @include https://creativemarket.com*
// @version 1
// @require http://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js
// @require https://gist.github.com/raw/2625891/waitForKeyElements.js
// @grant GM_addStyle
var elem = document.getElementById("site-banner");
elem.parentNode.removeChild(elem);
var elem02 = document.getElementById("navigation-sub");
elem02.parentNode.removeChild(elem02);
...won't work. Only the first div is removed.
The goal is a single userscript which will work on static and AJAX pages (as demonstrated in the stackoverflow post mentioned above), matching DIVs by domain and (id and/or style).
Here is an example of some uBlock Origin filters to illustrate:
couponscorpion.com##.clearfix.single.main-side > .swp_one.scale-.scale-100.swp_other_full_color.swp_individual_full_color.swp_default_full_color.swp_flat_fresh.swp_social_panel
couponscorpion.com##.dark_style.footer-bottom
couponscorpion.com##.left_st_postproduct
couponscorpion.com##.sidebar
couponscorpion.com##ul:nth-of-type(2)
coupontry.com###header
coupontry.com###sidebar
creativemarket.com###communicate
creativemarket.com###fgotw-seller-list
creativemarket.com###products-by
creativemarket.com###similar-recommended
Would someone please show me how to do this?
- edit 01
Yes, I know see how what I typed is confusing. There are 3 questions:
- Remove an element based on its own characteristics (id, style, etc.)
- Remove an element based on its own and its parents characteristics
Conditional execution of portions of the code only on specified URL or portion thereof. For example, removing common code such as 1x1 pixels with reference to farcebook for tracking as opposed to site-specific elements. The goal is a single userscript which is variably applied depending on URL.
@Brock Adams - You've commented on a couple of my posts. I didn't give up trying things, I kept looking for answers then posted as my comprehension increased. Your function looks like it might be the solution BUT, as with almost every other example I've seen on the web, the code snippets show only one removal function and the code I'd created was only removing the first occurrence of multiple removal functions. Those aren't the same situation. Every attempt I made to find examples of multiple removals didn't bring a good example. Was my code syntactically incorrect, grammatically incorrect, subject to concurrence issues, subject to variable scope, etc., etc. etc.? I don't know. That's why I'm asking.