Advertisement
Guest User

exhentai tag userscript

a guest
Apr 26th, 2019
243
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name         Tag Previewer
  3. // @namespace    http://tampermonkey.net/
  4. // @version      0.1
  5. // @description  Preview tags
  6. // @author       Anon
  7. // @include      /^(http(s)?://)?exhentai.org/?.*/
  8. // @grant        none
  9. // @require      https://code.jquery.com/jquery-3.4.0.min.js
  10. // ==/UserScript==
  11.  
  12. $(document).ready(function() {
  13.     // first selector is for thumbnail view, second is for extended
  14.     $( "div.gl1t, td.gl1e" ).each( function( index, element ){
  15.         // combined namespace + all tags into one string to display at end
  16.         var combined = "";
  17.         // store the link to the actual doujin so we can pull tags
  18.         var href = $(element).find('a').attr('href');
  19.         // store the img since we will modify its title later
  20.         var img = $(element).find('img');
  21.         // delay is in ms, timeout is so we don't instally pull tags when we mouse over stuff
  22.         var delay=1, setTimeoutConst;
  23.         var loaded = false;
  24.         $(img).on("mouseenter", function() {
  25.             // if alread pulled tags, don't do it again. be nice to their servers
  26.             if (loaded) {
  27.                 return;
  28.             }
  29.             // start a timer, once 'delay' ms have happened, get tags
  30.             setTimeoutConst = setTimeout(function() {
  31.                        $.ajax({
  32.                            // make a get request to the doujin page to pull tags
  33.                            url: href,
  34.                            type: 'GET',
  35.                            success: function(res) {
  36.                                // get the parent element of each namespace + list of tags
  37.                                $(res).find('div#taglist table tbody tr').each( function( index, element ) {
  38.                                    // separate namespace and tags since we add to the string differently
  39.                                    var namespace = $(element).find('td.tc');
  40.                                    var tag = $(element).find("div");
  41.                                    combined += $(namespace).text() + ' ';
  42.                                    // iterate tags and add to string
  43.                                    $(tag).each(function( index, element ) {
  44.                                        combined += $(element).text() + ', ';
  45.                                    });
  46.                                    //strip last ', ' and add a newline
  47.                                    combined = combined.substring(0, combined.length - 2) + '\n';
  48.                                });
  49.                                //strip the last '\n'
  50.                                combined = combined.substring(0, combined.length - 1);
  51.                                $(img).prop('title', combined);
  52.                            }
  53.                        });
  54.                 loaded = true;
  55.             }, delay);
  56.         }).on("mouseleave", function() {
  57.             // if we moved mouse out of image before 'delay' ms, reset the timer
  58.             clearTimeout(setTimeoutConst);
  59.         });
  60.     });
  61. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement