Created
July 27, 2018 23:42
-
-
Save patrickroberts/b6937c0ffd9b1e8cea618f43370eea60 to your computer and use it in GitHub Desktop.
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 Stack Overflow Sticky Search Filter | |
// @namespace http://tampermonkey.net/ | |
// @version 0.0.0 | |
// @description Use localStorage to remember most recently used search filter | |
// @author Patrick Roberts | |
// @match https://*.stackoverflow.com/* | |
// @grant none | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
const tabsFilter = document.querySelector('.tabs-filter'); | |
if (tabsFilter !== null) { | |
tabsFilter.addEventListener('click', ({ target }) => { | |
if (target.matches('a[href]')) { | |
localStorage.tabsFilter = new URLSearchParams(target.search).get('tab'); | |
} | |
}); | |
} | |
if ('tabsFilter' in localStorage) { | |
for (const form of document.querySelectorAll('form[action="/search"]')) { | |
const tab = document.createElement('input'); | |
tab.setAttribute('type', 'hidden'); | |
tab.setAttribute('name', 'tab'); | |
tab.setAttribute('value', localStorage.tabsFilter); | |
form.prepend(tab); | |
} | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment