javascript - $ 未定义 Javascript

标签 javascript jquery tampermonkey

<分区>

我目前正在 tampermonkey 中编写一段代码,我无法弄清楚为什么我在 google chrome 的控制台中收到此错误,“脚本 'PalaceBOT' 的执行失败!$ 未定义”,我有另一个使用相同原则的脚本,我没有遇到这些问题。

脚本:

// ==UserScript==
// @name         SupremeBOT
// @namespace
// @version      0.1
// @description
// @author       @alfiefogg_
// @match        http://www.supremenewyork.com/shop/*
// @exclude      http://wwww.supremenewyork.com/shop/cart
// @require      https://gist.github.com/raw/2625891/waitForKeyElements.js
// @require      http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js
// @grant        none
// ==/UserScript==
var mySize = "large"; //Change to appropriate size
var productSort = "accessories"; //Change to appropriate size
(function() {
    var articles = $(".product-grid-item clearfix");
    if(productSort != "all"){
        for(var i = 0; i < articles.length;i++)
        {
            var category = $(articles[i]).find("a").attr("href");
            if(category.indexOf(productSort) == -1){
                articles[i].remove();
                document.getElementsByClassName("product-grid-item clearfix")[4].click();
            }
        }
    }
    waitForKeyElements("#img-main", exe);
})();
function exe(){
    selectSize();
    goCheckout();
}
function goCheckout(){
    var x = document.getElementById("add-remove-buttons");
    var z = x.getElementsByClassName("button")[0];

    if(z.className != "button remove"){
        z.click();
        setTimeout(goCheckout ,100);
    }else{
        window.location = "https://www.supremenewyork.com/checkout";
    }
}
function selectSize(){
    var sizeObj = document.getElementById("size");
    for(var i=0,sL=sizeObj.length;i<sL;i++){
        if(sizeObj.options[i].text == mySize){
            sizeObj.selectedIndex = i;
            break;
        }
    }
}

请记住,这不是一个完成的脚本。

最佳答案

从窗口对象获取jQuery

var $ = window.jQuery;

关于javascript - $ 未定义 Javascript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43924769/

相关文章:

javascript - jQuery on click 处理程序未在 asp.net 组件上激活

javascript - 标签式菜单动画

执行 "ctrl"+ "click"时,jQuery OnClick 在 IE 中不起作用

javascript - 为什么 '0' 不等于一个空列表?

javascript - jQuery Datepicker UI 动画不工作

JavaScript:document.getElementById 性能低下?

javascript - 我的代码可以在 Firefox 控制台中运行,但不能在 Tampermonkey 中运行? (不是时间问题)

javascript - 如何解决错误 "Did not load script at ' 脚本名称',因为在给出 'X-Content-Type: nosniff' 时不允许使用非脚本 MIME 类型

javascript - jQuery 插件不适用于子域

javascript - 如何在 Tampermonkey 中捕获/观看 Javascript 中的附加触发器?