您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
Save search queries
当前为
// ==UserScript== // @name Rule34 Save Search // @namespace http://tampermonkey.net/ // @version 0.2 // @description Save search queries // @author User_314159 // @license MIT // @match https://rule34.xxx/index.php?page=post&s=list* // @icon https://www.google.com/s2/favicons?sz=64&domain=rule34.xxx // @grant none // ==/UserScript== // display logic function should_display() { let contents = document.getElementById("content"); if (contents.getElementsByClassName("image-list")[0] != undefined) { let search_bar = contents.querySelector('input[name="tags"]'); if (search_bar.value != "") { console.log("Search bar not empty, should display"); return [true, search_bar.value]; } } return [false, ""]; } //io function getSavedSearches() { // gets the localstorage array and parses it into an actual array, creates a new one if there is no key in localStorage let artists; if (localStorage.getItem('rule34SavedSearches') === null) { console.log('generated new saved array'); artists = []; } else { artists = JSON.parse(localStorage.getItem('rule34SavedSearches')); } return artists; } function deleteSearch(search) { // deletes the specified search out of the array and saves it let artists = getSavedSearches(); let target = artists.indexOf(search); artists.splice(target, 1); saveSearches(artists); console.log('Deleted ' + search); } function saveSearches(searches) { // saves an updated version of the searches to local storage localStorage.setItem('rule34SavedSearches', JSON.stringify(searches)); } function addSearch(search) { let searches = getSavedSearches(); searches.push(search); saveSearches(searches); } // function exportSearches() { // gets the local storage and logs it to the console as a string // let searches = localStorage.getItem('rule34SavedSearches'); // console.log(searches); // Don't need to stringify here the localstorage got it stringified // navigator.clipboard.writeText(searches); // alert("Copied searches to clipboard"); // } // function importSearches() { // takes an inputted array string and overwrites the local storage with it // let input = window.prompt("Enter previously exported searches"); // window.prompt seems to return a double-escaped string // let data = JSON.parse(input); // due to this, we need to de-escape twice to get the actual json // let current_searches = getSavedSearches(); // for(let index = 0; index < data.length; index++) { // if(current_searches.includes(data[index])) { // continue; // } else { // current_searches.push(data[index]); // console.log("New artist: " + data[index]); // } // } // localStorage.setItem('rule34SavedSearches', JSON.stringify(current_searches)); // } // button logic function createA(target) { let href = createLink(target); let a = document.createElement("a"); a.href = href; a.innerHTML = target; a.style.overflow = "hidden"; return a; } function createLink(target) { return "index.php?page=post&s=list&tags=" + target; } function createAddButton(search) { let button = document.createElement("button"); button.innerHTML = "Save search"; button.style.width = "100%"; button.addEventListener("click", function() {console.log("adding Search.."); addSearch(search)}); return button; } (function() { 'use strict'; let [should_display_elements, search_value] = should_display(); if (should_display_elements) { let addButton = createAddButton(search_value); let collapsable = document.createElement("details"); let collapsable_name = document.createElement("summary"); collapsable_name.innerHTML = "Saved"; collapsable.style.maxHeight = "50vh"; collapsable.style.overflow = "hidden scroll"; collapsable.style.textOverflow = "ellipsis"; collapsable.style.whiteSpace = "nowrap"; collapsable.style.scrollbarWidth = "thin"; collapsable.appendChild(collapsable_name); let searches = getSavedSearches(); let linebreak = document.createElement("br"); for (let i = 0; i < searches.length; i++) { collapsable.appendChild(createA(searches[i])); collapsable.appendChild(linebreak.cloneNode()); } let search_bar = document.getElementsByClassName("tag-search")[0]; search_bar.append(addButton); search_bar.append(collapsable); } })();