2013-07-15 86 views
1

如何轉換使用deprecadted E4X的腳本?在不支持E4x的情況下轉換greasemonkey腳本

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 = [email protected]_id; 
     for each (com in comments.comment) { 
      var uname = [email protected]; 
      var nsid = [email protected]; 
      this.setTranslation({ uname: uname, nsid: nsid }); 
      // var create = new Date([email protected]); 
      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

+0

該腳本似乎沒有使用任何E4X。這可能不是問題。然而,劇本是7歲!自那時起,Flickr可能會發生很大的變化。爲你改寫腳本不是[so]的意思;閱讀[faq]瞭解如何改寫這個問題。 (提示:確切的錯誤消息,演示問題的代碼以及你曾嘗試過的代碼)。 –

+0

我認爲它是E4X:在「Bug 814633 - Firefox 17打破了依賴於E4X的Greasemonkey腳本(新增功能:Firefox 21完全刪除了它的支持)「Boris Zbarsky寫道: 用戶腳本的第558行是: var pid = comments。@ photo_id; 這絕對看起來像一個e4x主義對我來說。 還有幾條這樣的線。 只需在http:// userscripts中搜索名爲「ricCB」的函數即可。org/scripts/review/5016 我不希望你重寫代碼,但你只是簡單地解釋如何去做... – decembre

+0

好的,仔細檢查一下,它確實使用了E4X。但這仍然不是一個合適的SO問題。修復該腳本至少需要重構'parseXML'函數和所有其他使用其輸出的函數。你需要把它分解成可能幫助有同樣問題的人。這個問題需要一個SSCCE。閱讀[常見問題]並編輯您的問題,否則將被忽略並關閉。 –

回答

1

如果在E4X的依賴,嘗試包括JavaScript實現:

作爲替代,這裏有其他問題,其覆蓋製圖E4X語法XPath或XML到JSON:

此外,您可以繼續通過YQL訪問數據使用E4X:

參考

+0

感謝您的回覆。但我嘗試爲javascript實現做一個greasemonkey腳本,並用最後一個firefox測試它:沒有任何變化......一個想法? – decembre

+0

JavaScript實現使用Greasemonkey中的[XMLSerializer],它是[unsafe](http://www.greasespot.net/2005/12/workarounds-for-missing-xmlhttprequest.html)。作爲一種解決方法,將代碼複製並粘貼到您的腳本中,然後將'XMLSerializer'替換爲'unsafeWindow.XMLSerializer'以通過目標頁面訪問該API。請注意,目標頁面上的腳本有可能遵循'unsafeWindow'的用法返回Greasemonkey腳本引用,從而獲得[提升的權限](http://wiki.greasespot.net/UnsafeWindow)。 –

+0

我現在試着用你的解決方法,用unsafeWindow.XMLSerializer替換XMLSerializer的所有實例(見pastebin):JAVASCRIPT LIbrary for E4X - Greasemonkey script。似乎不好......也許是因爲我的GM的格式不對?你可以留意一下嗎? – decembre

相關問題