Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> [Script] Search bar with tags and autocomplete

 
post Oct 25 2020, 16:11
Post #1
ciccabanana



Lurker
Group: Recruits
Posts: 8
Joined: 7-September 17
Level 48 (Artisan)


The script replace the normal search bar with new one whit autocomplete of tags.

I often use the search bar and write the complete definition of the tag each time is boring. To make faster and easier I made a script that allows me search the tag through the site api.

Here is the script: [github.com] https://github.com/ciccabanana/e-hentai-hel...-helper.user.js
There is some documentation: [github.com] https://github.com/ciccabanana/e-hentai-helper-suite/
For any issue: [github.com] https://github.com/ciccabanana/e-hentai-helper-suite/issues

Preview gif:
(IMG:[github.com] https://github.com/ciccabanana/e-hentai-helper-suite/raw/master/images/tag-helper.webp)

Features
  • Compatible with Tampermonkey, Greasemonkey and Violentmonkey
  • Autocomplete of tags using site API
  • Delayed API request during typing and caching for avoid server restriction
  • Possibility of save favorites tags as bookmarks
  • Support the Exclusion `-` and the OR `~` operator See the ehwiki
    Supprot all qualifiers (tag, weak, title, uploader, uploaduid, gid, comment, favnote) (see below ↓ #Qualifiers)
  • Fast autocomplete using category index (ignore case) (see below #Namespaces)
  • Colored tags by qualifier or namespace (Color inspired by website colors of class i.e. color of class Doujinshi is used for female tags ecc...)
  • Settings interface (see below ↓ #settings-ui-preview)
  • Keyboard and mouse shortcut
  • Fast loading, the script will load alongside the website
  • No duplicate allowed.
  • Works both in front page and favorites search bar.
  • Works on both e-hentai and sadpanda.

Cache
This feature allows the program to save user's inputs and corresponding server responses by creating a cache. If the user re-enters the same input, the response is delivered more quickly from the cache, without needing to query the API again.
Users have the option to clear all cached data at any time or to remove only the data that is older than a specified number of days, with the ability to choose the number of days themselves.
(IMG:[github.com] https://github.com/ciccabanana/e-hentai-helper-suite/raw/master/images/tag-helper-settings-cache.png)

Bookmarks
This feature allows users to save their favorite tags and access them quickly from a dropdown menu that appears beneath the search bar when it gains focus. Users can easily add or remove favorites either through the settings or directly while searching for a tag by clicking on the bookmark icon or using the Ctrl+B keyboard shortcut.
Favorites can be saved with full details, including Namespace, Qualifiers, Exclusion operators (-), and OR operators (~). The feature supports a maximum of 50 favorite tags, with the top 25 being displayed in the dropdown menu for quick access.
Users can also reorder their favorites through the settings using a simple drag-and-drop interface.
(IMG:[github.com] https://github.com/ciccabanana/e-hentai-helper-suite/raw/master/images/tag-helper-settings-bookmarks.webp)

Namespaces: (For more info See the ehwiki)
  • a: => artist
  • c: => character
  • co: => cosplayer
  • f: => female
  • g: => group
  • l: => language
  • m: => male
  • x: OR mix: => mixed
  • o: other
  • p: => parody
  • r: => reclass
  • mis: => temp

Qualifiers: (For more info See the ehwiki)
⚠️ N.B. Only the qualifier "tag" and "weak" have the autocomplete feature.
  • tg: => tag
  • wk: => weak
  • tt: OR ti: => title
  • up: => uploader
  • upd: => uploaduid
  • gd: => gid
  • m: => comment
  • fv: OR fav: => favnote

Settings:
(IMG:[github.com] https://github.com/ciccabanana/e-hentai-helper-suite/raw/master/images/tag-helper-settings.png)

Shortcut:
  • Dropdown
    • ↑ ↓ - Navigate the list
    • Ctrl+B - Add/Remove bookmarks
  • Tag
    • Middle click on a tag will remove the tag
    • Left click will rotate between operator. Normal → Exclusion (-) → OR (~) → Normal

FQA:
  • Q: Why a not an hardcoded cache or favorites?
    • A: Because if a user edit the code, for insert his favorites, the next update of the script will probably overwrite the changes done from the user. (It depends on with userscript managers the user use)

ToDo
  • Settings interface Done
  • Possibility of user to personalize tags color Done
  • Support for Qualifiers "tag:" / "weak:" / "title:" / "uploader:" / "uploaduid:" / "gid:" / "comment:" / "favnote:" Done
  • The possibility of change the keyboard shortcut
  • An option for enable an automatic clear of expired data in the cache (If users request this feature)
  • Compatibility to work in the insertion of new tags on the gallery page (Under evaluation)
Known bugs
  • ...

Thanks to
  • [github.com] yairEO For making Tagify, foundation on which I built this userscript
  • [github.com] SortableJS For making the script that allow to reorder the bookmarks


This post has been edited by ciccabanana: Aug 18 2024, 17:24
User is online!Profile CardPM
Go to the top of the page
+Quote Post

 
post Oct 26 2020, 10:40
Post #2
Rikis



Bringer of Light
********
Group: Gold Star Club
Posts: 3,680
Joined: 7-July 09
Level 500 (Godslayer)


QUOTE(ciccabanana @ Oct 25 2020, 17:11) *
There is some documentation: [github.com] https://github.com/ciccabanana/e-hentai-hel...-helper.user.js

Wrong link.


Here is mine: [github.com] https://github.com/RikisX/eHentai-Autocompl...omplete.user.js
It feels much faster.

This post has been edited by Rikis: Oct 26 2020, 11:40
User is offlineProfile CardPM
Go to the top of the page
+Quote Post

 
post Oct 26 2020, 13:55
Post #3
ciccabanana



Lurker
Group: Recruits
Posts: 8
Joined: 7-September 17
Level 48 (Artisan)


QUOTE(Rikis @ Oct 26 2020, 09:40) *

Wrong link.

Thanks dude, I've copied and pasted 2 time the same link xD

QUOTE(Rikis @ Oct 26 2020, 09:40) *

Here is mine: [github.com] https://github.com/RikisX/eHentai-Autocompl...omplete.user.js
It feels much faster.

Sorry dude, but the script you linked over there looks like a copy and paste of the script used in the page Mytags.
i.e. https://e-hentai.org/z/0348/ehg_mytags.c.js

If the problem is a slow reaction of my script during typing, I can try to reduce the delay between typing and api requests.
(Stop typing) -> (Wait some time to see if the user has really ended typing) -> (Make api request)
I have inserted this delay to prevent too much request during typing.
Without this delay my script as yours (Yes, I tested it) will make at least 2 requests even if you type quickly. That is why I preferred to avoid it, adding a delay.

If the problem is the loading time inside the website I can try to optimize it.
If you want to be more meticulous you can to enable the debug mode of my script, changing to true [github.com] line:26 ('var debug = false;' => 'var debug = true;') and tell me the loading time of the script on your PC. Please update to latest version (0.1.3) to get the message as in the example below.
Example: [Tags Auto]: Loading time: 33.486083984375 ms

For any issue or feature request please, reply to this post or better go and open an issue on GitHub: [github.com] https://github.com/ciccabanana/e-hentai-helper-suite/issues



User is online!Profile CardPM
Go to the top of the page
+Quote Post

 
post Oct 26 2020, 14:27
Post #4
Rikis



Bringer of Light
********
Group: Gold Star Club
Posts: 3,680
Joined: 7-July 09
Level 500 (Godslayer)


Yeah it's copy paste.
Dropdown opening and closing doesn't help. Doesn't look smooth like mytags one.
User is offlineProfile CardPM
Go to the top of the page
+Quote Post

 
post Oct 26 2020, 22:04
Post #5
ciccabanana



Lurker
Group: Recruits
Posts: 8
Joined: 7-September 17
Level 48 (Artisan)


QUOTE(Rikis @ Oct 26 2020, 13:27) *

Yeah it's copy paste.
Dropdown opening and closing doesn't help. Doesn't look smooth like mytags one.

Ok now I have understand what is the problem.
The problem was if the dropdown was already show and was type another letter, the dropdown menu disappeared and was completely reloaded.

I fixed this bug in the latest version, please check if smooth as you would like.
User is online!Profile CardPM
Go to the top of the page
+Quote Post

 
post Oct 26 2020, 22:45
Post #6
Rikis



Bringer of Light
********
Group: Gold Star Club
Posts: 3,680
Joined: 7-July 09
Level 500 (Godslayer)


Looks nice (IMG:[invalid] style_emoticons/default/happy.gif)
User is offlineProfile CardPM
Go to the top of the page
+Quote Post

 
post Oct 26 2020, 23:42
Post #7
uareader



Critter
*********
Group: Catgirl Camarilla
Posts: 5,592
Joined: 1-September 14
Level 500 (Ponyslayer)


I'm not sure how this work, so maybe my proposal don't make sense, but it could be good if the system had both a softcoded and hardcoded cache system for autocompletion.

The softcoded cache would record what text you had typed before choosing something for the list, and the corresponding choice in the dropdown, so it can reload it faster during that browser session.

The hardcoded cache would be a list directly typed in the script code by the user, allowing him to put his favorites tags so that it's quickly available permanently and on every session, since it's hardcoded.
User is offlineProfile CardPM
Go to the top of the page
+Quote Post

 
post Aug 2 2021, 22:08
Post #8
diyer



Newcomer
**
Group: Members
Posts: 51
Joined: 15-January 14
Level 238 (Godslayer)


thank your script.
(IMG:[invalid] style_emoticons/default/smile.gif)
would it add a new feature and work for vote tag? i think it may be cooler. (IMG:[invalid] style_emoticons/default/tongue.gif)
i changed a bit(only id) below, script of Rikis.
---------

PENGUIN EDIT: for reasons

CODE

// ==UserScript==
// @name         EH Gallery AutoComplete
// @namespace    E-Hentai
// @version      0.2
// @encoding     utf-8
// @description  autocomple for tags
// @author       Rikis
// @match        https://e-hentai.org/g/*
// @match        https://e-hentai.org/g/*
// @connect      self
// @connect      e-hentai.org
// @connect      *
// @grant        none
// ==/UserScript==


if (typeof tagcompleter !== 'undefined') return;


(()=>{

    let style = document.createElement('style');
    style.innerHTML =
        '.tagcomplete{position:relative;display:inline-block}.tagcomplete-items{position:absolute;border:1px solid '+
        '#B5A4A4;border-top:none;border-bottom:none;z-index:99;margin-left:60px;width:323px}.tagcomplete-items div{padding:10px;'+
        'cursor:pointer;background-color:#EDEBDF;text-align:left}.tagcomplete-items div:not(:last-child){border-bottom:1px solid '+
        '#D4D4D4}.tagcomplete-items div:last-child{border-bottom:1px solid #B5A4A4}.tagcomplete-items div:hover{'+
        'background-color:#F3F0E0}.tagcomplete-active{background-color:#5C0D12!important;color:#EDEBDF};';
    document.head.appendChild(style);

    const api_url = "https://api.e-hentai.org/api.php";

    function api_call(b, a, c) {
        b.open("POST", api_url);
        b.setRequestHeader("Content-Type", "application/json");
        b.withCredentials = true;
        b.onreadystatechange = c;
        b.send(JSON.stringify(a));
    }
    function api_response(b) {
        if (b.readyState == 4) {
            if (b.status == 200) {
                var a = JSON.parse(b.responseText);
                if (a.login != undefined) {
                    top.location.href = 'https://e-hentai.org/home.php';
                } else {
                    return a;
                }
            } else {
                console.error("Server communication failed: " + b.status + " (" + b.responseText + ")");
            }
        }
        return false;
    }


    var tagcomplete_focus = -1;
    function tagcompleter(j) {
        let l = undefined;
        let g = undefined,
            f = undefined;
        let e = undefined;
        function d(m) {
            if (e === m) {
                return;
            }
            e = m;
            if (g != undefined) {
                if (f != undefined) {
                    return;
                } else {
                    clearTimeout(g);
                    g = undefined;
                }
            }
            setTimeout(function () {
                f = new XMLHttpRequest();
                let n = { method: "tagsuggest", text: m };
                api_call(f, n, h);
            }, 200);
        }
        function h() {
            var m = api_response(f);
            if (m != false) {
                if (m.error != undefined) {
                    console.error(m.error);
                } else {
                    if (tagcomplete_focus < 0) {
                        a();
                        l = m.tags;
                    }
                }
                f = undefined;
                k();
            }
        }
        function k() {
            a();
            var n = j.value.replace(/["\']/g, "");
            if (n.match(/^(x|mi).*:/)) {
                n = n.replace(/^(x|mi).*:/, "misc:");
            } else {
                n = n
                    .replace(/^f.*:/, "female:")
                    .replace(/^m.*:/, "male:")
                    .replace(/^r.*:/, "reclass:")
                    .replace(/^l.*:/, "language:")
                    .replace(/^p.*:/, "parody:")
                    .replace(/^c.*:/, "character:")
                    .replace(/^g.*:/, "group:")
                    .replace(/^a.*:/, "artist:");
            }
            if (n.replace(/^.*:/, "").length < 2) {
                return false;
            } else {
                d(n);
            }
            if (l == undefined) {
                return false;
            }
            tagcomplete_focus = -1;
            var t = document.createElement("DIV");
            t.setAttribute("id", j.id + "tagcomplete-list");
            t.setAttribute("class", "tagcomplete-items");
            j.parentNode.appendChild(t);
            var o = 0;
            var p = new RegExp("(^| |:)" + n, "ig");
            for (var tagid in l) {
                var q = l[tagid].ns + ':' + l[tagid].tn + '';
                var m = l[tagid].ns + ':"' + l[tagid].tn + '$"';
                if (q.match(p)) {
                    var u = l[tagid].mid != undefined ? l[tagid].mns + ":" + l[tagid].mtn : undefined;
                    var r = u == undefined ? q : q + " <strong>=></strong> " + u;
                    // var m = u == undefined ? q : u;
                    var s = document.createElement("DIV");
                    s.innerHTML = r.replace(p, "<strong>$&</strong>");
                    s.setAttribute("data-value", m);
                    s.addEventListener("click", function (v) {
                        j.value = this.getAttribute("data-value");
                        a();
                        var elem=document.getElementById("newtagfield");
                        elem.focus();
                    });
                    t.appendChild(s);
                    ++o;
                }
            }
            if (o > 0) {
                j.style.borderRadius = "3px 3px 0 0";
            }
        }
        j.addEventListener("input", function (m) {
            k();
        });
        j.addEventListener("keydown", function (n) {
            if (l == undefined) {
                return;
            }
            var m = document.getElementById(this.id + "tagcomplete-list");
            if (m) {
                m = m.getElementsByTagName("div");
            }
            if (n.keyCode == 40) {
                ++tagcomplete_focus;
                b(m);
            } else {
                if (n.keyCode == 38) {
                    --tagcomplete_focus;
                    b(m);
                } else {
                    if (n.keyCode == 13) {
                        // n.preventDefault();
                        if (m && tagcomplete_focus > -1) {
                            m[tagcomplete_focus].click();
                        }
                    }
                }
            }
        });
        function b(m) {
            if (!m) {
                return false;
            }
            c(m);
            if (tagcomplete_focus >= m.length) {
                tagcomplete_focus = 0;
            }
            if (tagcomplete_focus < 0) {
                tagcomplete_focus = m.length - 1;
            }
            m[tagcomplete_focus].classList.add("tagcomplete-active");
        }
        function c(m) {
            for (var n = 0; n < m.length; n++) {
                m[n].classList.remove("tagcomplete-active");
            }
        }
        function a(o) {
            j.style.borderRadius = "";
            var m = document.getElementsByClassName("tagcomplete-items");
            for (var n = 0; n < m.length; n++) {
                if (o != m[n] && o != j) {
                    m[n].parentNode.removeChild(m[n]);
                }
            }
        }
        document.addEventListener("click", function (m) {
            a(m.target);
        });
    }

    var elem=document.getElementById("newtagfield");
    elem.autocomplete = "off"
    tagcompleter(elem)

})();



This post has been edited by blue penguin: Aug 2 2021, 23:02
User is offlineProfile CardPM
Go to the top of the page
+Quote Post

 
post Aug 2 2021, 23:04
Post #9
blue penguin



in umbra, igitur, pugnabimus
***********
Group: Gold Star Club
Posts: 10,046
Joined: 24-March 12
Level 500 (Godslayer)


Apart from a few edits I needed to make, don't use @icon if you value the users of the script.

I do not like the idea of someone who owns an s2 bucket getting my EH browsing history.
User is offlineProfile CardPM
Go to the top of the page
+Quote Post

 
post Aug 2 2021, 23:26
Post #10
diyer



Newcomer
**
Group: Members
Posts: 51
Joined: 15-January 14
Level 238 (Godslayer)


QUOTE(blue penguin @ Aug 2 2021, 23:04) *

Apart from a few edits I needed to make, don't use @icon if you value the users of the script.

I do not like the idea of someone who owns an s2 bucket getting my EH browsing history.

I didn't consider that aspect, sorry. (IMG:[invalid] style_emoticons/default/anime_cry.gif)
User is offlineProfile CardPM
Go to the top of the page
+Quote Post

 
post Nov 22 2022, 21:21
Post #11
Jerrk



Newcomer
*
Group: Members
Posts: 47
Joined: 8-July 12
Level 11 (Novice)


Any chance for an update for the new search system?
User is offlineProfile CardPM
Go to the top of the page
+Quote Post

 
post Nov 25 2022, 16:38
Post #12
babydragon0123



Newcomer
**
Group: Gold Star Club
Posts: 55
Joined: 11-November 11
Level 500 (Ponyslayer)


QUOTE(ciccabanana @ Oct 25 2020, 21:11) *

The script replace the normal search bar with new one whit autocomplete of tags.

I often use the search bar and write the complete definition of the tag each time is boring. To make faster and easier I made a script that allows me search the tag through the site api.

E.g. If i want to search the english gallerys i will simply tap "eng" and select "language:english" from the dropdown.

P.s. I tried to make as few API requests as possible during typing using varius delay, at least one request is made.

Here is the script: [github.com] https://github.com/ciccabanana/e-hentai-hel...-helper.user.js
There is some documentation: [github.com] https://github.com/ciccabanana/e-hentai-helper-suite/
For any issue: [github.com] https://github.com/ciccabanana/e-hentai-helper-suite/issues

Preview gif:
(IMG:[github.com] https://github.com/ciccabanana/e-hentai-helper-suite/raw/master/images/tag-helper.gif)

Features
  • Compatible with Tampermonkey, Greasemonkey and Violentmonkey
  • Fast loading ~40ms
  • Autocomplete of tags using site API
  • Delayed API request during typing for avoid server overload
  • Fast autocomplete using category index (ignore case) (see below #Category-index)
  • Colored tags by category (Color inspired by website colors of class i.e. color of class Doujinshi is used for female tags ecc...)
  • No duplicate allowed.
  • Works both in front page and favorites search bar.
  • Works on both e-hentai and sadpanda.
Category index
  • f: => female
  • m: => male
  • l: => language
  • p: => parody
  • c: => character
  • g: => group
  • a: => artist
  • x: OR mi: => misc
ToDo
  • Settings interface
  • Possibility of user to personalize tags color
  • Compatibility to work in the insertion of new tags on the gallery page (Under evaluation)
Known bugs
  • ...


Thank you very much for your script. Can you update it to make it work with current site?
User is offlineProfile CardPM
Go to the top of the page
+Quote Post

 
post Jan 9 2023, 11:41
Post #13
defski



Newcomer
*
Group: Members
Posts: 39
Joined: 10-January 19
Level 109 (Lord)


Ditto, an update would be appreciated. I don't know what admin changed, but a bunch of my scripts stopped working.
User is offlineProfile CardPM
Go to the top of the page
+Quote Post

 
post Jan 9 2023, 12:10
Post #14
Mayriad



SUPER ★ BUSY ★ TIME
*******
Group: Global Mods
Posts: 2,061
Joined: 18-December 10
Level 135 (Lord)


QUOTE(defski @ Jan 9 2023, 09:41) *
Ditto, an update would be appreciated. I don't know what admin changed, but a bunch of my scripts stopped working.

The search engine was upgraded and a lot of things changed, so it is natural that many scripts will stop working without a code update. You can read about the search engine upgrade here: https://forums.e-hentai.org/index.php?showtopic=261743
User is offlineProfile CardPM
Go to the top of the page
+Quote Post

 
post Nov 20 2023, 16:03
Post #15
ciccabanana



Lurker
Group: Recruits
Posts: 8
Joined: 7-September 17
Level 48 (Artisan)


QUOTE(defski @ Jan 9 2023, 10:41) *

Ditto, an update would be appreciated. I don't know what admin changed, but a bunch of my scripts stopped working.


QUOTE(Mayriad @ Jan 9 2023, 11:10) *

The search engine was upgraded and a lot of things changed, so it is natural that many scripts will stop working without a code update. You can read about the search engine upgrade here: https://forums.e-hentai.org/index.php?showtopic=261743


Sorry for the delay, I had some personal business to do.
Soon I will update the script.
I found some bug with the new code and I will to fix it before the release.
User is online!Profile CardPM
Go to the top of the page
+Quote Post

 
post Dec 1 2023, 03:28
Post #16
ciccabanana



Lurker
Group: Recruits
Posts: 8
Joined: 7-September 17
Level 48 (Artisan)


As I announced, here is a brand new version. I hope you enjoy.
User is online!Profile CardPM
Go to the top of the page
+Quote Post

 
post Aug 18 2024, 17:28
Post #17
ciccabanana



Lurker
Group: Recruits
Posts: 8
Joined: 7-September 17
Level 48 (Artisan)


I released a new update with bookmarks (favorite) and a caching system.
User is online!Profile CardPM
Go to the top of the page
+Quote Post


Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 


Lo-Fi Version Time is now: 31st March 2025 - 21:37