Search code examples
javascriptgreasemonkeytampermonkey

How to set script only run one times? Greasemonkey/Tampermonkey


For example. new tab and include website is the same url

// ==UserScript==
// @name     _YOUR_SCRIPT_NAME
// @include  https://stackoverflow.com/
// @grant    GM_openInTab
// ==/UserScript==

var curTab  = GM_openInTab ("https://stackoverflow.com/");

visit SOF.com after than open more one SOF.com new tab


Solution

  • The question is not clear enough for a definite answer. Here is a script example based on available information:

    // ==UserScript==
    // @name          One Time
    // @description   Open New tab one time
    // @match         https://stackoverflow.com/
    // @grant         GM_openInTab
    // @author        erosman
    // @version       1.0
    // ==/UserScript==
    
    if (!localStorage.getItem('oneTime')) {
      
      localStorage.setItem('oneTime', 'true');
      GM_openInTab('https://stackoverflow.com/');
    }