I have never used Express before, but this application looks like this:
__parseJSONPResponse("\"hi buddy!\"");
which is placed in the <script> node in the landing page area .
This means that the Greasemonkey script must also place the __parseJSONPResponse function in the landing page area.
One way to do this:
unsafeWindow.__parseJSONPResponse = function (data) { alert (data); }
However, it looks like you are in control of the Express application. If this is true, then do not use JSONP for this kind of thing. Use GM_xmlhttpRequest () .
app.js can become:
var express = require ("express"); var app = express (); var fs = require ('fs'); var stringforfirefox = 'hi buddy!' app.get ('/getJSONPResponse', function (req, res) { res.send (JSON.stringify (stringforfirefox) ); } ); app.listen (8001)
And the GM script will be something like this:
// ==UserScript== // @name greasemonkeytestscript // @namespace http://www.example.com/ // @description jQuery test script // @include * // @require http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js // @grant GM_xmlhttpRequest // ==/UserScript== document.onkeypress = function keypressed (e){ if (e.keyCode == 112) { GM_xmlhttpRequest ( { method: 'GET', url: 'http://localhost:8001/getJSONPResponse', onload: function (respDetails) { alert (respDetails.responseText); } } ); } }
source share