【网页主动化】篡改猴入门教程

打印 上一主题 下一主题

主题 976|帖子 976|积分 2928

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

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 实现定时操纵:
  1. // 每 5 秒执行一次
  2. setInterval(() => {
  3.     console.log('定时任务执行中...');
  4.     const button = document.querySelector("#buttonID");
  5.     if (button) button.click();
  6. }, 5000);
复制代码
动态URL匹配

利用正则表达式匹配多种 URL:
  1. // ==UserScript==
  2. // @match        https://*.example.com/*
  3. // @match        https://another-site.com/page/*
  4. // ==/UserScript==
复制代码
高级权限

通过 @grant 利用更多功能,如跨域请求或本地存储:

  1. // ==UserScript==
  2. // @grant GM_xmlhttpRequest
  3. // @grant GM_setValue
  4. // @grant GM_getValue
  5. // ==/UserScript==
  6. // 示例:跨域请求
  7. GM_xmlhttpRequest({
  8.     method: 'GET',
  9.     url: 'https://api.example.com/data',
  10.     onload: function(response) {
  11.         console.log('数据加载成功:', response.responseText);
  12.     }
  13. });
复制代码
示例:主动登录脚本

  1. // ==UserScript==
  2. // @name         自动登录
  3. // @namespace    http://tampermonkey.net/
  4. // @version      1.0
  5. // @description  自动填写用户名和密码并登录
  6. // @match        https://login.example.com/*
  7. // @grant        none
  8. // ==/UserScript==
  9. (function() {
  10.     'use strict';
  11.     // 自动填充用户名和密码
  12.     const usernameField = document.querySelector("#username");
  13.     const passwordField = document.querySelector("#password");
  14.     const loginButton = document.querySelector("#loginButton");
  15.     if (usernameField && passwordField && loginButton) {
  16.         usernameField.value = "myUsername";
  17.         passwordField.value = "myPassword";
  18.         console.log("用户名和密码已填写");
  19.         // 自动点击登录按钮
  20.         loginButton.click();
  21.         console.log("登录按钮已点击");
  22.     }
  23. })();
复制代码


免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。
回复

使用道具 举报

0 个回复

倒序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则

魏晓东

金牌会员
这个人很懒什么都没写!
快速回复 返回顶部 返回列表