Skip to content

Instantly share code, notes, and snippets.

@FERR1TE
Last active April 24, 2023 04:08
Show Gist options
  • Save FERR1TE/e9c598b50829b067380b8df33795ebb5 to your computer and use it in GitHub Desktop.
Save FERR1TE/e9c598b50829b067380b8df33795ebb5 to your computer and use it in GitHub Desktop.
Custom buttons for FA's nav bar for frequent searches
// ==UserScript==
// @name Add FA Buttons
// @namespace http://tampermonkey.net/
// @version 1.4
// @description Puts custom buttons on FA's nav bar for frequent searches
// @author HazmatDrone
// @match https://www.furaffinity.net/*
// @run-at document-end
// @icon https://www.furaffinity.net/favicon.ico
// ==/UserScript==
// Example FA URL in full: /search/@lower^rhino003$?&perpage=60&order-by=date&order-direction=desc&range=all&rating-general=0&rating-mature=0&rating-adult=1&type-art=0&type-flash=0&type-photo=0&type-music=0&type-story=1&type-poetry=0&mode=extended
(function () {
// Add the search query to the beginning of each search.
var globalPrefix = "/search/?q="
// Add buttons here in the format "Display text": "Search"
var searches = {
"Rubber": "rubber|latex|drone|pooltoy|melt|melting|melty",
"Petrification": "petrification|petrify|petrification|statue|aurification|golem|gargoyle",
"Candy": "chocolate|choco|candy|cake|icecream|(ice cream)|(melt|melting|melty vore)|living_candy",
}
// Add some extra parameters to apply to every search. Can include blacklist terms, search order, etc
var globalSuffix = "&order-by=date&type-photo=0"
/// Add a button element to the navhideonmobile of Furaffinity
function createCustomBtn(text, search) {
// Create list item
let newBtn = document.createElement("li");
newBtn.setAttribute("class", "lileft");
// Add our button to the item
newBtn.innerHTML = '<a class="top-heading" href="' + globalPrefix + search + globalSuffix + '">' + text + '</a>'
// Append our new button to FA's navhideonmobile
document.getElementById("ddmenu").getElementsByTagName('ul')[0].appendChild(newBtn);
}
for(const btn in searches){
createCustomBtn(btn, searches[btn])
}
})()
@FERR1TE
Copy link
Author

FERR1TE commented Apr 6, 2022

Custom FA Search Buttons

What this script does

It adds custom, user-defined search buttons to the right of the search box. They can be used as shortcuts for frequent and/or complex searches.
image
You can test the default ones here:

Installation

  1. Install Tampermonkey as a browser extension
  2. Click the Tampermonkey addon in your browser and select "Create new script"
  3. Delete all code in the editor and paste in the script above.
  4. Configure as you see fit.

Config

To edit the buttons that appear, see customButtons. Add searches in the form "Display text": "Search" where Display text is what text the button shows and Search is what the script searches for. You can add as few or as many as you like, so long as they're separated by commas.

You can also edit the globalSuffix variable to edit settings applied to all searches. The one included by default sorts by newest, and removes every submission type that isn't art.

If you want to add more complex behaviour, you can change globalPrefix to be blank. You'll have to manually add /search/?q= to any searches, but you can then also specify other URLs such as profile pages, submissions, or even external links if you really want.

This script can be used to blacklist search terms or users, but I'd recommend using it in conjunction with Filter Affinity instead (Chrome, Firefox).

Known Bugs

Currently, if you try to navigate backwards (with the browser's back button) during a search, some browsers may show a "Document Expired" error each time. This appears to have been fixed at around Tampermonkey v4.16.6160.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment