If you want the script (or part of the script) to be run only once, you need to save the flag in non-volatile memory. A script cannot delete itself or disconnect. But it can exit right away and not run any other code.
To store things based on the site (by domain), use localStorage . To save content in a script + namespace, use GM_setValue . Here's the base script:
// ==UserScript== // @name _Run a GM script one-time only // @namespace _pc // @include http://YOUR_SERVER.COM/YOUR_PATH/* // @grant GM_getValue // @grant GM_setValue // ==/UserScript== var alreadyRun = GM_getValue ("alreadyRun", false); if ( ! alreadyRun) { GM_setValue ("alreadyRun", true); alert ("This part of the script will run exactly once per install."); }
source share