Modao Menu Parser

modao menu parser

  1. // ==UserScript==
  2. // @name Modao Menu Parser
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.0.1
  5. // @description modao menu parser
  6. // @author 飞天小猪
  7. // @match http*://modao.cc/*
  8. // @icon https://gongjux.com/files/3/4453uhm5937m/32/favicon.ico
  9. // @grant none
  10. // @require https://gf.qytechs.cn/scripts/453166-jquery/code/jquery.js?version=1105525
  11. // @license MIT
  12. // ==/UserScript==
  13.  
  14.  
  15. // 判断modao版本
  16. function parserVersion() {
  17. return location.href.includes('proto')
  18. }
  19.  
  20. // 解析函数
  21. function parser() {
  22. const res = parserVersion()
  23. !res && layer.load(2, {shade: [0.5, '#393D49']})
  24. // 1. 获取ul元素
  25. const liElArr = findUlElememt()
  26. // 2. 整理数据
  27. if (!liElArr) return res ? alert('解析失败!') :layer.msg('解析失败!')
  28. const nodeList = getNodeList(liElArr)
  29. const result = toContent(flattenTreeWithLevels(nodeList))
  30. // 3. 将整理好的数据复制到剪贴板
  31. copyTextToClipboard(result)
  32. !res && layer.closeAll('loading');
  33. }
  34. function findUlElememt() {
  35. const res = parserVersion()
  36. return res ? ($('ul').children().toArray() || undefined) : ($('ul[class*="iAsEgD"]').children().toArray() || undefined)
  37. }
  38. function getNodeList(li) {
  39. const arr = []
  40. li.forEach(i => {
  41. const temp = {}
  42. const children = Array.from(i.children)
  43. temp.name = children.find(j => j.className.includes('rn-list-item')).innerText
  44. const list = Array.from(children.find(j => j.className.includes('child-screens'))?.children || [])
  45. if (list.length) {
  46. temp.children = getNodeList(list)
  47. } else {
  48. temp.children = []
  49. }
  50. arr.push(temp)
  51. })
  52. return arr
  53. }
  54.  
  55. function flattenTreeWithLevels(tree, levels = [], arr = []) {
  56. for (const node of tree) {
  57. const item = { ...levels };
  58. item[levels.length] = node.name;
  59. arr.push(item);
  60. if (node.children) {
  61. flattenTreeWithLevels(node.children, [...levels, node.name], arr);
  62. }
  63. }
  64. return arr;
  65. }
  66. function toContent(arr) {
  67. let str = ''
  68. const strArr = arr.map(i => {
  69. const itemArr = Object.values(i)
  70. return itemArr.join('\t')
  71. })
  72. str = strArr.join('\n')
  73. return str
  74. }
  75. async function copyTextToClipboard(text) {
  76. const res = parserVersion()
  77. if (navigator.clipboard && navigator.clipboard.writeText) {
  78. try {
  79. await navigator.clipboard.writeText(text);
  80. res ? alert('复制成功') :layer.msg('复制成功');
  81. return;
  82. } catch (err) {
  83. console.error('使用 Clipboard API 复制失败: ', err);
  84. }
  85. }
  86.  
  87. // 如果 Clipboard API 不可用,尝试使用 execCommand 方法
  88. const textArea = document.createElement('textarea');
  89. document.body.appendChild(textArea);
  90. textArea.value = text;
  91. textArea.select();
  92. try {
  93. const successful = document.execCommand('copy');
  94. if (successful) {
  95. console.log('使用 execCommand 复制成功');
  96. } else {
  97. console.log('使用 execCommand 复制失败');
  98. }
  99. } catch (err) {
  100. console.error('使用 execCommand 复制失败: ', err);
  101. } finally {
  102. document.body.removeChild(textArea);
  103. }
  104. }
  105. (function() {
  106. 'use strict';
  107.  
  108. function setButton() {
  109. // 创建一个新的button元素
  110. var button = document.createElement('button');
  111. button.textContent = '解析菜单'; // 设置按钮文字
  112.  
  113. // 设置按钮的基本样式(包括固定定位与默认透明度)
  114. button.style.cssText = `
  115. position: fixed; /* 或者 absolute,取决于您的布局需求 */
  116. top: 88px; /* 举例位置,您可以自定义 */
  117. right: 10px; /* 举例位置,您可以自定义 */
  118. z-index: 999;
  119. background-color: #007bff;
  120. color: white;
  121. padding: 6px 12px;
  122. border: none;
  123. border-radius: 5px;
  124. cursor: pointer;
  125. opacity: 0.3;
  126. transition: opacity 0.3s ease;
  127. `;
  128.  
  129.  
  130. // 添加鼠标悬浮时的透明度变化
  131. button.addEventListener('mouseover', function () {
  132. this.style.opacity = 1;
  133. });
  134.  
  135. // 添加鼠标离开时的透明度变化
  136. button.addEventListener('mouseout', function () {
  137. this.style.opacity = 0.3;
  138. });
  139. button.addEventListener('click', parser)
  140. // 将按钮添加到文档中
  141. document.body.appendChild(button);
  142. }
  143. function sleep(time) {
  144. return new Promise((resolve, reject) => {
  145. setTimeout(() => {
  146. resolve()
  147. }, time * 1000)
  148. })
  149. }
  150. async function init() {
  151. const res = parserVersion()
  152. if (res) {
  153. setButton()
  154. } else {
  155. $('head').append($('<link rel="stylesheet" href="https://www.layuicdn.com/layui/css/layui.css">')) // 名称:layui,版本:2.7.6,原始地址:https://www.layuicdn.com/#Layui
  156. if (typeof layer == 'undefined') {
  157. $('head').append('<script src="https://www.layuicdn.com/layer-v3.5.1/layer.js"></script>') // 名称:layer,版本:3.5.1,原始地址:https://www.layuicdn.com/#Layer
  158. }
  159. // 等待layer加载成功
  160. while (true) {
  161. const loadEl = document.getElementById('loading')
  162. const loadElStyle = loadEl && window.getComputedStyle(loadEl)
  163. if (typeof layer != 'undefined' && loadElStyle && loadElStyle.display === 'none') {
  164. break
  165. }
  166. await sleep(0.5)
  167. }
  168. setButton()
  169.  
  170. }
  171. }
  172. init()
  173. })();

QingJ © 2025

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