nastoolNameTest

NasTools名称测试划词版

  1. // ==UserScript==
  2. // @name nastoolNameTest
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.6
  5. // @description NasTools名称测试划词版
  6. // @author yubanmeiqin9048
  7. // @match https://*/details.php?id=*
  8. // @match https://*/details_movie.php?id=*
  9. // @match https://*/details_tv.php?id=*
  10. // @match https://*/details_animate.php?id=*
  11. // @match https://bangumi.moe/*
  12. // @match https://*.acgnx.se/*
  13. // @match https://*.dmhy.org/*
  14. // @match https://nyaa.si/*
  15. // @match https://mikanani.me/*
  16. // @match https://*.skyey2.com/*
  17. // @grant GM_log
  18. // @grant GM_xmlhttpRequest
  19. // @connect *
  20. // @license MIT
  21. // ==/UserScript==
  22.  
  23.  
  24. (function () {
  25. 'use strict';
  26. //nastool地址
  27. const nastoolUrl = 'http://localhost:3000';
  28. // 结果面板
  29. class TranslateTip {
  30. constructor() {
  31. const div = document.createElement('div');
  32. div.hidden = true;
  33. div.setAttribute('style',
  34. `position:absolute!important;
  35. font-size:13px!important;
  36. overflow:auto!important;
  37. background:#fff!important;
  38. font-family:sans-serif,Arial!important;
  39. font-weight:normal!important;
  40. text-align:left!important;
  41. color:#000!important;
  42. padding:0.5em 1em!important;
  43. line-height:1.5em!important;
  44. border-radius:5px!important;
  45. border:1px solid #ccc!important;
  46. box-shadow:4px 4px 8px #888!important;
  47. max-width:350px!important;
  48. max-height:216px!important;
  49. z-index:2147483647!important;`
  50. );
  51. document.documentElement.appendChild(div);
  52. //点击了内容面板,不再创建图标
  53. div.addEventListener('mouseup', e => e.stopPropagation());
  54. this._tip = div;
  55. }
  56. showText(text) { //显示测试结果
  57. this._tip.innerHTML = text;
  58. this._tip.hidden = !1;
  59. }
  60. hide() {
  61. this._tip.innerHTML = '';
  62. this._tip.hidden = true;
  63. }
  64. pop(ev) {
  65. this._tip.style.top = ev.pageY + 'px';
  66. //面板最大宽度为350px
  67. this._tip.style.left = (ev.pageX + 350 <= document.body.clientWidth ?
  68. ev.pageX : document.body.clientWidth - 350) + 'px';
  69. }
  70. }
  71. const tip = new TranslateTip();
  72.  
  73. class Icon {
  74. constructor() {
  75. const icon = document.createElement('span');
  76. icon.hidden = true;
  77. icon.innerHTML = `<svg style="margin:4px !important;" width="16" height="16" viewBox="0 0 24 24">
  78. <path d="M12 2L22 12L12 22L2 12Z" style="fill:none;stroke:#3e84f4;stroke-width:2;"></path></svg>`;
  79. icon.setAttribute('style',
  80. `width:24px!important;
  81. height:24px!important;
  82. background:#fff!important;
  83. border-radius:50%!important;
  84. box-shadow:4px 4px 8px #888!important;
  85. position:absolute!important;
  86. z-index:2147483647!important;`
  87. );
  88. document.documentElement.appendChild(icon);
  89. //拦截二个鼠标事件,以防止选中的文本消失
  90. icon.addEventListener('mousedown', e => e.preventDefault(), true);
  91. icon.addEventListener('mouseup', ev => ev.preventDefault(), true);
  92. icon.addEventListener('click', ev => {
  93. if (ev.ctrlKey) navigator.clipboard.readText()
  94. .then(text => {
  95. this.queryText(text.trim(), ev);
  96. })
  97. .catch(err => {
  98. console.error('Failed to read contents: ', err);
  99. });
  100. else {
  101. const text = window.getSelection().toString().trim().replace(/\s{2,}/g, ' ');
  102. this.queryText(text, ev);
  103. }
  104. });
  105. this._icon = icon;
  106. }
  107. pop(ev) {
  108. const icon = this._icon;
  109. icon.style.top = ev.pageY + 9 + 'px';
  110. icon.style.left = ev.pageX + -18 + 'px';
  111. icon.hidden = !1;
  112. setTimeout(this.hide.bind(this), 2e3);
  113. }
  114. hide() {
  115. this._icon.hidden = true;
  116. }
  117. queryText(text, ev) {
  118. if (text) {
  119. this._icon.hidden = true;
  120. tip.pop(ev);
  121. nastool(text);
  122. }
  123. }
  124. }
  125. const icon = new Icon();
  126.  
  127. document.addEventListener('mouseup', function (e) {
  128. var text = window.getSelection().toString().trim();
  129. GM_log(text);
  130. if (!text) {
  131. icon.hide();
  132. tip.hide();
  133. }
  134. else icon.pop(e);
  135. });
  136.  
  137. function nastool(text) {
  138. tip.showText(`识别中`);
  139. GM_log(text);
  140. GM_xmlhttpRequest({
  141. url: nastoolUrl + "/do?random=" + Math.random(),
  142. method: "POST",
  143. responseType: 'json',
  144. data: `{"cmd":"name_test","data":{"name":"${text}"}}`,
  145. headers: {
  146. "user-agent": navigator.userAgent,
  147. "content-type": "application/json; charset=UTF-8"
  148. },
  149. onload: (res) => {
  150. if (res.status === 200) {
  151. GM_log(res.response.data);
  152. let html = '';
  153. html += res.response.data.type ? `类型:${res.response.data.type}<br>` : '';
  154. html += res.response.data.category ? `分类:${res.response.data.category}<br>` : '';
  155. html += res.response.data.name ? `名称:${res.response.data.name}<br>` : '';
  156. html += res.response.data.title ? `标题:${res.response.data.title}<br>` : '';
  157. html += res.response.data.season_episode ? `季集:${res.response.data.season_episode}<br>` : '';
  158. html += res.response.data.year ? `年份:${res.response.data.year}<br>` : '';
  159. html += res.response.data.team ? `制作:${res.response.data.team}<br>` : '';
  160. html += res.response.data.tmdbid ? 'tmdb:<a href="' + res.response.data.tmdblink + '" target="_blank">' + res.response.data.tmdbid + '</a>' : 'tmdb:未识别';
  161. tip.showText(html);
  162. } else {
  163. GM_log(res);
  164. tip.showText("连接失败");
  165. }
  166. }
  167. });
  168. }
  169. })();
  170.  

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址