1

How to convert this script which use deprecadted E4X ?

Flickr Functional Suite.

i am not a programmer, but if you explain to me where i need to start, i do my best.

In first , it seems not a problem of CDATA ...

Here a link, in Buggzilla , where i describe my problem : Firefox 17 breaks a Greasemonkey script that relies on E4X (New : Firefox 21 delete totally its support)

I obtain here a first indice where E4x is in use (search in the code "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);
        }
    }

Initially posted here : My Greasemonkey script stopped working after something updated

Community
  • 1
  • 1
decembre
  • 11
  • 1
  • 1
  • 4
  • That script does not appear to use any E4X. That's probably not the problem. However, the script is 7 years old! Flickr has likely changed quite a bit since then. Rewriting that script for you is not what [so] is for; read the [faq] for ideas on how to rewrite this question. (Hint: exact error messages, code that demos the problem, and what you have tried.) – Brock Adams Jul 15 '13 at 10:40
  • I thinks it's E4X : in "Bug 814633 - Firefox 17 breaks a Greasemonkey script that relies on E4X (New : Firefox 21 delete totally its support)" Boris Zbarsky write: Line 558 of the user script is: var pid = comments.@photo_id; which definitely looks like an e4x-ism to me. There are a few more lines like that. Just search for the function called "ricCB" in http://userscripts.org/scripts/review/5016 And i don't want you rewrite the code , but you explain simply how to do... – decembre Jul 15 '13 at 14:24
  • Okay, on closer inspection, it does use E4X. But this is still not a proper SO question. Fixing that script requires, at a minimum, refactoring the `parseXML` function and all the other functions that use its output. You need to break it down into bits that might help someone with the same problem. This question needs an SSCCE. Read the [faq] and edit your question, or it will get ignored and closed. – Brock Adams Jul 15 '13 at 21:17

1 Answers1

1

If there is a dependency on e4x, try including the JavaScript implementation:

As an alternative, here are other questions which cover mapping e4x syntax to XPath or XML to JSON:

In addition, you can continue to use e4x by accessing the data via yql:

References

Community
  • 1
  • 1
Paul Sweatte
  • 24,148
  • 7
  • 127
  • 265
  • Thanks for your reply . But i try to do a greasemonkey script for the javascript implementation and test it with the last firefox: nothing change.... An idea? – decembre Dec 15 '13 at 21:48
  • The JavaScript implementation uses `XMLSerializer`, which is [unsafe](http://www.greasespot.net/2005/12/workarounds-for-missing-xmlhttprequest.html) in Greasemonkey. As a workaround, copy and paste the code into your script, then replace `XMLSerializer` with `unsafeWindow.XMLSerializer` to access that API via the target page. Be aware that it is possible for scripts on the target page to follow `unsafeWindow` usage back to the Greasemonkey script reference and thus gain [elevated privileges](http://wiki.greasespot.net/UnsafeWindow). – Paul Sweatte Dec 16 '13 at 18:21
  • I try now with your workaround by replacing all instance of XMLSerializer by unsafeWindow.XMLSerializer(see in pastebin):JAVASCRIPT LIbrary for E4X - Greasemonkey script. seems not good... Maybe because a wrong format of my GM? Can you drop an eye on it? – decembre Dec 17 '13 at 01:09