找回密码
 立即注册
CeraNetworksBGVM服务器主机交流IP归属甄别会员请立即修改密码
查看: 56|回复: 9

请教关于油猴脚本的问题

[复制链接]

12

主题

38

回帖

204

积分

中级会员

积分
204
发表于 2020-3-9 22:22:00 | 显示全部楼层 |阅读模式
太难了,一堆脚本怪在抢课,之后都在黑市群被交易,买一门课好贵啊!于是自己写了一个js脚本
不太了解油猴插件
代码在console里运行是可以的,但是放到油猴运行时,报错是 click is undefined
本来页面已经加载了jQuery
代码贴在这里了
希望大佬指点
轻喷
[ol][*](function() {
[*]    'use strict';
[*]
[*]    // Your code here...
[*]        //输入要抢的科目
[*]    $('#signBtn').ready();
[*]    var subject = "庄子";
[*]    //选择2019级
[*]    document.querySelectorAll('li[index^=njdm_id_list_2019] a')[0].click();
[*]    //选择机院
[*]    document.querySelectorAll('li[index^=jg_id_list_30] a')[0].click();
[*]    //查询操作
[*]    document.querySelectorAll('button[name^=query]')[0].click();
[*]    //点击更多
[*]    document.querySelectorAll('div#more font a')[0].click();
[*]    //选课,获取全部列表名
[*]    var list_subjectName= document.querySelectorAll('h3.panel-title');
[*]    var srch = function get_order_num(list, string){
[*]        for(var i = 0; i  0){
[*]                return i;
[*]            }
[*]        }
[*]    }
[*]    var list = document.querySelectorAll('div[class*=panel-info]');
[*]    var num = srch(list_subjectName, subject) + 1;
[*]    //展开面板
[*]    list[num].querySelector('a[class*=expand]').click();
[*]    setTimeout(function abc(){
[*]        var button_list = list[num].querySelectorAll('button');
[*]        var full_list = list[num].querySelectorAll('tr td.full')
[*]        for(var i = 0; i 复制代码
回复

使用道具 举报

39

主题

969

回帖

2577

积分

金牌会员

积分
2577
发表于 2020-3-9 22:24:41 | 显示全部楼层
现在的孩子上课都要抢着上吗?
回复

使用道具 举报

71

主题

690

回帖

2319

积分

金牌会员

积分
2319
发表于 2020-3-9 22:25:29 | 显示全部楼层
js有个执行时间概念。即在什么时候执行。
你这个写法是立即执行
在GM脚本中有一个标头
//@run-at    document-start
或者是document-end
你的可能就是后者了,当然你也可以加一个按钮,点击这个按钮,立即执行对应代码
具体可以参加:Tampermonkey的标头API文档说明
回复

使用道具 举报

12

主题

38

回帖

204

积分

中级会员

积分
204
 楼主| 发表于 2020-3-9 22:26:33 | 显示全部楼层
有的科目好拿分呐,当代大学生,真卑微
回复

使用道具 举报

274

主题

899

回帖

3789

积分

论坛元老

积分
3789
发表于 2020-3-9 22:27:46 | 显示全部楼层
同二楼 上课也要抢着上?
回复

使用道具 举报

12

主题

38

回帖

204

积分

中级会员

积分
204
 楼主| 发表于 2020-3-9 22:28:12 | 显示全部楼层

千牛 发表于 2020-3-9 22:25

js有个执行时间概念。即在什么时候执行。
你这个写法是立即执行
在GM脚本中有一个标头

谢谢大佬,马上试一下
回复

使用道具 举报

0

主题

234

回帖

482

积分

中级会员

积分
482
发表于 2020-3-9 22:25:00 | 显示全部楼层
可怜的大学生,居然还有黑市一说。
回复

使用道具 举报

12

主题

38

回帖

204

积分

中级会员

积分
204
 楼主| 发表于 2020-3-9 22:29:56 | 显示全部楼层

千牛 发表于 2020-3-9 22:25

js有个执行时间概念。即在什么时候执行。
你这个写法是立即执行
在GM脚本中有一个标头

还是不行,报错如下
userscript.html?name=LCG%E7%9A%84%E6%8A%A2%E8%AF%BE%E8%84%9A%E6%9C%AC.user.js&id=e70624f4-89a4-46ef-ab83-a91e8788bf82:1 ERROR: Execution of script 'LCG的抢课脚本' failed! Cannot read property 'click' of undefined
eval @ userscript.html?name=LCG%E7%9A%84%E6%8A%A2%E8%AF%BE%E8%84%9A%E6%9C%AC.user.js&id=e70624f4-89a4-46ef-ab83-a91e8788bf82:1
eval @ userscript.html?name=LCG%E7%9A%84%E6%8A%A2%E8%AF%BE%E8%84%9A%E6%9C%AC.user.js&id=e70624f4-89a4-46ef-ab83-a91e8788bf82:1
eval @ userscript.html?name=LCG%E7%9A%84%E6%8A%A2%E8%AF%BE%E8%84%9A%E6%9C%AC.user.js&id=e70624f4-89a4-46ef-ab83-a91e8788bf82:58
eval @ userscript.html?name=LCG%E7%9A%84%E6%8A%A2%E8%AF%BE%E8%84%9A%E6%9C%AC.user.js&id=e70624f4-89a4-46ef-ab83-a91e8788bf82:60
(anonymous) @ VM104:3
c @ VM104:2
(anonymous) @ VM104:3
ka @ VM108:59
create @ VM108:71
d @ VM108:13
runListeners @ VM108:13
eval @ VM108:72
Q @ VM104:11
send @ content.js:7
(anonymous) @ content.js:27
processQueue @ content.js:3
a @ content.js:9
userscript.html?name=LCG%E7%9A%84%E6%8A%A2%E8%AF%BE%E8%84%9A%E6%9C%AC.user.js&id=e70624f4-89a4-46ef-ab83-a91e8788bf82:1 TypeError: Cannot read property 'click' of undefined
    at eval (userscript.html?name=LCG%E7%9A%84%E6%8A%A2%E8%AF%BE%E8%84%9A%E6%9C%AC.user.js&id=e70624f4-89a4-46ef-ab83-a91e8788bf82:25)
    at Window.eval (userscript.html?name=LCG%E7%9A%84%E6%8A%A2%E8%AF%BE%E8%84%9A%E6%9C%AC.user.js&id=e70624f4-89a4-46ef-ab83-a91e8788bf82:55)
    at :3:98
    at eval (userscript.html?name=LCG%E7%9A%84%E6%8A%A2%E8%AF%BE%E8%84%9A%E6%9C%AC.user.js&id=e70624f4-89a4-46ef-ab83-a91e8788bf82:1)
    at eval (userscript.html?name=LCG%E7%9A%84%E6%8A%A2%E8%AF%BE%E8%84%9A%E6%9C%AC.user.js&id=e70624f4-89a4-46ef-ab83-a91e8788bf82:1)
    at eval (userscript.html?name=LCG%E7%9A%84%E6%8A%A2%E8%AF%BE%E8%84%9A%E6%9C%AC.user.js&id=e70624f4-89a4-46ef-ab83-a91e8788bf82:58)
    at eval (userscript.html?name=LCG%E7%9A%84%E6%8A%A2%E8%AF%BE%E8%84%9A%E6%9C%AC.user.js&id=e70624f4-89a4-46ef-ab83-a91e8788bf82:60)
    at eval ()
    at :3:98
    at Object.c [as F_c] (:2:146)
回复

使用道具 举报

71

主题

690

回帖

2319

积分

金牌会员

积分
2319
发表于 2020-3-9 22:32:23 | 显示全部楼层

二茂铁 发表于 2020-3-9 22:32

还是不行,报错如下
userscript.html?name=LCG%E7%9A%84%E6%8A%A2%E8%AF%BE%E8%84%9A%E6%9C%AC.user.js&i ...

emmmm
"click something of undefined" means you want to click something, but something is not exist.
就是说你的目标点击对象不存在,你的代码选择有问题
console里面能运行,有可能你的域估计没找对


你console里面执行可能是在iframe里面执行的,确认下
其次才是确认是否代码执行的时候数据未载入
回复

使用道具 举报

12

主题

38

回帖

204

积分

中级会员

积分
204
 楼主| 发表于 2020-3-9 22:25:00 | 显示全部楼层

千牛 发表于 2020-3-9 22:41

emmmm
"click something of undefined" means you want to click something, but something is not exist ...

嗯嗯嗯好的
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|HS2V主机综合交流论坛

GMT+8, 2024-4-29 20:05 , Processed in 0.119161 second(s), 3 queries , Gzip On, Redis On.

Powered by Discuz! X3.5

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表