【问题标题】:Can't use jQuery on TamperMonkey extension?不能在 TamperMonkey 扩展上使用 jQuery?
【发布时间】:2020-03-04 01:24:17
【问题描述】:

我正在尝试在 TamperMonkey 上使用 jQuery,所以我像这样在头部添加了所需的

// ==UserScript==
// @name         Sliver.tv Bot
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  Sliver.tv betting bot
// @author       Pachi
// @include      https://www.sliver.tv/win/fortnite
// @include      https://www.sliver.tv/win/pubg
// @include      https://www.sliver.tv/win/csgo
// @match        https://www.sliver.tv/win/fortnite
// @match        https://www.sliver.tv/win/pubg
// @match        https://www.sliver.tv/win/cs
// @match        https://www.sliver.tv/win/*
// @match        https://www.sliver.tv/win*
// @grant        none
// @require http://code.jquery.com/jquery-3.3.1.min.js
// ==/UserScript==

$(".waw-prediction-card").each(function (index) {



        var SeleccionDeCarta = $(".waw-prediction-card").eq(index);
        var SeleccionDeOpciones = $(SeleccionDeCarta).find(".waw-prediction-choice--active");
        var CantidadDeOpciones = SeleccionDeOpciones.length;
        var Random = Math.floor(Math.random() * CantidadDeOpciones);


        var SeleccionFinal = $(SeleccionDeOpciones).eq(Random);
        SeleccionFinal[0].click();



    });

但我的脚本不工作。我在 "$" 旁边有一个黄色三角形,表示 $ 未定义,也许要求不起作用?

【问题讨论】:

  • 我不确定你的意思,我用完整的脚本编辑了
  • 我重新创建了脚本,首先添加了要求,保存,然后脚本并保存,sasme 错误;(
  • 出于好奇,您是否尝试过在您的脚本中访问window.$,而不是仅仅访问$ 以查看它是否有效?相关:stackoverflow.com/questions/51090754/…
  • 我试过了,错误消失了,但是脚本还没有工作,但是如果我在 chrome 的控制台上执行可以工作
  • 删除 @grant none 并且永远不要使用它,除非您真的需要在沙盒之外运行代码。

标签: javascript jquery google-chrome-extension


【解决方案1】:

我知道你必须做什么。在$(".waw-prediction-card")前加上这段代码:

var $ = window.jQuery;

【讨论】:

    猜你喜欢
    • 2014-04-10
    • 2013-06-19
    • 2013-09-03
    • 1970-01-01
    • 1970-01-01
    • 2020-01-04
    • 2021-07-29
    • 1970-01-01
    • 2017-12-10
    相关资源
    最近更新 更多