Add button on exhentai searchbox from tag button

Add your favorite keyword/tag on the searchbox from tag button

当前为 2022-12-03 提交的版本,查看 最新版本

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Add button on exhentai searchbox from tag button
// @description  Add your favorite keyword/tag on the searchbox from tag button
// @license      MIT
// @version      0.2
// @match        https://exhentai.org/g/*
// @run-at       context-menu
// @namespace https://greasyfork.org/users/383371
// ==/UserScript==


function capitalize(str) {
   var tmp = str.toLowerCase().split(' ');
   for(let i = 0; i < tmp.length; i++) {
       tmp[i] = tmp[i].charAt(0).toUpperCase() + tmp[i].substring(1);
   }
   return tmp.join(' ');
}

function add_tag(tag, name){
    let config = JSON.parse(window.localStorage.getItem('config'));
    if(!config){
        config = [];
    }
    config.push([tag, name]);
    window.localStorage.setItem('config', JSON.stringify(config));
}

(function() {
    if(document.activeElement.id.substring(0, 2) == 'ta'){
        let tag = document.activeElement.href.substring(document.activeElement.href.indexOf('tag/') + 4).replaceAll('+', ' ');
        let tmp = tag.split(':');
        let tag_namespace = tmp[0];
        let tag_value = tmp[1];
        tag_value += '$';
        if(tag_value.includes(' ')){
            tag_value = `"${tag_value}"`;
        }
        let name = prompt('name', capitalize(document.activeElement.innerText));
        if(!name){
            return;
        }
        add_tag(`${tag_namespace}:${tag_value}`, name);
        alert(`${tag_namespace}:${tag_value} added`);
    }
})();