Tampermonkey's GM_xmlhttpRequest not implementing 'context' property?

て烟熏妆下的殇ゞ 提交于 2019-12-04 15:20:28
Brock Adams

Update:
Tampermonkey now reports that this feature is fixed as of version 3.8.4116 (in beta at the moment). See:


Older/generic workaround:
The context property is a relatively new feature of GM_xmlhttpRequest(), in Firefox. I doubt it's been implemented in Tampermonkey yet; see Tampermonkey's docs for GM_xmlhttpRequest().

Meanwhile, the tried-and-true method for this kind of thing is to use a closure.

Change your GM_xmlhttpRequest() call to something like:

( function (flair_index, flair_text, encoded_name, profile_url, query_url) {
    GM_xmlhttpRequest ( {
        method: 'GET',
        url:    xml_url, // Link to a steam profile with ?xml=1 added
        accept: 'text/xml',
        onreadystatechange: function (response) {
            if (response.readyState != 4)
                return;

            var doc = parser.parseFromString (response.responseText, 'text/xml');
            var validProfile = doc.documentElement.nodeName == 'profile';
            var a = document.createElement ('a');
            a.href = validProfile ?
                profile_url : 
                ('http://steamcommunity.com/actions/SearchFriends?K=' + encoded_name);
            a.className += (validProfile ? 'steam-profile-link' : 'steam-profile-search-link');
            var a_text = document.createTextNode (flair_text);
            a.appendChild (a_text);
            set_text (flairs[flair_index], '');
            flairs[flair_index].appendChild (a);
        }
    } );
} ) (
    i,
    text, // textContent of span element
    name,
    url, // Link to steam profile
    xml_url
);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!