Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove a div with a changing id via Tampermonkey/Greasemonkey?

I would like to be able to remove a div with an id that changes every time you refresh the page.

The div looks like this:

<div id="8474adblockinfo">
</div>

So there is a regular id called 'adblockinfo' and it always has a set of 4 numbers in the id before 'adblockinfo' (e.g. 1234adblockinfo, 1235adblockinfo). Any idea how I can remove this with a Tampermonkey script?

I've tried code:

$("div[id$='adblockinfo']").remove
$("div[id$='adblockinfo']").css('display', 'none');

Neither seems to work.

I also think that the webpage is inserting the div via AJAX after pageload or something, so that could be an issue? I've tried running the script at: // @run-at document-idle but that didn't do it.

Any tips on this?

like image 570
ApolloJam Avatar asked Nov 18 '25 16:11

ApolloJam


1 Answers

The following will work on both static and AJAX-driven pages:

// ==UserScript==
// @name     _delete Adblock blocking nodes
// @match    *://YOUR_SERVER.COM/YOUR_PATH/*
// @require  https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js
// @require  https://gist.github.com/raw/2625891/waitForKeyElements.js
// @grant    GM_addStyle
// @grant    GM.getValue
// ==/UserScript==
//- The @grant directives are needed to restore the proper sandbox.
/* global $, waitForKeyElements */

waitForKeyElements ("[id$='adblockinfo']", killNode);

function killNode (jNode) {
    jNode.remove ();
}
like image 164
Brock Adams Avatar answered Nov 20 '25 06:11

Brock Adams



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!