ASMRONE跳转Kikoeru

检测页面中的RJ号,并在每个RJ号旁边显示跳转按钮,同时根据资源存在情况改变按钮颜色和文本。在 127.0.0.1:8889 页面中创建跳转到 ASMRONE 的按钮。

目前为 2025-03-05 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name ASMRONE跳转Kikoeru
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.8
  5. // @description 检测页面中的RJ号,并在每个RJ号旁边显示跳转按钮,同时根据资源存在情况改变按钮颜色和文本。在 127.0.0.1:8889 页面中创建跳转到 ASMRONE 的按钮。
  6. // @author 你的名字
  7. // @match *://asmr-300.com/*
  8. // @match *://asmr-200.com/*
  9. // @match *://asmr-100.com/*
  10. // @match *://asmr.one/*
  11. // @match *://127.0.0.1:8889/*
  12. // @grant GM_xmlhttpRequest
  13. // ==/UserScript==
  14.  
  15. // 使用严格模式,避免代码中的潜在问题
  16. (function () {
  17. 'use strict';
  18.  
  19. // 判断当前页面是否为 127.0.0.1:8889
  20. const isLocalhost8889 = window.location.hostname === '127.0.0.1' && window.location.port === '8889';
  21.  
  22. // 如果不是 127.0.0.1:8889,执行原代码
  23. if (!isLocalhost8889) {
  24. // 定义按钮的样式
  25. const style = `
  26. .rdl-button {
  27. display: inline-block; /* 按钮显示为行内块元素 */
  28. padding: 1px 1px; /* 按钮内边距 */
  29. text-decoration: none; /* 去掉文字装饰(如下划线) */
  30. margin-left: 10px; /* 按钮左边距 */
  31. cursor: pointer; /* 鼠标悬停时显示为手型 */
  32. border: none; /* 去掉边框 */
  33. border-radius: 4px; /* 圆角边框 */
  34. font-size: 13px; /* 字体大小 */
  35. color: white; /* 文字颜色为白色 */
  36. }
  37. .rdl-button_green {
  38. background-color: #67c23a; /* 绿色背景 */
  39. }
  40. .rdl-button_red {
  41. background-color: #f56c6c; /* 红色背景 */
  42. }
  43. .rdl-button_blue {
  44. background-color: #409eff; /* 蓝色背景 */
  45. }
  46. `;
  47.  
  48. // 创建一个 <style> 元素,用于将样式添加到页面中
  49. const styleSheet = document.createElement("style");
  50. styleSheet.type = "text/css"; // 设置样式表类型
  51. styleSheet.innerText = style; // 将样式内容添加到 <style> 元素
  52. document.head.appendChild(styleSheet); // 将 <style> 元素添加到页面的 <head> 中
  53.  
  54. // 检测页面中的RJ号并创建按钮
  55. const checkPageAndCreateButtons = async () => {
  56. console.log('checkPageAndCreateButtons called'); // 打印日志,表示函数被调用
  57.  
  58. // 查找所有包含RJ号的元素
  59. const rjElements = document.querySelectorAll('.q-chip__content.col.row.no-wrap.items-center.q-anchor--skip');
  60. rjElements.forEach(element => {
  61. // 检查是否已经处理过这个元素
  62. if (element.dataset.processed) {
  63. return; // 如果已经处理过,跳过
  64. }
  65.  
  66. const text = element.innerText; // 获取元素的文本内容
  67. const rjRegex = /RJ(\d{6,8})/i; // 正则表达式,匹配RJ号
  68. const match = text.match(rjRegex); // 在文本中查找RJ号
  69.  
  70. if (match) {
  71. let rjNumber = match[1]; // 提取RJ号的数字部分
  72. if (rjNumber.length === 6) {
  73. rjNumber = rjNumber; // 如果RJ号是6位数,直接使用
  74. } else if (rjNumber.length === 8) {
  75. rjNumber = rjNumber.slice(1); // 如果RJ号是8位数,去掉第一位
  76. }
  77.  
  78. // 检查是否已经存在按钮
  79. const existingButton = element.parentElement.querySelector('.kikoeru-jump-button');
  80. if (existingButton) {
  81. return; // 如果按钮已经存在,跳过
  82. }
  83.  
  84. // 创建按钮
  85. const button = document.createElement('a'); // 创建一个 <a> 元素
  86. button.className = 'rdl-button rdl-button_red kikoeru-jump-button'; // 设置按钮的类名
  87. button.textContent = '正在检查...'; // 设置按钮的文本
  88. button.target = "_blank"; // 设置按钮点击后在新标签页中打开
  89.  
  90. // 将按钮添加到元素的右边
  91. element.parentElement.appendChild(button);
  92.  
  93. // 标记这个元素已经处理过
  94. element.dataset.processed = 'true';
  95.  
  96. // 检查资源是否存在
  97. checkResource(rjNumber, button);
  98. }
  99. });
  100. };
  101.  
  102. // 检查资源是否存在
  103. async function checkResource(rj, button) {
  104. const url = `http://127.0.0.1:8889/api/search?keyword=${rj}`; // 构造请求URL
  105. GM_xmlhttpRequest({
  106. method: 'GET', // 使用GET方法发送请求
  107. url: url, // 请求的URL
  108. onload: function (response) { // 请求成功时的回调函数
  109. try {
  110. const works = JSON.parse(response.responseText).works; // 解析响应数据
  111. if (works.length > 0) { // 如果资源存在
  112. button.textContent = '跳转kikoeru'; // 设置按钮文本
  113. button.href = `http://127.0.0.1:8889/work/${rj}`; // 设置按钮跳转链接
  114. button.className = "rdl-button rdl-button_green"; // 设置按钮为绿色
  115.  
  116. // 添加点击事件监听器,确保跳转行为
  117. button.addEventListener('click', (event) => {
  118. event.preventDefault(); // 阻止默认行为
  119. window.open(button.href, '_blank'); // 在新标签页中打开链接
  120. });
  121. } else { // 如果资源不存在
  122. button.textContent = '资源不存在'; // 设置按钮文本
  123. button.href = '#'; // 禁用链接
  124. button.className = "rdl-button rdl-button_red"; // 设置按钮为红色
  125. }
  126. } catch (error) { // 如果解析响应数据失败
  127. button.textContent = '请求失败'; // 设置按钮文本
  128. button.href = '#'; // 禁用链接
  129. button.className = "rdl-button rdl-button_red"; // 设置按钮为红色
  130. }
  131. },
  132. onerror: function () { // 请求失败时的回调函数
  133. button.textContent = '请求失败'; // 设置按钮文本
  134. button.href = '#'; // 禁用链接
  135. button.className = "rdl-button rdl-button_red"; // 设置按钮为红色
  136. }
  137. });
  138. }
  139.  
  140. // 初始化时检测一次页面
  141. checkPageAndCreateButtons();
  142.  
  143. // 使用 MutationObserver 动态监测 DOM 变化
  144. const observer = new MutationObserver(checkPageAndCreateButtons);
  145. observer.observe(document.body, { childList: true, subtree: true }); // 监听 body 元素的变化
  146. }
  147.  
  148. // 如果是 127.0.0.1:8889 页面,执行新增的代码
  149. if (isLocalhost8889) {
  150. // 创建跳转到 ASMRONE 的按钮
  151. const createAsmrOneButton = (url) => {
  152. const rjRegex = /work\/(\d{6,7})/i; // 匹配 6 位或 7 位的 RJ 号
  153. const match = url.match(rjRegex);
  154.  
  155. if (match) {
  156. let rjNumber = match[1];
  157. if (rjNumber.length === 6) {
  158. rjNumber = `RJ${rjNumber}`; // 6 位数直接使用
  159. } else if (rjNumber.length === 7) {
  160. rjNumber = `RJ0${rjNumber}`; // 7 位数补 0 为 8 位
  161. }
  162.  
  163. const jumpUrl = `https://asmr-200.com/work/${rjNumber}`;
  164.  
  165. const existingButton = document.getElementById('asmr-one-jump-button');
  166. if (existingButton) {
  167. existingButton.remove();
  168. }
  169.  
  170. const targetRow = document.querySelector('.row.items-center.q-gutter-xs');
  171. if (targetRow) {
  172. console.log('Target row found');
  173. const button = document.createElement('a');
  174. button.id = 'asmr-one-jump-button'; // 设置按钮的 ID,用于唯一标识该按钮
  175. button.textContent = 'ASMRONE'; // 设置按钮上显示的文本内容
  176. button.style.marginLeft = '10px'; // 设置按钮左边距为 10px,使其与左侧元素保持一定距离
  177. button.style.textDecoration = 'none'; // 移除按钮文本的下划线(通常用于链接)
  178. button.style.cursor = 'pointer'; // 设置鼠标悬停时的光标样式为指针(表示可点击)
  179. button.style.backgroundColor = '#31ccec'; // 设置背景颜色为绿色
  180. button.style.color = 'white'; // 设置文字颜色为白色
  181. button.style.border = 'none'; // 移除边框
  182. button.style.padding = '6px 12px'; // 设置内边距
  183. button.style.borderRadius = '4px'; // 设置圆角
  184. button.style.fontSize = '13px'; // 设置字体大小
  185. button.style.width = 'auto'; // 宽度自适应内容
  186. button.style.height = 'auto'; // 高度自适应内容
  187. button.target = "_blank"; // 在新标签页中打开
  188. button.href = jumpUrl; // 设置按钮点击后跳转的链接地址
  189.  
  190. // 设置样式为蓝色
  191. button.className = 'rdl-button rdl-button_blue';
  192.  
  193. // 添加到目标行的最后
  194. targetRow.appendChild(button);
  195. } else {
  196. console.log('Target row not found');
  197. }
  198. } else {
  199. console.log('No RJ number in URL');
  200. const existingButton = document.getElementById('asmr-one-jump-button');
  201. if (existingButton) {
  202. existingButton.remove();
  203. }
  204. }
  205. };
  206.  
  207. // 初始化时执行一次创建 ASMRONE 按钮的逻辑
  208. createAsmrOneButton(window.location.href);
  209.  
  210. // 监听 AJAX 请求完成事件,确保在内容加载完成后再执行按钮创建逻辑
  211. const originalOpen = XMLHttpRequest.prototype.open;
  212. XMLHttpRequest.prototype.open = function () {
  213. this.addEventListener('load', () => {
  214. if (this.responseURL.includes('/work/')) {
  215. createAsmrOneButton(window.location.href);
  216. }
  217. });
  218. originalOpen.apply(this, arguments);
  219. };
  220. }
  221. })();

QingJ © 2025

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