在不支持E4x之后转换greasemonkey脚本

时间:2013-07-15 10:05:55

标签: javascript firefox greasemonkey e4x forward-compatibility

如何转换使用了弃草E4X的脚本?

Flickr Functional Suite

我不是程序员,但如果你向我解释我需要从哪里开始,我会尽我所能。

首先,它似乎不是CDATA的问题......

这是一个链接,在Buggzilla中,我描述了我的问题: Firefox 17 breaks a Greasemonkey script that relies on E4X (New : Firefox 21 delete totally its support)

我在这里获得了第一个使用E4x的指标(在代码中搜索“ricCB”):

requestImageComments: function( id ) {
    if (!id) return;
    var tkey = 'getComments';
    // Set up ticket status queue if needed
    if (!this.ticketStatus[tkey]) this.ticketStatus[tkey] = new Object();
    return this.flickrApi
    ( { method: 'flickr.photos.comments.getList', photo_id: id },
      'ricCB', {ticktype: tkey} );
},
ricCB: function(rsp) {
    var hash = this.objects.comments;
    for each (comments in rsp.comments) {
        // for (var cs = 0; cs < rsp.comments.length; cs++) {
        // var comments = rsp.comments[cs];
        var pid  = comments.@photo_id;
        for each (com in comments.comment) {
            var uname  = com.@authorname;
            var nsid   = com.@author;
            this.setTranslation( { uname: uname, nsid: nsid } );
            // var create = new Date( com.@datecreate );
            var ctxt  = com + '';
            // Strip out HTML tags:
            ctxt = ctxt.replace(/(\<|\&lt\;).+?(\>|\&gt\;)/g,'');
            // Collapse all whitespace runs to single spaces:
            ctxt = ctxt.replace(/[\s\n\r\t]+/g, ' ');
            // Store data under both authorname and photo ID (hash
            // will collide only if someone is using a pure
            // integer as a name AND a photo has same integer).
            var info = { txt: ctxt, uname: uname, photo: pid };
            if (!hash[uname]) hash[uname] = new Array();
            if (!hash[pid])   hash[pid]   = new Array();
            hash[uname].push(info);
            hash[pid].push(info);
        }
    }

最初发布在这里: My Greasemonkey script stopped working after something updated

1 个答案:

答案 0 :(得分:1)

如果依赖e4x,请尝试包含JavaScript实现:

作为替代方案,这里还有其他问题,包括将e4x语法映射到XPath或XML到JSON:

此外,您可以通过yql:

访问数据继续使用e4x

<强>参考