javascript - Tampermonkey 匹配所有子目录

标签 javascript regex google-chrome match tampermonkey

我正在使用 Tampermonkey 在表单的每个页面上运行脚本:

https://markus.teach.cs.toronto.edu/csc413-2020-01/assignments/2/submissions/329/results/329/edit

一般结构在哪里

https://markus.teach.cs.toronto.edu/csc413-2020-01/assignments/2/submissions/#NUM/results/#NUM/edit

我尝试通过以下方式匹配此网址: https://markus.teach.cs.toronto.edu/csc413-2020-01/assignments/2/*,但此模板未触发脚本。

完整的脚本如下:

// ==UserScript==
// @name         CSC413 autoscript
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  Automation
// @author       II
// @match https://markus.teach.cs.toronto.edu/csc413-2020-01/assignments/2/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';
    console.log("script running");
    //code here
    console.log("finished execution");
})();

有人知道这是怎么回事吗?如果我使用通用的,它会匹配 @include https://*/*

最佳答案

您需要转义斜杠和点,因为它们在正则表达式中具有特殊含义。 并且您需要在星号前添加一个点。点表示任意一个字符。这位明星将其量化为“零个或更多”。 .* 计算一切。在您的代码中编写/*。上面写着“零个或多个斜杠”

https:\/\/markus\.teach\.cs\.toronto\.edu\/csc413-2020-01\/assignments\/2\/.*

演示 https://regex101.com/r/CRtpWT/1

关于javascript - Tampermonkey 匹配所有子目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60469965/

相关文章:

javascript - v-html 中的 Vue.js v-model

javascript - 如何在 JavaScript 的 JSON 数组中搜索特定参数?

javascript - 如何使用正则表达式识别一组字符和数字以及由符号组成的组?

Python 正则表达式不匹配 http ://

javascript - 你如何捕捉流转换错误?

javascript - JavaScript 中的 match() 有什么问题?

css - 如何防止浏览器缓存 CSS 文件?

javascript - Chrome 在拖动时将光标设置为文本,为什么?

python - 无法使用 Selenium 将文本发送到 Microsoft 登录页面上的电子邮件字段

javascript - firefox 自动触发名为 'onload' 的 javascript 函数