I'm planning to write a Greasemonkey script that will run on a particular URL (@include or @match), but, I'd like to have it so that if I open up one or more additional tabs with the same URL, the Greasemonkey script will NOT run on the second (and further) duplicate pages.
So, for example, say I have a Greasemonkey script that makes "style" changes to a webpage (or in some other way "modifies" it) when I open "google.com". I want to be able to open another tab to "google.com" where that Greasemonkey script will not run. Or, more correctly, will run but will detect that it is already running and "modifying" the page in the first tab and then "exit" in the second tab. The second tab will remain open but is just "unaffected" by the script.
I don't know if a Greasemonkey script can "see" other opened tabs, but if it can, my first thought was to check if another tab was already loaded to that page, and then to exit if it found that it was.
But it would have to be a bit more involved than that because:
- If the first tab was closed and a new ("third") tab was opened to that URL, I would want the Greasemonkey script to run and "modify" that page as it would have on the first page.
- Similarly, if I "refresh" the first tab (say after editing the Greasemonkey script, or for another reason), I would want the Greasemonkey script to run and "modify" the reloaded page.
So, it seems the Greasemonkey script would have to either:
- Check the URL of each other tab to find a "match", and then "Peek into that tab" to see if the Greasemonkey script was "actively" modifying that page (perhaps look for a hidden, empty, named "DIV" or other element).
- Use some sort of "local storage" or "cross-tab global (superglobal ?) variables" to keep track of the tabs as they open and close.
I'm not looking for someone to write this script for me, I feel I'm capable of writing the script if I knew how to do a few things. If a script that does all or most of this already exists then that would be great too.
To get started, I need to know if (and how) a Greasemonkey script:
- Can "see" other tabs.
- Can read the URLs (and perhaps the "title" text) of the other tabs.
- Check for existence of (and perhaps read but not write) elements in the other tab.
- Manage "local (computer) storage" or manage "cross-tab global variables" (if this can even be done).