【发布时间】:2016-03-16 08:21:27
【问题描述】:
是的,这基本上是同一个老问题。编写我的第一个 GreaseMonkey 脚本,脚本告诉我 GM_xmlhttpRequest 没有定义。经过进一步调查 - 我认为我一般无法访问 API,GM_info 给了我同样的问题。
这是完整的脚本:
// ==UserScript==
// @name Mirror Page
// @namespace mailto:linkhyrule5@gmail.com
// @description POSTs page to dynamic page mirror
// @include http://www.google.com
// @version 1
// @grant GM_xmlhttpRequest
// @grant GM_info
// ==/UserScript==
console.log(GM_info);
var ihtml = document.body.innerHTML;
GM_xmlhttpRequest({
method:'POST',
url:'http://localhost:5723/index.php',
data:"PageContents=" + escape(ihtml) + "\nURL=" + escape(document.URL),
headers: {'Content-Type': 'application/x-www-form-urlencoded'}
});
在 Google 主页上找到我
/*
Exception: ReferenceError: GM_info is not defined
@Scratchpad/1:11:1
*/
以及之前的GM_xmlhttpRequest is not defined。
在 Firefox 45.0 上运行 GreaseMonkey 3.7。我已重新启动 Firefox 并启用/禁用;该脚本纯粹存在于我的剪贴板和沙箱中,但就“删除脚本并从剪贴板重新创建”而言,我还重新安装了该脚本。
我现在尝试将文件复制到 .user.js 文件中并从那里安装;还是不行。
【问题讨论】: