NOTICE: By continued use of this site you understand and agree to the binding Terms of Service and Privacy Policy.
// ==UserScript== // @name Localhost sites storage sync // @namespace http://tampermonkey.net/ // @version 0.1 // @description Sync localstorage for localhost sites // @author You // @match http*://localhost:*/* // @icon https://www.google.com/s2/favicons?sz=64&domain=undefined.localhost // @require https://openuserjs.org/src/libs/sizzle/GM_config.js // @grant GM_registerMenuCommand // @grant GM_getValue // @grant GM_setValue // @license MIT // ==/UserScript== (function () { 'use strict'; let checkInterval, rpaInterval; let defaultInterval = 1000; GM_config.init({ 'id': 'scriptConfig', 'fields': { 'mainHost': { 'label': 'Main site host', 'type': 'text', 'title': 'Host of main site(include port if different of 80. Example: localhost:8080)', 'default': 'localhost' }, 'rpaHost': { 'label': 'Rpa site host', 'type': 'text', 'title': 'Host of rpa site', 'default': 'localhost:3000' } } }); GM_registerMenuCommand("Options", function () { GM_config.open(); }, "a"); checkInterval = setInterval(checkToken, defaultInterval) rpaInterval = setInterval(setRpaLocalStorage, defaultInterval) function checkToken() { if (location.host !== GM_config.get('mainHost')) { return; } if (GM_getValue('mainToken') !== localStorage.getItem('Steve.session.token')) { GM_setValue('mainToken', localStorage.getItem('Steve.session.token')); GM_setValue('mainLocalStorage', JSON.stringify(localStorage)); } } function setRpaLocalStorage() { if (location.host !== GM_config.get('rpaHost')) { return; } const mainToken = GM_getValue('mainToken'); if (mainToken !== null && mainToken !== undefined && GM_getValue('mainToken') !== localStorage.getItem('Steve.session.token')) { let mainLocalStorage = JSON.parse(GM_getValue('mainLocalStorage')); for (let key in mainLocalStorage) { localStorage.setItem(key, mainLocalStorage[key]); } location.reload(); } } })();