I'm playing in the GreaseMonkey sandbox, trying to make a script that forwards loaded pages to another server for processing through POST. Here's the script:
// ==UserScript==
// @name Mirror Page
// @namespace mailto:linkhyrule5@gmail.com
// @description POSTs page to dynamic page mirror
// @include http://*
// @include https://*
// @version 1
// @grant GM_xmlhttpRequest
// ==/UserScript==
var ihtml = document.body.innerHTML;
GM_xmlhttpRequest({
method: 'POST',
url: 'http://localhost:5723/index.php',
data: "PageContents=" + encodeURIcomponent(ihtml) + "\nURL=" + encodeURIcomponent(document.URL),
headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
});
Somehow, I'm getting encodeURIcomponent is not defined
, even though it's a global function and should be available anywhere JavaScript is. I assume I'm misunderstanding something?
You forgot that Capital C... Its like Camel-Case:
var ihtml = document.body.innerHTML;
GM_xmlhttpRequest({
method: 'POST',
url: 'http://localhost:5723/index.php',
data: "PageContents=" + encodeURIComponent(ihtml) + "\nURL=" + encodeURIComponent(document.URL),
headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
});