Skip to content

Instantly share code, notes, and snippets.

@qqueue
Created October 30, 2012 18:19
Show Gist options
  • Save qqueue/3982012 to your computer and use it in GitHub Desktop.
Save qqueue/3982012 to your computer and use it in GitHub Desktop.
Persist 4chan native extension settings

View the "raw" version of the script source to install.

// ==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