这是我当前的代码:
setInterval(function (){
// ==UserScript==
// @name DriversEd Time Saver!
// @namespace [email protected]
// @description Automatically goes to the next slide once the next button is clickable.
// @copyright 2014+, Marque Kuem
// @license GPL version 3 or any later version; http://www.gnu.org/copyleft/gpl.html
// @license (CC); http://creativecommons.org/licenses/by-nc-sa/3.0/
// @version 0.1
// @icon https://driversed.com/img/logo.png
// @homepageURL https://duckduckgo.com/
// @supportURL https://duckduckgo.com/
// @include https://driversed.com/dashboard/course/*
// ==/UserScript==
alert('Running!');
var clickNext = document.querySelectorAll("btn.btn-small.btn_next.btn-advance");
if(clickNext.length>0){
alert('Next is clickable.');
}
},2500);
但是当我运行它时,它根本无法工作,就好像代码永远不会运行,我该如何解决呢?另外,有人可以给我链接一些入门指南,以开始使用用户脚本和JavaScript吗?
文档需要准备好,试试这个:
window.onload = function () {
// your code here
}
或使用jQuery:
$( document ).ready(function() {
// your code here
});
您尚未显示HTML源代码。我想您想选择具有.btn-small
,.btn_next
或.btn-advance
类之一的按钮。您的查询选择的HTML标记“ btn”在任何标准中都不存在。您可能要选择:"button.btn-small, button.btn-next, button.btn-advance"
为什么在包含元数据块的GM脚本周围有setInterval?
如果它没有运行全部 –如果您甚至没有看到第一个警报,请重新安排代码一点:
==UserScript==
块必须是第一件事。我相信空白行是允许的,但是我不确定。
// ==UserScript==
// @name DriversEd Time Saver!
// @namespace [email protected]
// @description Automatically goes to the next slide once the next button is clickable.
// @copyright 2014+, Marque Kuem
// @license GPL version 3 or any later version; http://www.gnu.org/copyleft/gpl.html
// @license (CC); http://creativecommons.org/licenses/by-nc-sa/3.0/
// @version 0.1
// @icon https://driversed.com/img/logo.png
// @homepageURL https://duckduckgo.com/
// @supportURL https://duckduckgo.com/
// @include https://driversed.com/dashboard/course/*
// ==/UserScript==
setInterval(function (){
alert('Running!');
var clickNext = document.querySelectorAll("btn.btn-small.btn_next.btn-advance");
if(clickNext.length>0){
alert('Next is clickable.');
}
},2500);