> [脚本体验师001 发表于 2023-7-29 15:01](forum.php?mod=redirect&goto=findpost&pid=65256&ptid=4824)
> > 在这里讨论技术方面是不需要花钱的,这也是我喜欢这个论坛的原因,每个人都会和善的对待你
it works!感谢指点
但是我想进一步调试一下,下面这几个console.log都打印不出来任何东西……
(function() {
'use strict';
setTimeout = () => {};
const ele = document.querySelector("#hd_0_container_0 > div:nth-child(1) > div:nth-child(2) > div > div:nth-child(1) > div:nth-child(3)");
const prop = Object.keys(ele).find(p => p.startsWith('__reactEventHandlers'));
ele.onMouseEnter();
console.log('打印元素绑定的事件');
console.log(ele);
console.log(prop);
console.log(ele);
// Your code here...
})();
我也根据教程下载了react developer tools,但一直是在这个页面没有显示任何内容 emmm
!(data/attachment/forum/202307/29/184321q2nbfbcghk2gzjj6.png)
xiaooooooo 发表于 2023-7-29 18:43
> [脚本体验师001 发表于 2023-7-29 15:01](forum.php?mod=redirect&goto=findpost&pid=65256&ptid=482 ...
打印不出信息应该是 console.log 被页面劫持了,使用 console.info 就可以
react developer tools 试了可以正常,重装一下?
脚本体验师001 发表于 2023-7-29 19:43
打印不出信息应该是 console.log 被页面劫持了,使用 console.info 就可以
react developer tools 试了可 ...
赞 又学了一招
脚本体验师001 发表于 2023-7-25 23:10
在这里讨论技术方面是不需要花钱的,这也是我喜欢这个论坛的原因,每个人都会和善的对待你
哥哥想赚点没问题的~
我个人其实倾向于论坛想学的就给解答
如果只想求方案的话支持大家收取懒惰税~
毕竟用爱发电久了大家可能扛不住
李恒道 发表于 2023-7-29 21:49
哥哥想赚点没问题的~
我个人其实倾向于论坛想学的就给解答
如果只想求方案的话支持大家收取懒惰税~
老师能持这么开放的态度来管理论坛,是我等之幸
想,在我不会写脚本之前,用过很多别人的脚本,其中不乏大神一级的牛的滴溜溜直转圈的。到最后都销声匿迹了,肯定不是在这个平台你知道的。他们落不着任何好处,还一不留神被用户骂了。还一不留神被封号删脚本了,我的天这世道,这简直丧尽天良
我每天看这个论坛,就是想看有一天这么好的论坛有扬眉吐气的时候
本帖最后由 xiaooooooo 于 2023-7-30 15:29 编辑
脚本体验师001 发表于 2023-7-29 22:25
老师能持这么开放的态度来管理论坛,是我等之幸
想,在我不会写脚本之前,用过很多别人的脚本,其中不乏 ...
大佬,之前的方案我发现这么一个小问题,就是写法没错,但是有成功率(个人觉得是在元素还没有加载完毕的时候,js就已经执行完了),如下被我注释掉的那一段。我的想法是采用cxxjackie大佬写的elemGetter脚本(因为我记得他是在该脚本中设置过等待元素出现的相关机制)进行改写,但是改写之后好像哪里没调对,现在连onMouseEnter的函数都触发不了了……不知是啥原因
// @match https://detail.1688.com/offer/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=1688.com
// @require http://cdn.bootcss.com/jquery/1.11.2/jquery.js
// @require https://scriptcat.org/lib/513/2.0.0/ElementGetter.js
// @grant GM_xmlhttpRequest
// ==/UserScript==
(function() {
'use strict';
elmGetter.selector($);
setTimeout = () => {};
// const ele = document.querySelector("#hd_0_container_0 > div:nth-child(1) > div:nth-child(2) > div > div:nth-child(1) > div:nth-child(3)");
// const prop = Object.keys(ele).find(p => p.startsWith('__reactEventHandlers'));
// ele.onMouseEnter();
// console.info('打印元素绑定的事件');
// console.info(ele);
// console.info(prop);
// console.info(ele);
elmGetter.get([
"#hd_0_container_0 > div:nth-child(1) > div:nth-child(2) > div > div:nth-child(1) > div:nth-child(3)",
]).then((ele) => {
const prop = Object.keys(ele).find(p => p.startsWith('__reactEventHandlers'));
ele.onMouseEnter();
console.info('打印元素绑定的事件');
console.info(ele);
console.info(prop);
console.info(ele);
});
elmGetter.get([
'#hd_0_container_0 > div:nth-child(1) > div:nth-child(2) > div > div:nth-child(1) > div:nth-child(4) > div > div:nth-child(3) > div:nth-child(1) > div:nth-child(1) > div',
]).then(() => {
const dataList = {
'jiaoyixunzhang': jiaoyixunzhang.text()
};
console.info(dataList);
});
// Your code here...
})();
xiaooooooo 发表于 2023-7-30 15:26
大佬,之前的方案我发现这么一个小问题,就是写法没错,但是有成功率(个人觉得是在元素还没有加载完毕的 ...
elmGetter.get([
"#hd_0_container_0 > div:nth-child(1) > div:nth-child(2) > div > div:nth-child(1) > div:nth-child(3)",
]).then((ele) => { //此时ele 是一个数组
ele = ele; //此时ele 是一个jQuery对象
ele = ele.get(0); //此时转为原生dom
const prop = Object.keys(ele).find(p => p.startsWith('__reactEventHandlers'));
ele.onMouseEnter();
console.info('打印元素绑定的事件');
console.info(ele);
console.info(prop);
console.info(ele);
});
建议哥哥再读一遍 elmGetter 的文档
脚本体验师001 发表于 2023-7-30 17:09
建议哥哥再读一遍 elmGetter 的文档
谢谢大佬 注释很赞
我之前有尝试过写成.then(() => {,但是缺了这个.get(0)的操作,结果也出不来,现在懂了
elmGetter.get([
"#hd_0_container_0 > div:nth-child(1) > div:nth-child(2) > div > div:nth-child(1) > div:nth-child(3)",
]).then(() => { //此时ele 是一个数组
//ele = ele; //此时ele 是一个jQuery对象
ele = ele.get(0); //此时转为原生dom
const prop = Object.keys(ele).find(p => p.startsWith('__reactEventHandlers'));
ele.onMouseEnter();
console.info('打印元素绑定的事件');
console.info(ele);
console.info(prop);
console.info(ele);
});
xiaooooooo 发表于 2023-7-30 15:26
大佬,之前的方案我发现这么一个小问题,就是写法没错,但是有成功率(个人觉得是在元素还没有加载完毕的 ...
如果你不需要获取多个,那就不必写选择器数组;如果不想要jQuery节点,选择器本身也可以被原生兼容,那就不需要变更为jQuery选择器,selector方法是可以在必要的时候随时切换的:
// 不调用selector,默认使用原生css选择器,返回元素节点:
elmGetter.get("#hd_0_container_0 > div:nth-child(1) > div:nth-child(2) > div > div:nth-child(1) > div:nth-child(3)").then(ele => {
console.info(ele);
});
// 之后再调用selector可变更为jQuery选择器:
elmGetter.selector($);
// ...
// 还可以再次调用selector变回去:
elmGetter.selector();
cxxjackie 发表于 2023-7-30 23:00
如果你不需要获取多个,那就不必写选择器数组;如果不想要jQuery节点,选择器本身也可以被原生兼容,那就 ...
谢谢大佬 我才知道这句话是个开关……
// 之后再调用selector可变更为jQuery选择器:
elmGetter.selector($);
// ...
// 还可以再次调用selector变回去:
elmGetter.selector();