LMLPHP后院

油猴子插件指南技术

maybe yes 发表于 2022-09-15 23:49

油猴子插件怎么用?

确实是个好东西,降低了开发 Chrome 插件的门槛,是个不错的选择。

插件对于开发来讲,收集数据是必备的,也就是所谓的前端爬虫。

但是,油猴子插件在编写脚本的注释中没有好的指引,以至于老手也会被它搞得不知道为什么没用。

先看下面的栗子

// ==UserScript==
// @name         New Userscript
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  try to take over the world!
// @author       You
// @match        https://domain.com/* // 这里非常重要
// @grant        GM_xmlhttpRequest // 这里是引用功能
// @run-at       document-end
// @connect      *
// ==/UserScript==

(function() {
    'use strict';

    GM_xmlhttpRequest({
        "method": "post",
        "url": "http://localdev.com:8080/store",
        "data": $.param({"a":"a"}),
        "headers":{"Content-Type":"application/x-www-form-urlencoded"},
        "onload":function(r){
        }
    });

})();
2024-04-26 09:16:32 1714094192 0.017258