Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8523231
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T07:21:04+00:00 2026-06-11T07:21:04+00:00

I have a Greasemonkey script that keeps track of different things on unicreatures.com .

  • 0

I have a Greasemonkey script that keeps track of different things on unicreatures.com.

One of the things I wanted to count was clicks on some links on the page, but not all links.

These need counted,
http://unicreatures.com/explore.php?area=sea&id=89&key=bf12
These should not be counted,
http://unicreatures.com/explore.php?area=sea&gather=5&enc=394844&r=

Someone helped me figure out a regexp that did what I wanted, but I had to code each different explore location (area=**) into it, so I decided that wouldn’t work.

The regexp version

var links = document.getElementsByTagName( 'a' );

for ( var i = 0; i < links.length; i++ ) {
var link = links[i];
if ( /area=sea(?!\&gather)/.test( link.href )) {
    link.addEventListener( 'click', function () {
localStorage.steps=Number(localStorage.steps)+1
       // alert(localStorage.steps + ' in Sargasso' );
    }, true );
}
}

Obviously I don’t want a billion if statements for the different values of area=, and I couldn’t find a way to add a variable to a regexp.

So I finally found some string manipulation commands and put together this:

var url = window.location.href;
var startOf=url.indexOf("=")+1;
var endOf=url.indexOf("&");
var loc =url.substring(startOf,endOf);

var links = document.getElementsByTagName( 'a' );

for ( var i = 0; i < links.length; i++ ) {
var link = links[i];
if (url.indexOf("area=")>=0 && url.indexOf("gather=")<0) {
    link.addEventListener( 'click', function () {
localStorage.steps=Number(localStorage.steps)+1
localStorage[loc+"Steps"]=Number(localStorage[loc+"Steps"])+1
        alert(localStorage[loc+"Steps"] +" in local"+loc);
    }, true );
}
}  

For some reason it counts even when the second condition is false. Is this a simple case of me getting the syntax wrong somewhere, or is this a Greasemonkey bug? I don’t get any errors in the console.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T07:21:06+00:00Added an answer on June 11, 2026 at 7:21 am

    Try just to tweak your regexp version, instead of this:

    if ( /area=sea(?!\&gather)/.test( link.href )) {
    

    use this regex:

    if ( /area=(\w*)&id=/.test( link.href )) {
    

    that will match all links that have an ‘area’ parameter followed by an ‘id’ parameter, which seems enough to match the links you want.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So, I have GreaseMonkey Script that does some operations with integers and then sets
I have a Greasemonkey script that dynamically inserts an HTML form into some web
I have a simple greasemonkey script that makes some simple dom manipulation. The greasemonkey
So I have a greasemonkey script that I am adding onto, and one of
I have created a Greasemonkey script that runs fine in the firebug editor, with
Do you have any link\example of Greasemonkey script with Jquery that works in Google
I have a messageboard and one of my users has written a greasemonkey script
I have a Greasemonkey script that prints a div -- works! However, I'd like
I have this Greasemonkey script that works fine in the Fiddle. It's designed to
I have a greasemonkey script that opens an iframe containing a form from a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.