Skip to content Skip to sidebar Skip to footer

How To Run Script Only If Div:contains In An Iframe - Greasemonkey

So let's say we have this code in an iFrame. I'm pretty sure the iFrame is from the same domain, that matters I think.
You become 1 best coder
I wan

Solution 1:

First you need to get the iframe. If that is the only one then you can try ....

Note: Updated based on comment

// ==UserScript==// @name        Script// @include     https://www.somesite.com/*// @require     http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/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.
*/const intv = setInterval(function() {
  const iframe = document.querySelector('iframe[src*="something.php"]');
  const sp = iframe && iframe.contentWindow.document.body.querySelector('#10'); // find id (some)if (sp && sp.textContent === 'You become 1 best coder') {
    alert('Hello world!');
  }
}, 5000);

Update

iframe content are also document. If the code doesn't need to interact with the parent frame, you can inject the userscript in the target iframe document and run it there.

Post a Comment for "How To Run Script Only If Div:contains In An Iframe - Greasemonkey"