kp4jd2

Generate a list of links for JD2 from kemono posts.

As of 2023-08-04. See the latest version.

  1. // ==UserScript==
  2. // @name kp4jd2
  3. // @namespace https://sleazyfork.org/en/scripts/441628-kp4jd2
  4. // @version 0.33
  5. // @description Generate a list of links for JD2 from kemono posts.
  6. // @author You
  7. // @match https://kemono.party/*/user/*/post/*
  8. // @icon https://www.google.com/s2/favicons?domain=kemono.party
  9. // @require http://code.jquery.com/jquery-latest.min.js
  10. // @license MIT
  11. // @grant GM.getValue
  12. // @grant GM.setValue
  13. // ==/UserScript==
  14. var $ = window.jQuery;
  15.  
  16. (function() {
  17. 'use strict';
  18.  
  19. // Default ignore post thumb behavior
  20. let iPT = GM.getValue('kp_ipt', true).then((kp_ipt) => { iPT = kp_ipt; });
  21.  
  22.  
  23. $(document).ready(function () {
  24. $(".post__header").after("<div class='kpdlh'></div>");
  25. $(".kpdlh").append(`<button class="kpdl" style="vertical-align:middle">Generate List for JD2</button>`).css("padding","0.5rem");
  26. $(".kpdl").click(function() {genList();});
  27.  
  28. $(".kpdlh").append(`<input class="kpit" type="checkbox">`).append(`<label>Ignore post thumb</label>`);
  29. $('.kpdlh').children().css('vertical-align', 'middle');
  30. $('.kpit').css({'width':'16px','height':'16px','margin':'4px'});
  31. $('.kpit').prop('checked', GM.getValue('kp_ipt', true).then((kp_ipt) => { $(".kpit").prop('checked', kp_ipt); }));
  32. $('.kpit').on('change', () => {GM.setValue("kp_ipt", $('.kpit').prop('checked')); GM.getValue('kp_ipt', true).then((kp_ipt) => { iPT = kp_ipt; } );});
  33.  
  34. function genList() {
  35. let srcList = "";
  36. let idx = 0;
  37. let imgcount = $(".post__files .post__thumbnail a.image-link").length;
  38.  
  39. $(".post__files .post__thumbnail a.image-link").each(function() {
  40. let tmtl = $(this).attr("href");
  41. let tmfi = tmtl.lastIndexOf("?f=") != -1 ? tmtl.lastIndexOf("?f=") : tmtl.length;
  42. let tmei = tmtl.lastIndexOf(".") + 1;
  43. let tmnf = tmtl.slice(tmfi);
  44. let tmex = tmtl.substr(tmei);
  45. tmtl = tmtl.slice(0,tmfi);
  46.  
  47. let kpid = window.location.pathname;
  48. kpid = kpid.substr(kpid.lastIndexOf("/")+1);
  49. let lidx = idx.toString().padStart(Math.max(2,imgcount.toString().length),'0');
  50.  
  51. if (iPT === true && lidx == "00") {
  52. console.log(`${kpid}_${lidx} ignored.`);
  53. idx += 1;
  54. } else {
  55. //jd2 for some reason dislikes .jpe files
  56. if (tmex == "jpe") tmex = "jpeg";
  57. let base = ""; // "https://kemono.party"
  58. //console.log(tmtl);
  59. let url = base+tmtl+"?f="+kpid+"_"+lidx+"."+tmex;
  60. srcList += url + "\n";
  61. idx += 1;
  62. }
  63. });
  64.  
  65. $(".post__attachment a.post__attachment-link").each(function() {
  66. let tmtl = $(this).attr("href");
  67. let url = "https://kemono.party"+tmtl;
  68. srcList += url + "\n";
  69. });
  70.  
  71. srcList += $.trim($(".post__title").text());
  72. navigator.clipboard.writeText(srcList);
  73.  
  74. $(".kpdlh").append(`<span class="kpdlfb">List copied to Clipboard.</span>`);
  75. $(".kpdlfb").css("margin-left","0.5rem");
  76. setTimeout(function() {
  77. $(".kpdlfb").fadeOut(500, function() {
  78. $(".kpdlfb").remove()});
  79. }, 2000);
  80. }
  81. });
  82. })();