ASMRONE跳转Kikoeru

检测地址栏中的RJ号,并在指定的div元素中显示跳转Kikoeru按钮,同时根据资源存在情况改变按钮颜色和文本

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

  1. // ==UserScript==
  2. // @name ASMRONE跳转Kikoeru
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.1
  5. // @description 检测地址栏中的RJ号,并在指定的div元素中显示跳转Kikoeru按钮,同时根据资源存在情况改变按钮颜色和文本
  6. // @author 你的名字
  7. // @match *://asmr-300.com/*
  8. // @match *://asmr-200.com/*
  9. // @match *://asmr-100.com/*
  10. // @match *://asmr.one/*
  11. // @grant GM_xmlhttpRequest
  12. // ==/UserScript==
  13.  
  14. (function () {
  15. 'use strict';
  16.  
  17. // 添加样式定义
  18. const style = `
  19. .rdl-button {
  20. display: inline-block;
  21. padding: 5px 10px;
  22. text-decoration: none;
  23. }
  24. .rdl-button_green {
  25. background-color: #67c23a;
  26. color: white;
  27. }
  28. .rdl-button_red {
  29. background-color: #f56c6c;
  30. color: white;
  31. }
  32. `;
  33. const styleSheet = document.createElement("style");
  34. styleSheet.type = "text/css";
  35. styleSheet.innerText = style;
  36. document.head.appendChild(styleSheet);
  37.  
  38. // 检测地址栏中的RJ号并创建按钮
  39. const checkUrlAndCreateButton = async () => {
  40. console.log('checkUrlAndCreateButton called');
  41. const url = window.location.href;
  42. console.log('Current URL:', url);
  43. const rjRegex = /RJ(\d{6,8})/i;
  44. const match = url.match(rjRegex);
  45.  
  46. if (match) {
  47. let rjNumber = match[1];
  48. if (rjNumber.length === 6) {
  49. rjNumber = rjNumber; // 6位数直接去掉RJ
  50. } else if (rjNumber.length === 8) {
  51. rjNumber = rjNumber.slice(1); // 8位数保留后7位
  52. }
  53.  
  54. const jumpUrl = `http://localhost:8889/work/${rjNumber}`;
  55.  
  56. const existingButton = document.getElementById('rj-jump-button');
  57. if (existingButton) {
  58. existingButton.remove();
  59. }
  60.  
  61. const targetRow = document.querySelector('.row.items-center.q-gutter-xs');
  62. if (targetRow) {
  63. console.log('Target row found');
  64. const button = document.createElement('a');
  65. button.id = 'rj-jump-button';
  66. button.textContent = '正在检查...';
  67. button.style.marginLeft = '10px';
  68. button.style.textDecoration = 'none';
  69. button.style.cursor = 'pointer';
  70.  
  71. // 设置默认样式为红色
  72. button.className = 'rdl-button rdl-button_red';
  73.  
  74. // 添加到目标行的最后
  75. targetRow.appendChild(button);
  76.  
  77. // 检查资源是否存在
  78. await checkResource(rjNumber, button);
  79. } else {
  80. console.log('Target row not found');
  81. }
  82. } else {
  83. console.log('No RJ number in URL');
  84. const existingButton = document.getElementById('rj-jump-button');
  85. if (existingButton) {
  86. existingButton.remove();
  87. }
  88. }
  89. };
  90.  
  91. // 检查资源是否存在
  92. async function checkResource(rj, button) {
  93. const url = `http://localhost:8889/api/search?keyword=${rj}`;
  94. GM_xmlhttpRequest({
  95. method: 'GET',
  96. url: url,
  97. onload: function (response) {
  98. try {
  99. const works = JSON.parse(response.responseText).works;
  100. if (works.length > 0) {
  101. button.textContent = '跳转kikoeru';
  102. button.href = `http://localhost:8889/work/${rj}`;
  103. button.className = "rdl-button rdl-button_green"; // 资源存在,变绿
  104. } else {
  105. button.textContent = '资源不存在';
  106. button.href = '#'; // 禁用链接
  107. button.className = "rdl-button rdl-button_red"; // 资源不存在,保持红
  108. }
  109. } catch (error) {
  110. button.textContent = '请求失败';
  111. button.href = '#'; // 禁用链接
  112. button.className = "rdl-button rdl-button_red"; // 请求失败,保持红
  113. }
  114. },
  115. onerror: function () {
  116. button.textContent = '请求失败';
  117. button.href = '#'; // 禁用链接
  118. button.className = "rdl-button rdl-button_red"; // 请求失败,保持红
  119. }
  120. });
  121. }
  122.  
  123. // 初始化时检测一次URL
  124. checkUrlAndCreateButton();
  125. let lastUrl = window.location.href;
  126.  
  127. // 监听所有链接的点击事件
  128. document.addEventListener('click', (event) => {
  129. const target = event.target.closest('a');
  130. if (target) {
  131. // 延迟一小段时间(例如100ms),等待URL更新
  132. setTimeout(() => {
  133. if (window.location.href !== lastUrl) {
  134. lastUrl = window.location.href;
  135. checkUrlAndCreateButton();
  136. }
  137. }, 100); // 延迟时间可以根据实际情况调整
  138. }
  139. });
  140. })();

QingJ © 2025

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