Danbooru

[Userscript] BetterSavedSearches (UNSUPPORTED)

Posted under General

BetterSavedSearches provides an alternative mechanism and user interface for a user's saved searches. This includes more frequent checking, better feedback information, and finer control.

Installation

Project page

Main script

https://raw.githubusercontent.com/BrokenEagle/JavaScripts/stable/bettersavedsearches.user.js

Usage notes

Settings can be modified from your Danbooru user edit page, (My Account >> Settings) under Userscript Menus.

In the settings menu is a user setting to turn off the script, allowing it to be turned on/off on a subdomain basis.

More Details
Initialization

The first run of the script will query every single saved search to seed all of the query entries. This means that the more queries you have, the longer it will take to finish initializing. To give an idea, 70 saved searches, took around 15 seconds to finish loading.

Post Index

This is where the main user interface is installed. Saved searches are organized by labels alphabetically. Queries under each label are also organized alphabetically.

Post Show

Supports sequential navigation of search queries on posts that are clicked from the post index.

Click

Clicking various items on the interface will yield different effects.

  • "Toggle List" - Hides or shows the saved search list (this setting is saved between page loads).
  • triangle - Expands or contracts the query list under a label (not saved with some exceptions).
  • headers - Reloads the page showing all of posts for that category that have been collected by BetterSavedSearches.
    • "Saved Searches" - Shows all of them. Equivalent to search:all.
    • labels - Shows all under a label. Equivalent to search:LABEL.
    • queries - Shows all of the posts under a query. Equivalent to QUERY.
  • arrows - Reloads the page using the actual search metatags (what Danbooru has collected) or query lines (actual queries).
  • last item - Provides various controls to modify that line in some fashion
    • (##) - Performs the same action as headers above, but only shows the unseen posts since the last time checked.
    • red X - Clears all of the posts from that level, and marks it as disabled.
    • circular arrow - Performs a fresh query at that level
    • NOTE: (##) -> red X -> circular arrow -> (##)
  • "Last Updated - Red X" - Resets the post progress to the present, skipping all posts
    • Useful for after long periods of absence
Hover

Hovering over various items will show different information.

  • calendar - Last time that the query was updated/rechecked.
  • header - Shows the full header text, in the case that the label/query is too long.
    • Query lines with pool IDs used will show the query as it is stored, however hovering over it will show popup text with the pool name.
  • last item
    • (##) - Total number of posts collected for that query/label.
    • red X - ditto
Style

There are a variety of styling effects used to indicate various conditions

  • green text - Indicates the presence of metatags in a query. Labels are highlighted if any are metatags.
  • underlined - Indicates the query is disabled. Labels are highlighted only if all are disabled.
  • bold - Indicates the active query selected from the prior page load.
Caveats

Metatags are handled differently from other queries, and will only be refreshed in under a day.

Disabled affects regular and metatag queries differently. For metatags, it completely shuts them down. For regular, it will continue to collect new posts, but won't perform queries. This allows a user to track how many posts a query has had since a certain point in time, kind of like a trip indicator. Some queries may automatically be disabled if the seed query find zero posts.

Saved Search Index

This is where some alternative management functions are at.

A link has been added to the top submenu called "Refresh BetterSavedSearches(#)" which performs a synchronization and normalization of the saved searches saved on Danbooru and the script.

An interface has been added to the bottom that allows a user to create new saved searches without having to use the controls provided by Danbooru on the post index. So now all management can be done from one page, i.e. add, edit, or delete.

Program details

Show

Standard operations include a recheck every 5 minutes (user default), performing a variety of collection actions.

  • Initial pass: Any post older than 5 minutes gets processed (will catch most uploads from users that tag well).
    • Posts between 5 - 60 minutes old get saved for a second pass.
  • Second pass: Any post older than 1 hour gets processed (will catch most uploads tagged by others that tag well).
  • Metatag check: Metatag queries are given a random 16 - 24 hour expiration (user default). Queries that are expired get rechecked.
  • Random check: One query is chosen each hour (user default) for a recheck. Favors queries the longer they've gone without being updated, that have more posts per time period, and that have more success when performing the random check.

Final

Any suggestions or feedback is appreciated.

Latest edits

  • (2022-09-04) Updated OP
  • (2022-03-12) Script is no longer being supported

Versions

Show
  • (2018-07-30)
    • Version 2 - Initial release
  • (2019-06-01)
    • Version 3
      • Settings menu
      • Full pagination
      • Sequential navigation
      • Progress indicator
  • (2019-07-12)
    • Version 4
      • Results shown on profile page
      • Robust pagination/sequential navigation
  • (2019-08-20)
    • Version 5
      • Better recheck mechanism
      • More query info tracked and displayed
  • (2020-01-01)
    • Version 6 Updated library version

Updated

Really wanted to use this but the version of greasemonkey I'm stuck using can't use it. I debugged it and found it's the async/await that causes it to fail. I can remove those and get it to mostly compile but don't know what I can do for removing the promises, as I haven't worked with those yet.

EMUltra3 said:

Really wanted to use this but the version of greasemonkey I'm stuck using can't use it. I debugged it and found it's the async/await that causes it to fail. I can remove those and get it to mostly compile but don't know what I can do for removing the promises, as I haven't worked with those yet.

What version of GreaseMonkey, what browser, and what OS are you using?

I'm not sure what I'll be able to do, since the code fundamentally relies on async/await and would require a major rewrite otherwise, but I'll look around and see if there's a way to get GreaseMonkey to use async/await.

Um...nevermind, I thought Pale Moon wasn't going to support async/await but the most recent update did. Got it working.

I just have one question though: Is there any settings to append the search query? I usually filter out my favorites and include status:any.

Edit: It causes small load hickups on every page load. Maybe Chrome doesn't get those. I just changed the whitelist to saved_searches and tags=search*.

Updated

EMUltra3 said:

I just have one question though: Is there any settings to append the search query? I usually filter out my favorites and include status:any.

Do you mean filter them out pre-collection or post-collection?

Pre-collection

If it's the former, then status:any is already being applied, as all posts are searched when they are created. One caveat is that if you haven't checked Danbooru for 3 or more days, then the script will have to play catch-up, and currently it doesn't look like the script is applying a status:any to the script. I'll have to check to see if the status:any is a freebie tag or whether it counts towards the user's total, and fix it accordingly.

For favorite filters, fav: currently falls under the list of metatags that aren't being handled by the regular handler.

Current unhandled metatags:

commenter, comm, noter, noteupdater, artcomm, ordpool, favgroup, fav, ordfav, md5, locked, width, height, mpixels, ratio, score, favcount, filesize, source, id, date, age, order, limit, approver, tagcount, pixiv_id, pixiv, search, upvote, downvote, flagger, appealer, gentags, chartags, copytags, arttags, metatags

When a query with an unhandled metatag is encountered, it switches to checking that query every 16-24 hours.

However, fav: could be handled, however it would be limited to just the user themselves. Also, many of the above entries could be handled, but I didn't want to put a lot of coding into it if there wasn't a desire for them.

Post-collection

I know that the search query line gets pretty long when checking a saved search, but you can always append status:any and/or -fav:username to the front of it.

If this is something that is desired on a permanent basis, then that would require a user setting and setting up a user interface.

Final

It'd probably be preferable to go with a post-collection filter for the fav: metatag, as the regular check happens every 5 minutes, and unless you are super fast at favoriting new posts, it wouldn't remove them from the post display. If the permanent option is desired, then it would take about a week to code.

Pushed Version 3 which added several updates and enhancements:

  • Added user settings and a settings menu
    • (My Account >> Settings) under Userscript Menus
    • Includes a user setting to disable the script
    • Useful for only wanting the script to run on certain subdomains
  • Facilitate full pagination of saved searches
    • Beforehand it was limited to the 500 most recent
  • Facilitate sequential navigation of saved searches
  • Displays the current progress of the script on getting new posts
  • Provides a control to skip all progress to the present
    • Useful for long periods of absence
  • Added post filters <EMUltra3 forum #151420>
    • Can filter out favorited posts
    • Can automatically adds status:any to the search (to show deleted posts)
  • Accounts for user limit of tag on search queries
  • Updated the library to the latest version
  • Several other updates/simplifications
Minor versions
  • (2019-06-06)
    • 3.1 - Fix active query not being set correctly on a search label click

Updated

Pushed Version 4 which primarily adds the ability to view BetterSavedSearch results from the user profile page. Choose either "Script" or "Both" for the profile thumb source from the user settings menu.

Additionally, it adds a more robust method of handling pagination/sequentialization, including when opening a thumbnail/page link into a new tab.

Pushed Version 5 which primarily fixes a number of inefficiencies with the old random recheck mechanism. Instead of relying only on seed time, it now uses both post velocity and success rate. Additionally, the script now tracks the random recheck mechanism and lists them as Seeds/day on the post index menu. This will allow users to better tweak the recheck interval based upon their browsing pattern. Also, both the last seed time and last post found time are available for each query to help track how current they are.

Other major fixes and updates
  • Use scalpel instead of hammer validation for the query data
    • Beforehand it would throw out all of the data if any part was wrong
    • This would cause everything to be reset and would generate a large number of network requests
  • Heartbeat mechanism to detect when the browser discards the tab
    • This was causing tabs to unknowingly miss query updates from other tabs
    • When the tab became active again, it would often clobber the new data with its old data
  • Faster validation for arrays of simple data
  • Faster sets functions for simple boolean checks

Pushed Version 9 which primarily includes an update to the library code plus a few additions and fixes:

  • Additions
    • Added control on settings menu to reset all query data
    • Added new menu library elements/functions for cache editor
      • The raw program data can be extracted using the cache editor, which facilitates transferring program data to another browser/domain
      • Controls which are not applicable are hidden, for example Local storage must be selected before the raw data option becomes visible
  • Changes
    • The unseen posts control (# in parentheses) is now separate from the other controls and always visible
    • Altered method of retrieving aliases to reduce delay/load
    • Settings menu now adapts to the color changes of the chosen theme (light/dark)
  • Fixes
    • Fixed queries not updating once the maximum number of posts (200) had been reached
  • Other
    • Adjusted the CSS styling of several elements
    • Multiple internal code changes and refactors
1