js爬取本地变量数据

js爬取本地变量数据,

  1. // ==UserScript==
  2. // @name js爬取本地变量数据
  3. // @license GPL-3.0-or-later
  4. // @foo 11
  5. // @namespace http://tampermonkey.net/
  6. // @version 0.1
  7. // @description js爬取本地变量数据,
  8. // @author 本然
  9. // @match http://*/*
  10. // @icon data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
  11. // @grant none
  12. // @include *
  13. // ==/UserScript==
  14.  
  15. (function() {
  16. 'use strict';
  17.  
  18. // Your code here...
  19. })();
  20. window.globalSearch=(function(){
  21. 'use strict';
  22. /*该方法遍历传入参数的所有属性
  23.  
  24. 可以用来获取本地变量下的值
  25. 该脚本可以直接在浏览器执行,也可以放到油猴里面
  26. 使用
  27.  
  28. 1. globeSearch.filterKeys="";
  29. 2. globalSearch.globalSearch.searchText="自然数之一"
  30. 3. globalSearch.globalSearch.runSearch("window");
  31. 其中有参数
  32. filterKeys: [],
  33. searchText: "",//搜索内容
  34. methodExe:false,//是否执行无参有返回值方法
  35. deepLength:20,//递归深度
  36. 可以控制
  37. */
  38. let globeSearch = {
  39. //搜索时需要过滤的路径关键词
  40. filterKeys: ['["observing"]','rightBtn', 'doSubmit','$options','render','_self','_watcher','_'],
  41. searchText: "",//搜索内容
  42. methodExe:false,//是否执行无参有返回值方法
  43. deepLength:20,//递归深度
  44. runSearch: function (pathString,currentDeepLength) {//递归方法
  45. // if(pathString=='temp1["getParams"]') debugger
  46. currentDeepLength=currentDeepLength||0;
  47. currentDeepLength+=1;
  48. if(currentDeepLength>this.deepLength){
  49. return;
  50. }
  51. //用来搜索路径
  52. let temp="/"+this.searchText+"/gi";
  53. if (pathString.toLowerCase().includes(this.searchText.toLowerCase())) {
  54. //if (temp.test(pathString)) {
  55. //console.log(pathString)
  56. this.hightLingth(pathString,this.searchText)
  57. }
  58. //进行防治调用死链
  59.  
  60. let isMore = /(["[a-z]+"])/g;
  61. let s = new Set();
  62. let count = 0;
  63. let matched;
  64. while ((matched = isMore.exec(pathString)) !== null) {
  65. s.add(matched[0]);
  66. count++;
  67. // debugger
  68. if (count / s.size > 8) {
  69. this.filterKeys.push(pathString.substring(0, pathString.lastIndexOf('[')));
  70. // debugger
  71. // console.log(filterkeys)
  72. return;
  73. }
  74. }
  75. //执行过滤
  76. if (this.filterKeys.filter((a) => pathString.indexOf(a) > -1).length > 0) {
  77. return;
  78. }
  79.  
  80. //用来调试
  81. // Object.keys(WfForm).forEach((childAttr) => {
  82. // let temp = pathString + '["' + childAttr + '"]';
  83. // if (pathString == 'WfForm["' + childAttr + '"]') {
  84. // //console.log("函数式",pathString)
  85. // // debugger
  86. // }
  87. // })
  88. try {
  89. if (eval(pathString) != null || eval(pathString) != undefined) {
  90.  
  91. let type = eval('typeof ' + pathString);
  92.  
  93. if (type == 'function') {
  94.  
  95. let command = pathString;
  96.  
  97. let hasReturn = /return |native code|[(][)]=>/;
  98.  
  99.  
  100. //执行参数为0且有返回值的函数,并递归其返回值
  101. if (this.methodExe==true&&eval(command + '.length') == 0 && hasReturn.test(eval(command + '.toString()'))) {
  102. // console.log("aaaaaaaaaaaa"+command)
  103. // debugger
  104. this.runSearch(command + "()",currentDeepLength);
  105. }
  106.  
  107.  
  108. } else if (type == 'object') {
  109. if (eval(pathString) instanceof Array) {
  110.  
  111. for (let a = 0; a < eval(pathString).length; a++) {
  112. let command = pathString + '[' + a + ']';
  113. ////console.log("Array" + command);
  114.  
  115. this.runSearch(command,currentDeepLength);
  116. }
  117. } else {
  118. ////console.log("eval(pathString)", eval(pathString));
  119. Object.keys(eval(pathString)).forEach((childAttr) => {
  120. let command = pathString + '["' + childAttr + '"]';
  121. this.runSearch(command,currentDeepLength);
  122. })
  123. }
  124. } else {
  125. let temp="/"+this.searchText+"/gi"
  126. if (pathString.toLowerCase().includes(this.searchText.toLowerCase()) || (eval(pathString) + "").toLowerCase().includes(this.searchText.toLowerCase())) {
  127. //if (temp.test(pathString) || temp.test((eval(pathString) + ""))) {
  128. //console.log("---------------------------------" + pathString);
  129. this.hightLingth("---------------------------------"+pathString,this.searchText)
  130. console.log(eval(pathString));
  131. }
  132. }
  133. }
  134. } catch (e) {
  135. console.error(e)
  136. console.error(pathString)
  137. }
  138. },
  139. hightLingth:function(str,highlightChar){
  140. const regex = new RegExp(highlightChar, "g");
  141. const highlightedStr = str.replace(regex, `%c${highlightChar}%c`);
  142.  
  143. const highlightStyle = "color: red; font-weight: bold;";
  144. console.log(highlightedStr, highlightStyle, "");
  145.  
  146. }
  147.  
  148. }
  149.  
  150. return {globalSearch:globeSearch}})(window)

QingJ © 2025

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