Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/374.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
用户/Javascript格式_Javascript_Greasemonkey_Userscripts - Fatal编程技术网

用户/Javascript格式

用户/Javascript格式,javascript,greasemonkey,userscripts,Javascript,Greasemonkey,Userscripts,这是我当前的代码: setInterval(function (){ // ==UserScript== // @name DriversEd Time Saver! // @namespace pandather@gmail.com // @description Automatically goes to the next slide once the next button is clickable. // @copyright 2014+, Marq

这是我当前的代码:

setInterval(function (){
// ==UserScript==
// @name          DriversEd Time Saver!
// @namespace     pandather@gmail.com
// @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\u next
.btn advance
的按钮。您的查询选择的HTML标记“btn”在任何标准中都不存在。您可能需要选择:
“button.btn-small,button.btn-next,button.btn-advance”

为什么在包含元数据块的GM脚本周围有setInterval?

如果它根本没有运行——如果您甚至没有看到第一个警报,请稍微重新安排代码:

==UserScript==
块必须是第一件事。我相信空行是允许的,但我记不清了

// ==UserScript==
// @name          DriversEd Time Saver!
// @namespace     pandather@gmail.com
// @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);

欢迎光临!默认情况下,Greasemonkey用户脚本在触发
DOMContentLoaded
事件时运行,因此使用
$(document).ready()
不会执行任何操作。您肯定需要将
setInterval(function(){
行移到元数据块下面。