5/30/2012

批量删除Kindle Library中的文档

  我一般都是用邮件给自己的Kindle、Kindle App for iOS/Android发送书籍文章。也直接用dogear狗耳朵ikindle爱看豆等订阅新闻之类的,不用连线的感觉很爽!经常用这个功能的童靴们都知道,每一个文档都会在出现你的Kindle Library中。长期积累下来想找一个以前传送过的文档很麻烦,尤其是Kindle Library还不支持中文搜索。
  我用dogear狗耳朵每日推送的看完就删除,但一直留在Kindle Library实在很烦。而且在Kindle Library里边还得一个一个地删除,每次删除一个文档页面就要自动刷新。在手工删了几十个之后实在不能忍了,只好放狗搜索。在Kindle forum里找到一个解决办法:http://goo.gl/ggjBH。但是他的方法只能一下子删除一整页(15个)。或者进行搜索,在搜索结果页面进行删除。于是自己基于Giacomo1871的脚本修改了一下。
  使用方法如下,译自英文回复:
  非常感谢Giacomo1871。你的方法确实有用!我另外做了一个可以更加灵活地删除条目的Bookmarklet。类似地:1.将代码加入书签栏。2.在Personal Documents页面,点击一下这个书签,然后在每个条目之前会出现一个复选框。3.选择你想删除条目对应的复选框。当然也有全部选择、全部不选和反向选择的快速连接。4.再次点击书签,被选择的条目将被删除。
  代码如下:
javascript:(function(){ var v = new RegExp('PersonalDocuments'); if (!v.test(document.URL)) { return false; } {a=document.getElementsByClassName('rowBodyCollapsed');b=document.getElementsByName('checkboxForDelete');if(b.length==0){document.getElementById('Row1Button').innerHTML += "<a href='javascript:(function(){for(var i=0;i<b.length;i++){b[i].checked=true;};})();'>All</a><a href='javascript:(function(){for(var i=0;i<b.length;i++){b[i].checked=false;};})();'> None</a><a href='javascript:(function(){for(var i=0;i<b.length;i++){b[i].checked=!b[i].checked;};})();'> Reverse</a>";for(var i = 0; i<a.length; i++){ tmp=document.getElementById('Row' + (i+1) + 'Button'); tmp.innerHTML += "<input type='checkbox' name='checkboxForDelete' />";};}else{for(var i = 0; i<b.length; i++){if(b[i].checked){Fion.deleteItem('deleteItem_'+a[i].getAttribute('asin'));}};}return;}})();

请使用下面的代码,修复了某些浏览器中在非Personal Documents页面中执行脚本会跳转页面的bug:
javascript:(function(){ var v = new RegExp('PersonalDocuments'); if (!v.test(document.URL)) {alert("The script can only work in Personal Documents!");}else{a=document.getElementsByClassName('rowBodyCollapsed');b=document.getElementsByName('checkboxForDelete');if(b.length==0){document.getElementById('Row1Button').innerHTML += "<a href='javascript:(function(){for(var i=0;i<b.length;i++){b[i].checked=true;};})();'>All</a><a href='javascript:(function(){for(var i=0;i<b.length;i++){b[i].checked=false;};})();'> None</a><a href='javascript:(function(){for(var i=0;i<b.length;i++){b[i].checked=!b[i].checked;};})();'> Reverse</a>";for(var i = 0; i<a.length; i++){ tmp=document.getElementById('Row' + (i+1) + 'Button'); tmp.innerHTML += "<input type='checkbox' name='checkboxForDelete' />";};}else{for(var i = 0; i<b.length; i++){if(b[i].checked){Fion.deleteItem('deleteItem_'+a[i].getAttribute('asin'));}};}return;}})();



For English Users:

Thanks for Giacomo1871. It does work! And I've made another bookmarklet can delete items more flexibly. Likewise: 1.Make a bookmarklet. 2.In personal documents page, click the bookmarklet, and there will be a checkbox in front of every item. 3.Select the box if you want delete the item, and there are three links can select ALL, NONE and REVERSE. 4.Click the bookmarklet again, the selected items will be deleted perfectly!
Here you are:
javascript:(function(){ var v = new RegExp('PersonalDocuments'); if (!v.test(document.URL)) { return false; } {a=document.getElementsByClassName('rowBodyCollapsed');b=document.getElementsByName('checkboxForDelete');if(b.length==0){document.getElementById('Row1Button').innerHTML += "<a href='javascript:(function(){for(var i=0;i<b.length;i++){b[i].checked=true;};})();'>All</a><a href='javascript:(function(){for(var i=0;i<b.length;i++){b[i].checked=false;};})();'> None</a><a href='javascript:(function(){for(var i=0;i<b.length;i++){b[i].checked=!b[i].checked;};})();'> Reverse</a>";for(var i = 0; i<a.length; i++){ tmp=document.getElementById('Row' + (i+1) + 'Button'); tmp.innerHTML += "<input type='checkbox' name='checkboxForDelete' />";};}else{for(var i = 0; i<b.length; i++){if(b[i].checked){Fion.deleteItem('deleteItem_'+a[i].getAttribute('asin'));}};}return;}})();

Please use the code blow below, fix a bug existed in a few browsers which would redirect page if you run this script in the NONE Personal Documents page:
javascript:(function(){ var v = new RegExp('PersonalDocuments'); if (!v.test(document.URL)) {alert("The script can only work in Personal Documents!");}else{a=document.getElementsByClassName('rowBodyCollapsed');b=document.getElementsByName('checkboxForDelete');if(b.length==0){document.getElementById('Row1Button').innerHTML += "<a href='javascript:(function(){for(var i=0;i<b.length;i++){b[i].checked=true;};})();'>All</a><a href='javascript:(function(){for(var i=0;i<b.length;i++){b[i].checked=false;};})();'> None</a><a href='javascript:(function(){for(var i=0;i<b.length;i++){b[i].checked=!b[i].checked;};})();'> Reverse</a>";for(var i = 0; i<a.length; i++){ tmp=document.getElementById('Row' + (i+1) + 'Button'); tmp.innerHTML += "<input type='checkbox' name='checkboxForDelete' />";};}else{for(var i = 0; i<b.length; i++){if(b[i].checked){Fion.deleteItem('deleteItem_'+a[i].getAttribute('asin'));}};}return;}})();

4 comments: