// ==UserScript== // @name ao3 saved filters // @description Adds fields for persistent global & fandom filters to works index pages on AO3 // @namespace ao3 // @include http*://www.archiveofourown.org/*works* // @include http*://archiveofourown.org/*works* // @grant none // @version 1.5 // @downloadURL https://update.greasyfork.icu/scripts/3578/ao3%20saved%20filters.user.js // @updateURL https://update.greasyfork.icu/scripts/3578/ao3%20saved%20filters.meta.js // ==/UserScript== (function ($) { // config var TAG_OWNERSHIP_PERCENT = 70; // the top fandom which owns works in the current tag must own at least this percent in order to be considered the search's active fandom var works = $('#main.works-index'), form = $('form#work-filters'); if (!works[0] || !form[0]) return; var fandomName = (function () { var fandom = $('#include_fandom_tags label').first().text(), fandomCount = parseInt( fandom.substring(fandom.lastIndexOf('(') + 1, fandom.lastIndexOf(')')) ), tagCount = works.find('.heading').first().text(); tagCount = tagCount.substring(0, tagCount.indexOf(' Works')); tagCount = parseInt(tagCount.substring(tagCount.lastIndexOf(' ') + 1)); fandom = fandom.substring(0, fandom.lastIndexOf('(')).trim(); if (!fandom || !fandomCount || !tagCount) { return; } return (fandomCount / tagCount * 100 > TAG_OWNERSHIP_PERCENT) ? fandom : null; })(), tempKey = 'temp-filter', tempFilter = localStorage[tempKey], tempGlobalKey = 'temp-global-filter', tempGlobalFilter = localStorage[tempGlobalKey], tempFandomKey = 'temp-fandom-filter', tempFandomFilter = localStorage[tempFandomKey], globalKey = 'global-filter', fandomKey = fandomName ? 'filter-' + fandomName : '', globalBox = $('