Gelbooru Show Tags on Hover for Saved Searches and Wiki Entries

Makes tags display on hover for saved searches and wiki pages, like on the rest of the site.

As of 2021-01-08. See the latest version.

// ==UserScript==
// @name         Gelbooru Show Tags on Hover for Saved Searches and Wiki Entries
// @namespace    http://tampermonkey.net/
// @version      2.1.0
// @description  Makes tags display on hover for saved searches and wiki pages, like on the rest of the site.
// @author       Xerodusk
// @homepage     https://greasyfork.org/en/users/460331-xerodusk
// @include      https://gelbooru.com/index.php*s=saved_search*
// @include      https://gelbooru.com/index.php*page=wiki*s=view*
// @grant        none
// @icon         https://gelbooru.com/favicon.png
// ==/UserScript==
/* jshint esversion: 6 */

// Decode encoded characters in tags for proper processing
function htmlDecode(input) {
    'use strict';

    const tempElem = document.createElement('div');
    tempElem.innerHTML = input;
    return tempElem.childNodes.length === 0 ? "" : tempElem.childNodes[0].nodeValue;
}

// Copy tags from alt attribute to title attribute for image thumbnails
function tagsToTitle(imageThumbs) {
    'use strict';

    imageThumbs.forEach(imageThumb => {
        imageThumb.setAttribute('title', htmlDecode(imageThumb.getAttribute('alt')));
    });
}

(function() {
    'use strict';

    // Get all image thumbnails on page
    let imageSelector; // selector for all image thumbnails
    const searchParams = new URLSearchParams(window.location.search);
    if (searchParams.get('s') === 'saved_search') {
        imageSelector = '.thumbnail-container > .thumbnail-preview a img';
    } else if (searchParams.get('page') === 'wiki') {
        imageSelector = '.thumb img';
    }

    const imageThumbs = [...document.querySelectorAll(imageSelector)];

    tagsToTitle(imageThumbs);
})();