哔咔download

提取 __NUXT_DATA__ 中的直链下载链接,清空页面内容并美观地显示出来,链接边框固定宽度,增加重试机制避免失效。

  1. // ==UserScript==
  2. // @name 哔咔download
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.1
  5. // @description 提取 __NUXT_DATA__ 中的直链下载链接,清空页面内容并美观地显示出来,链接边框固定宽度,增加重试机制避免失效。
  6. // @author ghost331188
  7. // @match https://game.storyend.net/*
  8. // @match https://www.vikacg.xyz/external/*
  9. // @license GNU General Public License v3.0
  10. // @grant none
  11.  
  12. // @run-at document-end // 等到页面资源完全加载后再执行脚本
  13. // ==/UserScript==
  14.  
  15. (function() {
  16. 'use strict';
  17.  
  18. // 查找并解析 __NUXT_DATA__ 的函数
  19. function findAndParseNuxtData(retryCount = 10) {
  20. const nuxtDataScript = document.querySelector('script#__NUXT_DATA__');
  21. if (nuxtDataScript) {
  22. console.log('找到 __NUXT_DATA__ 标签');
  23.  
  24. try {
  25. const nuxtData = JSON.parse(nuxtDataScript.textContent);
  26. console.log('成功解析 __NUXT_DATA__:', nuxtData);
  27. return nuxtData;
  28. } catch (error) {
  29. console.error('解析 __NUXT_DATA__ 数据时发生错误:', error);
  30. return null;
  31. }
  32. } else {
  33. console.log('未找到 __NUXT_DATA__ 脚本标签');
  34. // 如果还没有找到 __NUXT_DATA__,进行重试
  35. if (retryCount > 0) {
  36. console.log(`重试剩余次数: ${retryCount}`);
  37. setTimeout(() => findAndParseNuxtData(retryCount - 1), 1000); // 每秒重试一次
  38. }
  39. return null;
  40. }
  41. }
  42.  
  43. window.onload = function() {
  44. console.log('页面完全加载,脚本开始执行');
  45.  
  46. // 解析 __NUXT_DATA__ 并提取链接
  47. const nuxtData = findAndParseNuxtData();
  48.  
  49. if (!nuxtData) return;
  50.  
  51. const extractLinks = (obj) => {
  52. let links = [];
  53. const regex = /https?:\/\/[^\s"]+\.(zip|7z|rar|apk)/g;
  54.  
  55. const searchLinks = (data) => {
  56. if (typeof data === 'string') {
  57. const matchedLinks = data.match(regex);
  58. if (matchedLinks) {
  59. links.push(...matchedLinks);
  60. }
  61. } else if (typeof data === 'object' && data !== null) {
  62. Object.values(data).forEach(value => searchLinks(value));
  63. }
  64. };
  65.  
  66. searchLinks(obj);
  67. return links;
  68. };
  69.  
  70. const possibleLinks = extractLinks(nuxtData);
  71. console.log('找到的直链:', possibleLinks);
  72.  
  73. // 清空页面的所有内容
  74. document.body.innerHTML = '';
  75.  
  76. // 设置页面的基础样式
  77. document.body.style.backgroundColor = '#f4f4f4';
  78. document.body.style.display = 'flex';
  79. document.body.style.flexDirection = 'column';
  80. document.body.style.alignItems = 'center';
  81. document.body.style.justifyContent = 'center';
  82. document.body.style.fontFamily = 'Arial, sans-serif';
  83. document.body.style.padding = '20px';
  84.  
  85. // 动态获取并设置页面标题
  86. const pageTitle = document.title || '下载链接';
  87.  
  88. // 创建标题
  89. const title = document.createElement('h1');
  90. title.innerText = pageTitle; // 使用网页的标题
  91. title.style.color = '#333';
  92. title.style.marginBottom = '20px';
  93. title.style.fontSize = '24px';
  94. title.style.textAlign = 'center';
  95. document.body.appendChild(title);
  96.  
  97. // 检查是否找到了下载链接
  98. if (possibleLinks.length > 0) {
  99. possibleLinks.forEach(link => {
  100. const linkElement = document.createElement('a');
  101. linkElement.href = link;
  102. linkElement.innerText = link;
  103. linkElement.style.display = 'block';
  104. linkElement.style.margin = '10px 0';
  105. linkElement.style.padding = '10px 0'; // 内边距高度一致
  106. linkElement.style.width = '80%'; // 链接容器宽度设为 80%
  107. linkElement.style.maxWidth = '500px'; // 最大宽度500px,防止太宽
  108. linkElement.style.wordWrap = 'break-word';
  109. linkElement.style.color = '#007bff';
  110. linkElement.style.backgroundColor = '#ffffff';
  111. linkElement.style.borderRadius = '5px';
  112. linkElement.style.boxShadow = '0 2px 4px rgba(0, 0, 0, 0.1)';
  113. linkElement.style.textAlign = 'center'; // 文字居中
  114. linkElement.style.textDecoration = 'none';
  115. linkElement.style.transition = 'background-color 0.3s ease';
  116.  
  117. // 添加 hover 效果
  118. linkElement.addEventListener('mouseover', () => {
  119. linkElement.style.backgroundColor = '#e9f5ff';
  120. });
  121. linkElement.addEventListener('mouseout', () => {
  122. linkElement.style.backgroundColor = '#ffffff';
  123. });
  124.  
  125. document.body.appendChild(linkElement);
  126. });
  127. } else {
  128. const noLinksMessage = document.createElement('p');
  129. noLinksMessage.innerText = '未找到任何下载链接。';
  130. noLinksMessage.style.color = '#666';
  131. noLinksMessage.style.fontSize = '16px';
  132. noLinksMessage.style.textAlign = 'center';
  133. document.body.appendChild(noLinksMessage);
  134. }
  135.  
  136. console.log('页面已更新为下载链接');
  137. };
  138.  
  139. })();