跳至主要內容
  • Hostloc 空間訪問刷分
  • 售賣場
  • 廣告位
  • 賣站?

4563博客

全新的繁體中文 WordPress 網站
  • 首頁
  • 请教关于油猴脚本的问题
未分類
9 3 月 2020

请教关于油猴脚本的问题

二茂铁 大佬有话说 :

请教关于油猴脚本的问题

太难了,一堆脚本怪在抢课,之后都在黑市群被交易,买一门课好贵啊!于是自己写了一个js脚本
不太了解油猴插件
代码在console里运行是可以的,但是放到油猴运行时,报错是 click is undefined
本来页面已经加载了jQuery
代码贴在这里了
希望大佬指点
轻喷
(function() {
    ‘use strict’;

    // Your code here…
      //输入要抢的科目
    $(‘#signBtn’).ready();
    var subject = "庄子";
    //选择2019级
    document.querySelectorAll(‘li a’).click();
    //选择机院
    document.querySelectorAll(‘li a’).click();
    //查询操作
    document.querySelectorAll(‘button’).click();
    //点击更多
    document.querySelectorAll(‘div#more font a’).click();
    //选课,获取全部列表名
    var list_subjectName= document.querySelectorAll(‘h3.panel-title’);
    var srch = function get_order_num(list, string){
      for(var i = 0; i < list.length; i++) {
            var k = list.querySelector(‘span’).innerText.search(string);
            if (k > 0){
                return i;
            }
      }
    }
    var list = document.querySelectorAll(‘div’);
    var num = srch(list_subjectName, subject) + 1;
    //展开面板
    list.querySelector(‘a’).click();
    setTimeout(function abc(){
      var button_list = list.querySelectorAll(‘button’);
      var full_list = list.querySelectorAll(‘tr td.full’)
      for(var i = 0; i < button_list.length && full_list != ‘已满’; i++){
            if(button_list.innerText == ‘选课’){
                button_list.click();
                window.location.reload();
            }
      }}, 1000);
})();

loveqianool 大佬有话说 :

现在的孩子上课都要抢着上吗?

千牛 大佬有话说 :

js有个执行时间概念。即在什么时候执行。
你这个写法是立即执行
在GM脚本中有一个标头
//@run-at    document-start
或者是document-end
你的可能就是后者了,当然你也可以加一个按钮,点击这个按钮,立即执行对应代码
具体可以参加:Tampermonkey的标头API文档说明

二茂铁 大佬有话说 :

有的科目好拿分呐,当代大学生,真卑微

lsza 大佬有话说 :

同二楼 上课也要抢着上?

二茂铁 大佬有话说 :

千牛 大佬有话说 : 2020-3-9 22:25
js有个执行时间概念。即在什么时候执行。
你这个写法是立即执行
在GM脚本中有一个标头

谢谢大佬,马上试一下

我是一个大水怪 大佬有话说 :

可怜的大学生,居然还有黑市一说。

二茂铁 大佬有话说 :

千牛 大佬有话说 : 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 <anonymous>: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 (<anonymous>)
    at <anonymous>:3:98
    at Object.c (<anonymous>:2:146)

千牛 大佬有话说 :

二茂铁 大佬有话说 : 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里面能运行,有可能你的域估计没找对 yc011t
你console里面执行可能是在iframe里面执行的,确认下
其次才是确认是否代码执行的时候数据未载入

文章導覽

上一篇文章
下一篇文章

AD

其他操作

  • 登入
  • 訂閱網站內容的資訊提供
  • 訂閱留言的資訊提供
  • WordPress.org 台灣繁體中文

51la

4563博客

全新的繁體中文 WordPress 網站
返回頂端
本站採用 WordPress 建置 | 佈景主題採用 GretaThemes 所設計的 Memory
4563博客
  • Hostloc 空間訪問刷分
  • 售賣場
  • 廣告位
  • 賣站?
在這裡新增小工具