马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
x
安装篡改猴
- 打开浏览器扩展市肆(Edge、Chrome、Firefox 等)。
- 搜刮 Tampermonkey 并安装。
- 安装后,浏览器右上角会显示一个带有猴子图标的按钮。
创建用户脚本
脚本表明阐明
- @name:脚本名称。
- @namespace:脚本唯一标识,可随意设置。
- @version:脚本版本。
- @description:脚本形貌。
- @match:脚本运行的网页 URL 模式(支持通配符 *)。
- 示例:https://example.com/* 表示脚本在全部 example.com 的页面运行。
- @grant:声明权限。
- none:不利用任何特殊权限。
- 可用权限:参考Tampermonkey 文档。
生存并测试脚本
- 在编辑器中,按 Ctrl+S 或点击生存按钮。
- 打开与 @match 中 URL 对应的网页。
- 打开开发者工具(F12),在控制台检察脚本日志,确保脚本正常运行。
进阶操纵
定时任务
通过 setInterval 或 setTimeout 实现定时操纵:
- // 每 5 秒执行一次
- setInterval(() => {
- console.log('定时任务执行中...');
- const button = document.querySelector("#buttonID");
- if (button) button.click();
- }, 5000);
复制代码 动态URL匹配
利用正则表达式匹配多种 URL:
- // ==UserScript==
- // @match https://*.example.com/*
- // @match https://another-site.com/page/*
- // ==/UserScript==
复制代码 高级权限
通过 @grant 利用更多功能,如跨域请求或本地存储:
- // ==UserScript==
- // @grant GM_xmlhttpRequest
- // @grant GM_setValue
- // @grant GM_getValue
- // ==/UserScript==
- // 示例:跨域请求
- GM_xmlhttpRequest({
- method: 'GET',
- url: 'https://api.example.com/data',
- onload: function(response) {
- console.log('数据加载成功:', response.responseText);
- }
- });
复制代码 示例:主动登录脚本
- // ==UserScript==
- // @name 自动登录
- // @namespace http://tampermonkey.net/
- // @version 1.0
- // @description 自动填写用户名和密码并登录
- // @match https://login.example.com/*
- // @grant none
- // ==/UserScript==
- (function() {
- 'use strict';
- // 自动填充用户名和密码
- const usernameField = document.querySelector("#username");
- const passwordField = document.querySelector("#password");
- const loginButton = document.querySelector("#loginButton");
- if (usernameField && passwordField && loginButton) {
- usernameField.value = "myUsername";
- passwordField.value = "myPassword";
- console.log("用户名和密码已填写");
- // 自动点击登录按钮
- loginButton.click();
- console.log("登录按钮已点击");
- }
- })();
复制代码
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。 |