Skip to content

Instantly share code, notes, and snippets.

@arantius
Last active March 8, 2022 15:31
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arantius/5b25e120d38506021c4528d2df55feb4 to your computer and use it in GitHub Desktop.
Save arantius/5b25e120d38506021c4528d2df55feb4 to your computer and use it in GitHub Desktop.
A simple persistent value test user script
'use strict';
// ==UserScript==
// @name GM set/get demo
// @description Exercises both GM.getValue() and GM.getValue(). Logs a counter which goes up by one, at each page load.
// @grant GM.getValue
// @grant GM_getValue
// @grant GM.setValue
// @grant GM_setValue
// @require https://greasemonkey.github.io/gm4-polyfill/gm4-polyfill.js
// ==/UserScript==
async function getSetDemo() {
console.log('Starting the get/set demo ...');
let i = await GM.getValue('i', 0);
console.log(`This time, i was ${i}.`);
GM.setValue('i', i+1);
}
getSetDemo();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment