Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to detect clicks on specific links in page with Greasemonkey?
    text
    copied!<p>Ok... one of my virtual pet sites was down so I decided to tweak a Greasemonkey script for another site... the original script just pops up an alert when you find an egg so you don't click past it - I thought it would be simple to count how many eggs I came across. After 2 hours I finally found a way to keep a variable past page reloads - SUCCESS!! Then I decided I wanted to keep track of how many "steps" I was taking... ARGGGG!!!! Should be simple but isn't!<br> On the page there are three possible explore links to click (shows image not link). 3 hours later I found the event listener and can make an alert popup when I click anywhere on the page, but how do I check for clicks only on 1 of those 3 links? All 3 links have the same general format: <code>http://unicreatures.com/explore.php?area=***&amp;id=***&amp;key=****</code> where the <code>*</code> are changeable. </p> <p>Target page <code>http://unicreatures.com/explore.php?area=grassland</code> should be accessible without an account, if not let me know and I'll grab the source code. </p> <pre><code>// ==UserScript== // @name Unicreatures Egg pop-up // @namespace Unicreatures Egg pop-up // @description Unicreatures Egg pop-up // @include http://unicreatures.com/explore.php* // @include http://www.unicreatures.com/explore.php* // ==/UserScript== var y = document.body.innerHTML; //document.addEventListener('click', function(){alert('page clicked')}, true); if(y.indexOf("You find a Noble")&gt; 0) { alert('Noble Egg Alert'); } if(y.indexOf("You find an Exalted")&gt; 0) { localStorage.exaltedEggCount=Number(localStorage.exaltedEggCount)+1; alert('Exalted Egg Alert '+localStorage.exaltedEggCount); } if(y.indexOf("egg nearby!")&gt; 0) { localStorage.eggCount=Number(localStorage.eggCount)+1; alert('Egg Alert '+localStorage.eggCount); } </code></pre> <p>I do realize that the way the if statements are written that I get double alerts if either of the first 2 trigger(I didn't write that part, just made the alerts unique)... I'm fine with that for now. I did read something about get element id or something but I couldn't find it explained anywhere good enough for me to "get".<br> Please javascript only, no jquery... I'm still barely getting javascript at the moment... please explain answers so I understand how something works - I don't just want code snippets that leave me coming back with a similar question because I don't understand why a bit of code was used.</p> <p>And one other question unless I should open another question for it... when you find an egg the text says <code>You find an Exalted *** egg nearby</code> or <code>You find a *** egg nearby</code>. Is there a way to grab the <code>***</code> part from the page?</p> <p>Thanks!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload