$未定义Javascript

我正在编写一段当前在tampermonkey中的代码,我无法弄清楚为什么我在谷歌浏览器的控制台中出现这个错误,“执行脚本’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;
        }
    }
}

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

解决方法

从window对象获取jQuery
var $= window.jQuery;

相关文章

前言 做过web项目开发的人对layer弹层组件肯定不陌生,作为l...
前言 前端表单校验是过滤无效数据、假数据、有毒数据的第一步...
前言 图片上传是web项目常见的需求,我基于之前的博客的代码...
前言 导出Excel文件这个功能,通常都是在后端实现返回前端一...
前言 众所周知,js是单线程的,从上往下,从左往右依次执行,...
前言 项目开发中,我们可能会碰到这样的需求:select标签,禁...