|
// ==UserScript== |
|
// @name Permanent Ao3 Search Filters |
|
// @namespace https://brickgrass.uk |
|
// @version 0.1 |
|
// @description Lets you set checkboxes for ao3 filters that will always be on. |
|
// @author BrickGrass |
|
// @match https://archiveofourown.org/* |
|
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js |
|
// @grant none |
|
// ==/UserScript== |
|
|
|
const valid_filters = { |
|
"include_rating_ids_13": "Include Rating Explicit", |
|
"include_rating_ids_11": "Include Rating Teen And Up Audiences", |
|
"include_rating_ids_12": "Include Rating Mature", |
|
"include_rating_ids_10": "Include Rating General Audiences", |
|
"include_rating_ids_9": "Include Rating Not Rated", |
|
|
|
"include_archive_warning_ids_16": "Include Warning No Archive Warnings Apply", |
|
"include_archive_warning_ids_14": "Include Warning Creator Chose Not To Use Archive Warnings", |
|
"include_archive_warning_ids_17": "Include Warning Graphic Depictions of Violence", |
|
"include_archive_warning_ids_19": "Include Warning Rape/Non-Con", |
|
"include_archive_warning_ids_18": "Include Warning Major Character Death", |
|
"include_archive_warning_ids_20": "Include Warning Underage", |
|
|
|
"include_category_ids_23": "Include Category M/M", |
|
"include_category_ids_22": "Include Category F/M", |
|
"include_category_ids_21": "Include Category Gen", |
|
"include_category_ids_24": "Include Category Other", |
|
"include_category_ids_2246": "Include Category Multi", |
|
"include_category_ids_116": "Include Category F/F", |
|
|
|
"exclude_rating_ids_13": "Exclude Rating Explicit", |
|
"exclude_rating_ids_11": "Exclude Rating Teen And Up Audiences", |
|
"exclude_rating_ids_12": "Exclude Rating Mature", |
|
"exclude_rating_ids_10": "Exclude Rating General Audiences", |
|
"exclude_rating_ids_9": "Exclude Rating Not Rated", |
|
|
|
"exclude_archive_warning_ids_16": "Exclude Warning No Archive Warnings Apply", |
|
"exclude_archive_warning_ids_14": "Exclude Warning Creator Chose Not To Use Archive Warnings", |
|
"exclude_archive_warning_ids_17": "Exclude Warning Graphic Depictions of Violence", |
|
"exclude_archive_warning_ids_19": "Exclude Warning Rape/Non-Con", |
|
"exclude_archive_warning_ids_18": "Exclude Warning Major Character Death", |
|
"exclude_archive_warning_ids_20": "Exclude Warning Underage", |
|
|
|
"exclude_category_ids_23": "Exclude Category M/M", |
|
"exclude_category_ids_22": "Exclude Category F/M", |
|
"exclude_category_ids_21": "Exclude Category Gen", |
|
"exclude_category_ids_24": "Exclude Category Other", |
|
"exclude_category_ids_2246": "Exclude Category Multi", |
|
"exclude_category_ids_116": "Exclude Category F/F" |
|
} |
|
|
|
// Edit this array to contain a list of filters you want always enabled. The options you can pick from are listed above. |
|
// Please make sure you include a comma between each filter. |
|
const enabled_filters = ["include_rating_ids_13", "exclude_category_ids_23"]; |
|
|
|
const bookmark_search = /https:\/\/archiveofourown\.org\/(users\/.*\/bookmarks.*|bookmarks.*)/; |
|
const work_search = /https:\/\/archiveofourown\.org\/(tags\/.*\/works.*|works.*)/; |
|
|
|
$( document ).ready(function () { |
|
if (Array.isArray(enabled_filters) === false) { |
|
console.error("Permanent AO3 Search Filters: enabled_filters is not an array, exiting"); |
|
return; |
|
} |
|
|
|
var insert_string; |
|
let href = window.location.href; |
|
if (href.match(work_search)) { |
|
insert_string = "work_search_"; |
|
} else if (href.match(bookmark_search)) { |
|
insert_string = "bookmark_search_"; |
|
} |
|
|
|
for (var filter of enabled_filters) { |
|
if (valid_filters[filter] === undefined) { |
|
console.log(`Permanent AO3 Search Filters: Ignoring the invalid search filter '${filter}'`); |
|
continue; |
|
} |
|
|
|
filter = filter.substring(0, 8) + insert_string + filter.substring(8); |
|
|
|
// Enable filter and open its menu so that this is obvious to the user |
|
const filter_input = document.getElementById(filter); |
|
|
|
if (filter_input === null) { |
|
console.log(`Permanent AO3 Search Filters: The filter ${filter} does not exist on this page, skipping`); |
|
continue; |
|
} |
|
|
|
// If a search is loaded from url args the filter may already be on, don't turn it off if so |
|
if (filter_input.checked === false) { |
|
filter_input.click(); |
|
} |
|
const filter_menu = filter_input.closest("dd.expandable.hidden.tags"); |
|
if (filter_menu !== null) { |
|
filter_menu.classList.remove("hidden"); |
|
} |
|
} |
|
}); |