ehAutoStar

EH画廊自动/批量评分脚本

2021-08-24 या दिनांकाला. सर्वात नवीन आवृत्ती पाहा.

  1. // ==UserScript==
  2. // @name ehAutoStar
  3. // @namespace moe.cangku.mengzonefire
  4. // @version 1.1.1
  5. // @description EH画廊自动/批量评分脚本
  6. // @author mengzonefire
  7. // @require https://cdn.jsdelivr.net/npm/sweetalert2@9
  8. // @require https://cdn.staticfile.org/jquery/3.6.0/jquery.min.js
  9. // @require https://cdn.jsdelivr.net/npm/jquery-migrate
  10. // @match *://exhentai.org/g*
  11. // @match *://e-hentai.org/g*
  12. // @match *://exhentai.org/uploader/*
  13. // @match *://e-hentai.org/uploader/*
  14. // @grant GM_setValue
  15. // @grant GM_getValue
  16. // @run-at document-end
  17. // ==/UserScript==
  18. const href = window.location.href;
  19. const defRateMap = "BlossomPlus 5"
  20. !function () {
  21. 'use strict'
  22. var rating_img;
  23. var uploader;
  24. var my_apikey;
  25. var my_apiuid;
  26. var g_flag;
  27. var link_ele;
  28. var star_ele;
  29. var GaInfo;
  30. var count = 0;
  31. var fail_count = 0;
  32. var domain = href.indexOf("exhentai")!=-1?"exhentai":"e-hentai";
  33. var rateMapText = GM_getValue("rateMap");
  34. var rateMap = [];
  35. var icon_url = domain=="exhentai"?"https://exhentai.org/img/mr.gif":"https://ehgt.org/g/mr.gif"
  36. var html_btn = '<div style="float:left">&nbsp; <a id="rateSetting" href="#">';
  37. html_btn += `<img src="${icon_url}"> 自动评分设置`;
  38. html_btn += '</a></div>';
  39. var html_btn2 = '<input type="button" value="一键评分" id="autoRate">';
  40. var html_input = '<input type="text" id="inputRate" value="5" size="4" maxlength="3" style="width:22px">';
  41. if (!rateMapText){
  42. rateMapText = defRateMap;
  43. GM_setValue("rateMap", rateMapText);
  44. }
  45. readRateMap();
  46. if (href.indexOf("/uploader/")!=-1) {
  47. g_flag = false;
  48. let loop = setInterval(() => {
  49. var html_tag2 = $('#dms');
  50. if (!html_tag2.length) return fasle;
  51. html_tag2.append(html_btn2);
  52. html_tag2.append(html_input);
  53. $("#autoRate").click(function () {
  54. batchRating();
  55. });
  56. clearInterval(loop);
  57. },500);
  58. }
  59. else if (href.indexOf("/g/")!=-1) {
  60. var style;
  61. g_flag = true;
  62. my_apikey = apikey;
  63. my_apiuid = apiuid;
  64. if(domain=="exhentai"){
  65. style='<style>.swal2-textarea{color:#ffffff;background-color:#43464e}</style>';
  66. }else{
  67. style='<style>.swal2-textarea{color:#000000;background-color:#f3f0e0}</style>';
  68. }
  69. var ele=document.createElement('div');
  70. ele.innerHTML=style;
  71. document.getElementsByTagName('head')[0].appendChild(ele.firstElementChild);
  72. let loop1 = setInterval(() => {
  73. var html_tag = $("#gdr");
  74. if (!html_tag.length) return false;
  75. html_tag.append(html_btn);
  76. $("#rateSetting").click(function () {
  77. rateSetting();
  78. });
  79. clearInterval(loop1);
  80. }, 500);
  81. let loop2 = setInterval(() => {
  82. uploader = $("#gdn>a")[0].innerText;
  83. rating_img = $("#rating_image")[0];
  84. if (!uploader||!rating_img) return false;
  85. else if (rating_img.className=='ir'
  86. &&rateMap.hasOwnProperty(uploader)){
  87. rating(rateMap[uploader], -1);
  88. }
  89. clearInterval(loop2);
  90. }, 500);
  91. if (apikey!=GM_getValue("apikey")) {
  92. GM_setValue('apikey', apikey);
  93. }
  94. if (apiuid!=GM_getValue("apiuid")) {
  95. GM_setValue('apiuid', apiuid);
  96. }
  97. }
  98. function rating(rate, recu) {
  99. if (recu==-1) GaInfo = href.match(/\/g\/([\d]+)\/([\da-f]+)\//);
  100. else {
  101. if(recu==star_ele.length){
  102. Swal.fire(`一键评分完成,共评分${count}个画廊,失败${fail_count}个`);
  103. return true;
  104. }
  105. if(star_ele[recu].className == "ir") {
  106. rating_img = star_ele[recu];
  107. GaInfo = link_ele[recu].href.match(/\/g\/([\d]+)\/([\da-f]+)\//);
  108. }else{
  109. rating(rate, recu+1);
  110. return false;
  111. }
  112. }
  113. $.ajax({
  114. url: '/api.php',
  115. type: 'POST',
  116. contentType: 'application/json',
  117. dataType: 'json',
  118. data: JSON.stringify({
  119. apikey: my_apikey,
  120. apiuid: my_apiuid,
  121. gid: Number(GaInfo[1]),
  122. method: "rategallery",
  123. rating: rate*2,
  124. token: GaInfo[2]
  125. })
  126. }).success(function(r) {
  127. console.log(r);
  128. if(!r['error']){
  129. var n1 = Math.ceil(rate-5)*16;
  130. var n2 = rate%1?-21:-1;
  131. rating_img.setAttribute('style', `background-position: ${n1}px ${n2}px;`);
  132. rating_img.className=r["rating_cls"];
  133. if(recu==-1){
  134. $("#rating_label")[0].innerText = `平均值:${r["rating_avg"]}`;
  135. $("#rating_count")[0].innerText = r["rating_cnt"];
  136. }
  137. }
  138. }).fail(function(r) {
  139. console.log(r);
  140. fail_count += 1;
  141. }).always(function() {
  142. count += 1;
  143. if(recu!=-1) rating(rate, recu+1);
  144. });
  145. }
  146. function rateSetting(){
  147. Swal.fire({
  148. title: '输入自动评分配置\n格式:上传者 分数(0.5-5)',
  149. input: 'textarea',
  150. inputValue: GM_getValue("rateMap"),
  151. showCancelButton: true,
  152. confirmButtonText: '确定',
  153. cancelButtonText: '取消',
  154. inputValidator: (value) => {
  155. rateMapText = value;
  156. var errNum = readRateMap();
  157. if (errNum!=-1) {
  158. return `第{${errNum+1}行格式错误,分数必须为0.5的整数倍`;
  159. }
  160. }
  161. }).then((result) => {
  162. if (result.dismiss) return;
  163. GM_setValue("rateMap", rateMapText);
  164. })
  165. }
  166. function readRateMap(){
  167. var mapLine = rateMapText.split('\n');
  168. for (var line of mapLine)
  169. {
  170. var result = line.match(/([\s\S]+) ((?:[0-4].5)?[1-5]?)$/);
  171. if (result) rateMap[result[1]] = Number(result[2]);
  172. else return mapLine.indexOf(line);
  173. }
  174. return -1;
  175. }
  176. function batchRating(){
  177. if (GM_getValue("apiuid")) {
  178. my_apikey = GM_getValue("apikey");
  179. my_apiuid = GM_getValue("apiuid");
  180. }
  181. else{
  182. Swal.fire("api参数未记录,请先登录并进入任意画廊,脚本会自动记录参数,然后再使用此功能");
  183. return false;
  184. }
  185. if (my_apiuid!=Number(getCookie("ipb_member_id"))){
  186. Swal.fire("api参数不匹配,请先进入任意画廊,脚本会自动刷新参数,然后再使用此功能");
  187. return false;
  188. }
  189. var select_ele = $("#dms > div > select > option");
  190. var select_flag = getSelect(select_ele);
  191. switch (select_flag){
  192. case 'm':
  193. case 'p':
  194. star_ele = $("td.gl4m > div");
  195. link_ele = $("td.gl3m.glname > a");
  196. break;
  197. case 'l':
  198. star_ele = $("td.gl2c > div:nth-child(3) > div.ir");
  199. link_ele = $("td.gl3c.glname > a");
  200. break;
  201. case 'e':
  202. star_ele = $("td.gl2e > div > div > div.ir");
  203. link_ele = $("td.gl2e > div > a");
  204. break;
  205. case 't':
  206. star_ele = $("div.gl5t > div:nth-child(2) > div.ir");
  207. link_ele = $("div.itg.gld > div > a");
  208. break;
  209. default:
  210. Swal.fire("一键评分失败:select元素错误");
  211. }
  212. if (link_ele.length != star_ele.length){
  213. Swal.fire("一键评分失败:html元素错误");
  214. }
  215. else{
  216. var my_rate = Number($("#inputRate")[0].value);
  217. if(my_rate>0&&my_rate<=5&&my_rate%0.5==0){
  218. rating(my_rate, 0)
  219. }
  220. else{
  221. Swal.fire("分数错误:数值必须在0.5-5之间且为0.5的整数倍");
  222. }
  223. }
  224. }
  225. function getCookie(cookie_name) {
  226. var allcookies = document.cookie;
  227. var cookie_pos = allcookies.indexOf(cookie_name);
  228. if (cookie_pos != -1) {
  229. cookie_pos = cookie_pos + cookie_name.length + 1;
  230. var cookie_end = allcookies.indexOf(";", cookie_pos);
  231. if (cookie_end == -1) cookie_end = allcookies.length;
  232. var value = unescape(allcookies.substring(cookie_pos, cookie_end));
  233. }
  234. return value;
  235. }
  236. function getSelect(select_ele){
  237. for (var i = 0; i < select_ele.length; i++){
  238. if (select_ele[i].getAttribute("selected")){
  239. return select_ele[i].getAttribute("value");
  240. }
  241. }
  242. return null;
  243. }
  244. }();