2

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?

2
  • 2
    you wrote $("div[id$='adblockinfo']").remove it should be $("div[id$='adblockinfo']").remove() Dec 18, 2018 at 19:14
  • Thanks @CarstenLøvboAndersen that worked!
    – ApolloJam
    Dec 19, 2018 at 19:41

1 Answer 1

2

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 ();
}
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.