黄聪:Greasemonkey研究,通过GM_xmlhttpRequest获取远程URL的内容

最近开发火狐,没有任何工具开发程序真的好痛苦,调试JS,只能先依赖Greasemonkey了,今天测试了一下用GM_xmlhttpRequest获取远程URL的内容。在此马克一下。

// ==UserScript==
// @name        GetDZ
// @namespace   hcsem.com
// @description 从新浪获取当前地址
// @version     1
// @run-at      document-end
// @require     http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js
// @grant GM_xmlhttpRequest
// ==/UserScript==
var fullUrl = "http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=js";

GM_xmlhttpRequest({
    method: 'GET',
    url: fullUrl,
    headers: {
        'User-agent': 'Mozilla/4.0 (compatible) Greasemonkey',
        'Accept': 'application/atom+xml,application/xml,text/xml',
    },
    onload: function(responseDetails) {
        
        eval( responseDetails.responseText );
        var dz = remote_ip_info.country + " > " + remote_ip_info.province + " > " + remote_ip_info.city;
        alert(dz);
    }
});

运行结果:

原文地址:https://www.cnblogs.com/huangcong/p/3129830.html