:コンソールで
// ==UserScript==
// @name Remember value
// @namespace util
// @description Test that remembers any saved value after reload
// @include http://stackoverflow.com/*
// @version 1
// @grant none
// ==/UserScript==
// Try to load saved data from local storage
const FIELD_NAME = "userscript_TEST";
var saved = localStorage[FIELD_NAME]?JSON.parse(localStorage[FIELD_NAME]):{};
// Save data when leaving tab
window.addEventListener("unload", function() {
localStorage[FIELD_NAME] = JSON.stringify(saved);
});
// This changed document title and remembers it
window.changeDocumentTitleForever = function(title) {
saved["title"] = title;
document.title = title;
}
// This loads title after loading page
if(saved.title)
document.title = saved.title;
使用方法:以下は、ドキュメントのタイトルを変更することができますし、リロードの上にそれを覚えていますサンプルスクリプトを参照してくださいlocalStorage
より選択してください。
var arr = ["alex", "felix"];
try { arr = JSON.parse(GM_getValue('arr', '["alex", "felix"]')); }
catch (_ignore) { /* ignore when JSON.parse fail */ }
// do something with arr
arr.push('kelix');
GM_setValue('arr', JSON.stringify(arr));
出典
2016-09-02 02:10:15
tsh
refresh.'sessionStorage.setItem後に再使用する変数を格納するために使用のlocalStorage /のsessionStorage( '編曲'、編曲): 'と' sessionStorage.getItem( 'ARR')を使用して、それを取り出します; '。ここのsessionStorageの詳細はhttps://developer.mozilla.org/en/docs/Web/API/Window/sessionStorage –
で、 'localStorage.arr'を直接使うことができます – maioman