読込に失敗した画像を再読込する その2
読込状況がさっぱり分からない状況を改善してみた。
status bar に 左から 読込中 失敗 更新完了 の 数 を 表示 するように 機能を追加しました。
ただし、表示されるのは最後に実行した reloadimages のものになります。
ベストは、各タブ毎に 実行した結果が 出ることだと思うけど、
複数同時実行しない限り問題無いので妥協しちゃいました…
TabUnselect みたいな イベントあると 良いなぁ
diffとったら、3行しか 一致しなかったので全コード
(function(){ const id="reload-image-info"; let txt=document.getElementById(id); if(!txt){ let pnl=document.getElementById("liberator-statusline"); txt=document.createElement("label"); txt.setAttribute("id", id); txt.setAttribute("class", "plain"); pnl.appendChild(txt); } let info={ load:0,fail:0,success:0,count:0 ,reset:function(){ this.load=this.fail=this.success=0; ++this.count; } }; function refresh(){ txt.value = "["+info.load+"/"+info.fail+"/"+info.success+"]"; txt.setAttribute("tooltiptext","reload:"+info.load+"\nfail:"+info.fail+"\nsuccess:"+info.success); } let iterator=liberator.modules.util.Array.itervalues; function reloadimages(){ info.reset(); refresh(); let cnt = info.count; (function(aWindow){ for(let f in iterator(aWindow.frames)) arguments.callee(f); for(let img in iterator(aWindow.document.images)){ if(img instanceof Ci.nsIImageLoadingContent && img.currentURI){ req = img.getRequest(Ci.nsIImageLoadingContent.CURRENT_REQUEST); if(req && !(req.imageStatus & req.STATUS_LOAD_COMPLETE)){ let imgObserver ={ onStopRequest:function(aRequest,aIsLastPart){ if(cnt == info.count){ --info.load; if(aRequest.imageStatus & aRequest.STATUS_LOAD_COMPLETE) ++info.success; else ++info.fail; refresh(); } img.removeObserver(imgObserver); } }; img.addObserver(imgObserver); ++info.load; refresh(); img.forceReload(); } } } })(content.window); }; commands.addUserCommand(["reloadimage"],"reload images",function() reloadimages(),{argCount:"0"},true); })();