Skip to content

Instantly share code, notes, and snippets.

@BrickGrass
Last active November 22, 2022 20:32
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BrickGrass/505cbc1824bd6e98cbf2c52bb8cb4975 to your computer and use it in GitHub Desktop.
Save BrickGrass/505cbc1824bd6e98cbf2c52bb8cb4975 to your computer and use it in GitHub Desktop.

Permanent AO3 Seach Filters

This is a tampermonkey browser extension which allows you to permanently enable an ao3 search filter (such as include explict works or exclude works with warning underage).

To install the extension you first need to install tampermonkey:

  1. Install on Chrome
  2. Install on Firefox
  3. Install on Safari

Once tampermonkey is installed, click this link to install the script https://gist.github.com/BrickGrass/505cbc1824bd6e98cbf2c52bb8cb4975/raw/a4351ce09bccaf08ae530a32c28b50a91d61b32f/permanent_ao3_search_filters.user.js

Once it is installed, you can modify which ao3 filters you want permanently included or excluded. Open the tampermonkey extension's dashboard and enter the edit page for this script; then scroll down to line 56 and edit the list of filter ids, picking from the list of options directly above.

For example, if you wanted to always exclude works with the "Major Character Death" tag you would look in the list for the relevant line "exclude_archive_warning_ids_18": "Exclude Warning Major Character Death", which is on line 43. You would copy the text at the start ("exclude_archive_warning_ids_18") down into the enabled_filters variable. It would then look like: const enabled_filters = ["exclude_archive_warning_ids_18"];.

// ==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");
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment