Grasemonkey - how to add code to a webpage when certain text appears?

Scorpion Ghost

Elite Member
Executive VIP
Jr. VIP
Joined
Mar 22, 2013
Messages
9,145
Reaction score
10,489
I need to add some code to a webpage when a certain text appears on it.

So I load a webpage, and this appears:

Code:
<div id="someid" class="someclass" style=""></div>

I don't want anything to happen. But at some point this appears:

Code:
<div id="someid" class="someclass" style="">Some text here...</div>

When the text appears, I want to Greasemonkey to add this somewhere on the page.

Code:
<div id="idbla">This is text...</div>

I don't care where this appears, it doesn't need to be appended to anything, it doesn't even need to be visible on the page. I just want it to appear somewhere in the HTML of the webpage.

Any help?
 
Well I fixed it. Thank you all for the help :p

Code:
// ==UserScript==
// @name        Nameo
// @include     https://link.o
// @require     http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js
// @grant       GM_addStyle
// ==/UserScript==
/*- The @grant directive is needed to work around a design change
introduced in GM 1.0.   It restores the sandbox.
 */

var intv = setInterval(function() {
    
if (/(containerimg)|(currently)/i.test (document.body.innerHTML) )

{

$("body").append (
   '<a class="classo" href="#">texto</a>'
);
 
}
    
    }, 3000);
 
I'm curious what you are using this for, thanks for the code btw.

This was over a month ago, I don't even remember what I needed this for exactly. Something appears, and when it appears I want GM to add something specific so my automation can click away from the page at that point or close the browser. Something like that, I don't really remember.

Welcome :)
 
Back
Top