Basic localStorage usage

From SmartBots Developers Docs
Bot PlaygroundExamples
Revision as of 15:23, 6 October 2016 by Gg (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search


This script displays the basic usage of localStorage.set() and localStorage.get() functions.

var CONFIG = {};

restoreConfig();

CONFIG.runs++;
console.log("This script is starting for " + CONFIG.runs + " time");

saveConfig();


function restoreConfig() {
	var cnf = localStorage.get("my_config");
	CONFIG = { runs: 0 };
	
	if(typeof(cnf) != "undefined" && cnf != "") {
		CONFIG = JSON.parse(cnf);
	}
}

function saveConfig() {
	localStorage.set("my_config", JSON.stringify(CONFIG));
}