1

如何转换这个使用过时 E4X 的脚本?

Flickr 功能套件

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

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

这是 Buggzilla 中的一个链接,我在其中描述了我的问题: Firefox 17 破坏了依赖 E4X 的 Greasemonkey 脚本(新:Firefox 21 完全删除了它的支持)

我在这里获得了使用 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);
        }
    }

最初发布在这里: 我的 Greasemonkey 脚本在更新后停止工作

4

1 回答 1

1

如果存在对 e4x 的依赖,请尝试包含 JavaScript 实现:

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

另外,通过yql访问数据,可以继续使用e4x:

参考

于 2013-09-04T20:24:11.337 回答