I'm trying to run a script in Tampermonkey and have it run one single time in a tab or on a given webpage page before it stops. The script currently automatically clicks any "a" element link that has a given word within it. Example HTML code like so:
<a href="adbc.com">Contact</a>
The script will click on that link given that I have specified the word "Contact" in the script. The script I have, unfortunately, continues to run infinitely within a single page / tab in my browser, no matter how many times it has been clicked. I want this to stop - and be used one single time within a tab (even when it goes to the next link that's been clicked).
I want this script to stop once it has clicked on a single link - or only run once in a single tab or from a single page. Oftentimes this is usually not a problem because the next loaded page (the clicked link) won't contain a link with the given phrase... But sometimes it will, which will cause the page to just click on links infinitely. I need a way to avoid this problem - to only have the script click once or on one link. This can involve exiting the script, pausing the script, or simply just having the program run one single time.
Right now I have the following code, which automatically clicks any links with the phrase "Contact" within them:
// ==UserScript==
// @name Music Submissions Contact
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js
// @include *
// @grant GM_addStyle
// ==/UserScript==
var TargetLink = $("a:contains('Contact')")
if (TargetLink.length)
window.location.href = TargetLink[0].href
I want a way for this script to stop/exit/close/pause/suspend after one single click. I've been unable to find the correct syntax or logic, so any advice would surely help.