kp4jd2

Generate a list of links for JD2 from kemono posts.

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