该方法遍历传入参数的所有属性
可以用来获取本地变量下的值
该脚本可以直接在浏览器执行,也可以放到油猴里面
使用
- globeSearch.filterKeys=“”;
- globalSearch.globalSearch.searchText=“自然数之一”
- globalSearch.globalSearch.runSearch(“window”);
其中有参数
filterKeys: [],
searchText: “”,//搜索内容
methodExe:false,//是否执行无参有返回值方法
deepLength:20,//递归深度
可以控制
// ==UserScript==
// @name 爬取接口数据
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author You
// @match http://*/*
// @icon data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
// @grant none
//@include *
// ==/UserScript==
(function() {
'use strict';
// Your code here...
})();
window.globalSearch=(function(){
'use strict';
let globeSearch = {
//搜索时需要过滤的路径关键词
filterKeys: ['["observing"]','rightBtn', 'doSubmit','$options','render','_self','_watcher','_'],
searchText: "",//搜索内容
methodExe:false,//是否执行无参有返回值方法
deepLength:20,//递归深度
runSearch: function (pathString,currentDeepLength) {//递归方法
// if(pathString=='temp1["getParams"]') debugger
currentDeepLength=currentDeepLength||0;
currentDeepLength+=1;
if(currentDeepLength>this.deepLength){
return;
}
//用来搜索路径
let temp="/"+this.searchText+"/gi";
if (pathString.toLowerCase().includes(this.searchText.toLowerCase())) {
//if (temp.test(pathString)) {
//console.log(pathString)
this.hightLingth(pathString,this.searchText)
}
//进行防治调用死链
let isMore = /(["[a-z]+"])/g;
let s = new Set();
let count = 0;
let matched;
while ((matched = isMore.exec(pathString)) !== null) {
s.add(matched[0]);
count++;
// debugger
if (count / s.size > 8) {
this.filterKeys.push(pathString.substring(0, pathString.lastIndexOf('[')));
// debugger
// console.log(filterkeys)
return;
}
}
//执行过滤
if (this.filterKeys.filter((a) => pathString.indexOf(a) > -1).length > 0) {
return;
}
//用来调试
// Object.keys(WfForm).forEach((childAttr) => {
// let temp = pathString + '["' + childAttr + '"]';
// if (pathString == 'WfForm["' + childAttr + '"]') {
// //console.log("函数式",pathString)
// // debugger
// }
// })
try {
if (eval(pathString) != null || eval(pathString) != undefined) {
let type = eval('typeof ' + pathString);
if (type == 'function') {
let command = pathString;
let hasReturn = /return |native code|[(][)]=>/;
//执行参数为0且有返回值的函数,并递归其返回值
if (this.methodExe==true&&eval(command + '.length') == 0 && hasReturn.test(eval(command + '.toString()'))) {
// console.log("aaaaaaaaaaaa"+command)
// debugger
this.runSearch(command + "()",currentDeepLength);
}
} else if (type == 'object') {
if (eval(pathString) instanceof Array) {
for (let a = 0; a < eval(pathString).length; a++) {
let command = pathString + '[' + a + ']';
console.log("Array" + command);
this.runSearch(command,currentDeepLength);
}
} else {
console.log("eval(pathString)", eval(pathString));
Object.keys(eval(pathString)).forEach((childAttr) => {
let command = pathString + '["' + childAttr + '"]';
this.runSearch(command,currentDeepLength);
})
}
} else {
let temp="/"+this.searchText+"/gi"
if (pathString.toLowerCase().includes(this.searchText.toLowerCase()) || (eval(pathString) + "").toLowerCase().includes(this.searchText.toLowerCase())) {
//if (temp.test(pathString) || temp.test((eval(pathString) + ""))) {
//console.log("---------------------------------" + pathString);
this.hightLingth("---------------------------------"+pathString,this.searchText)
console.log(eval(pathString));
}
}
}
} catch (e) {
console.error(e)
console.error(pathString)
}
},
hightLingth:function(str,highlightChar){
const regex = new RegExp(highlightChar, "g");
const highlightedStr = str.replace(regex, `%c${highlightChar}%c`);
const highlightStyle = "color: red; font-weight: bold;";
console.log(highlightedStr, highlightStyle, "");
}
}
return {globalSearch:globeSearch}})(window)