View the "raw" version of the script source to install.
Created
October 30, 2012 18:19
-
-
Save qqueue/3982012 to your computer and use it in GitHub Desktop.
Persist 4chan native extension settings
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name 4chan settings persistence | |
// @namespace queue | |
// @author queue | |
// @description Save 4chan JS settings to GM_preferences, which persist through cookie deletion. | |
// @include https://boards.4chan.org/* | |
// @include http://boards.4chan.org/* | |
// @version 1 | |
// @run-at document-start | |
// @grant GM_getValue | |
// @grant GM_setValue | |
// @grant GM_deleteValue | |
// @grant GM_listValues | |
// ==/UserScript== | |
//console.log('loading') | |
GM_listValues().forEach(function (k) { | |
//console.log(k) | |
localStorage.setItem(k, GM_getValue(k)) | |
}) | |
window.addEventListener('beforeunload', function () { | |
//console.log('saving...') | |
// clean up deleted | |
GM_listValues().forEach(function (k) { | |
//console.log(k) | |
if (!(localStorage.getItem(k))) { | |
GM_deleteValue(k) | |
} | |
}) | |
Object.keys(localStorage) | |
.filter(RegExp.prototype.test.bind(/^4chan-/)) // only native extension | |
.forEach(function (k) { | |
//console.log(k) | |
GM_setValue(k, localStorage.getItem(k)) | |
}) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment