Danbooru

[Userscript] IndexedAutocomplete

Posted under General

Shinjidude said (forum #198223):

...I tought I followed the link to the forum from the IndexedAutocomplete's settings page.

You are correct on that. I don't know how long it's been wrong like that. >_<

I pushed a fix on Version 28.19 which updates the topic to the correct ID on the settings page.

iphn said:

I noticed, when trying to remove a tag by typing -tag, that the - disappears after using autocomplete.

Pushed Version 28.20 as a fix for that. Also, I noticed that the main Danbooru's autocomplete is broken, as autocomplete no longer works with category prefixes.

Pushed Version 29 which primarily adjusts to the new word match autocomplete.

  • Additions
    • Word start matches
      • Forces the old behavior of only searching from the tag beginning.
    • Highlight words
      • Adds highlights to the words in word matches.
      • Uses an underline for the highlight.
  • Fixes
    • Fixed autocomplete highlight colors.

Found a bug: using hyphens breaks highlighting. Example: vanilla and indexedautocomplete. Note that in vanilla this works no matter what the delimiter is: example with asterisk.

There's also other random terms that don't highlight, you can see in this screenshot that 1girl and ah-1g_hueycobra have no boldness.

Edit: seems the problem is much more widespread that I previously realized: example. And the results are now ordered in a nonsensical way after I purged the cache to try and see if that fixed it.

Updated

nonamethanks said:

Found a bug: using hyphens breaks highlighting. Example: vanilla and indexedautocomplete. Note that in vanilla this works no matter what the delimiter is: example with asterisk.

Pushed Version 29.5 which accounts for the hyphen in word matching.

At this time, asterisk match highlighting won't be added since technically, they aren't word matches and follow a completely different pattern for portion highlighting. You can see this by comparing the following two API calls.

I'll work on adding asterisk matching in, but it'll take some time, and I'll make it an additional setting, since as I already stated, they aren't technically word matches. I'll probably reuse the same CSS class for that though, but add another class so that the two types can be differentiated and styled differently if desired.

There's also other random terms that don't highlight, you can see in this screenshot that 1girl and ah-1g_hueycobra have no boldness.

Edit: seems the problem is much more widespread that I previously realized: example. And the results are now ordered in a nonsensical way after I purged the cache to try and see if that fixed it.

Those are all most likely user choice matches, i.e. tags you've selected in the past. You can add styles to .iac-user-choice in order to visualize these. When a tag is selected, whatever type of data is on the match, including the source, gets saved and lasts for as long as that user choice entry remains in the user choice data cache.

This can be fixed in either one of two ways:

  • 1. Purge the entire user choice data cache
    • IndexedAutocomplete Settings >> Cache editor
      • Data source: Local Storage
      • Data name: choice-info
      • Click "Delete"
  • 2. Edit individual entries
    • IndexedAutocomplete Settings >> Cache editor
      • Data source: Local Storage
      • Data name: choice-info
      • Click "Get"
      • Find entries underneath the "choice_data" key and change the "source" to the desired type.
        • Valid types: metatag, tag, tag-word, tag-abbreviation, tag-alias, tag-correction, tag-other-name;
      • Click "Save"

Updated

The following classes become available on the <li> elements when the setting Source highlight enabled is turned on.

  • All: .iac-tag-highlight
  • Choice: .iac-user-choice
  • Exact: .iac-tag-exact
  • Word: .iac-tag-word
  • Abbreviation: .iac-tag-abbreviation
  • Alias: .iac-tag-alias
  • Other name: .iac-tag-other-name
  • Autocorrect: .iac-tag-autocorrect

Without that setting turned on, you can still access many of the same items though using different selectors.

  • All: ul.ui-autocomplete > li.ui-menu-item
  • Exact: [data-autocomplete-type="tag"]
  • Word: [data-autocomplete-type="tag-word"]
  • Abbreviation: [data-autocomplete-type="tag-abbreviation"]
  • Alias: [data-autocomplete-type="tag-alias"]
  • Other name: [data-autocomplete-type="tag-correction"]
  • Autocorrect: [data-autocomplete-type="tag-other-name"]

I currently don't add any classes or data items that can be used to identify choice tags, but that's something that could be added if desired.

BrokenEagle98 said:

  • All: .iac-tag-highlight

The following CSS does not work though:

.iac-tag-highlight {
  text-decoration: none !important;
  font-weight: bold;
}

I was searching for a selector to always highlight just like vanilla danbooru no matter the internal logic for why the tag is showing up.

As for cache purging, I did "Purge cache (...)" and it didn't clear them out. The description for that option says "Dumps all of the cached data related to IndexedAutocomplete" so I'm assuming it's bugged. Removing it manually as you said worked though.

Updated

nonamethanks said:

The following CSS does not work though:

.iac-tag-highlight {
  text-decoration: none !important;
  font-weight: bold;
}

I was searching for a selector to always highlight just like vanilla danbooru no matter the internal logic for why the tag is showing up.

Ah sorry, I misunderstood. I didn't realize that Danbooru was highlighting the matches for all of the sources, so I've only implemented that for word matches as of right now. That's something that will need to be worked on. I'll try to have something out by next weekend.

As for cache purging, I did "Purge cache (...)" and it didn't clear them out. The description for that option says "Dumps all of the cached data related to IndexedAutocomplete" so I'm assuming it's bugged. Removing it manually as you said worked though.

Yeah, that might be a bit of a misnomer, or rather, I'm reusing the term "cache" sometimes for program data when I should be using terms like "storage" instead. The "Purge cache" link currently only purges all data from the Indexed DB (API data from Danbooru), and nothing from Local Storage (program data). The reason being that it contains important information that the user may not want to delete, plus it could have unintended consequences with program behavior. However, one way which currently exists to clear the choice data though, besides doing it manually, is to do a factory reset.

That all being said, I could look into adding something which would purge all program data minus the user settings as something to implement in the future for all of my userscripts.

1 2 3