用户/ Javascript格式化

User/Javascript formatting

本文关键字:格式化 Javascript 用户      更新时间:2023-09-26

这是我当前的代码:

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?

如果它根本没有运行—如果您甚至没有看到第一个警告,请重新排列您的代码:

==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);

文档需要准备好,试试这个:

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,包括元数据块?