Gelbooru Visited

Marks previously visited images on Gelbooru search pages

目前為 2020-03-16 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Gelbooru Visited
// @namespace    http://tampermonkey.net/
// @version      0.3
// @description  Marks previously visited images on Gelbooru search pages
// @author       Xerodusk
// @homepage     https://greasyfork.org/en/users/460331-xerodusk
// @match        https://gelbooru.com/index.php*
// @grant        none
// @icon         https://gelbooru.com/favicon.png
// ==/UserScript==
/* jshint esversion: 6 */

/*   configuration   */
var imgUnvistedColor = '#E1F5FE'; // Color for unvisted images (Note: MUST BE A VALID, NON-TRANSPARENT COLOR FOR *VISITED* COLOR TO WORK)
var imgVisitedColor = '#2E7D32'; // Color for visited images
var webmUnvistedColor = '#1565C0'; // Color for unvisted WebMs
var webmVisitedColor = '#C62828'; // Color for visited WebMs

/*-------------------*/

(function() {
    'use strict';

    if (window.location.href.indexOf("s=list") > -1) { // Search page
        // Get search results area
        var galleryContainer = document.querySelector('.contain-push');
        var galleryLinks;
        if (!!galleryContainer) {
            // Get all image thumbnail links
            galleryLinks = galleryContainer.querySelectorAll('.thumbnail-preview a');
        }
        if (!!galleryLinks) {
            galleryLinks.forEach(galleryLink => {
                let linkURL = new URL('https:' + galleryLink.getAttribute('href'));
                // Set click to go to the original url to preserve next/previous feature
                galleryLink.setAttribute('onclick', 'window.location = "' + linkURL + '";return false;');
                // Remove the "tags" attribute so the link being used for this is constant for the same image across all searches it is included in
                var searchParams = new URLSearchParams(linkURL.search);
                searchParams.delete('tags');
                var newLinkURL = new URL(linkURL);
                newLinkURL.search = searchParams.toString();
                galleryLink.href = newLinkURL;
            });
        }
        // Apply borders
        var css = document.createElement('style');
        css.innerHTML = `
		  .thumbnail-preview a .preview {
			  border-width: 3px;
			  border-style: solid;
			  border-color: ` + imgUnvistedColor + `;
			  margin: -3px;
		  }
		  .thumbnail-preview a:visited .preview {
			  border-color: ` + imgVisitedColor + `;
		  }
		  .thumbnail-preview a .preview.webm {
			  border-color: ` + webmUnvistedColor + ` !important;
		  }
		  .thumbnail-preview a:visited .preview.webm {
			  border-color: ` + webmVisitedColor + ` !important;
		  }
		`;
        document.head.appendChild(css);
    } else if (window.location.href.indexOf("s=view") > -1) { // Image page
        // Add URL without the "tags" attribute to the history so as to make it match what the search results pages are modified for (and avoid breaking back button functionality while we're at it)
        var url = new URL(window.location);
        var searchParams = new URLSearchParams(url.search);
        searchParams.delete('tags');
        url.search = searchParams.toString();
        window.history.replaceState({}, '', '/' + url.href.substring(url.href.indexOf('/') + 1));
    }
})();