-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathkhl_bookmarklet.min.js
1 lines (1 loc) · 2.65 KB
/
khl_bookmarklet.min.js
1
javascript:(function(e){e.KHL={used_asins:[],offset:null,totalHighlights:0,imported:[],nextBookUrl:"https://kindle.amazon.com/your_highlights/next_book",getNextBook:function(){var e=this;var t={};if(e.offset!==null){t={"used_asins[]":e.used_asins,current_offset:e.offset}}$.get(e.nextBookUrl,t,function(t){e.process(t)},"html")},process:function(e){var t=this;if(e===""){t.end();return true}var n=$(e);var r=n.filter(".bookMain")[0];var i=$(r).find(".title a")[0];i=$(i).text();var s=$(r).attr("id").split("_");var o=s[0];t.offset=s[1];t.used_asins.push(o);var u=n.filter(".yourHighlight");var a=[];$.each(u,function(e){var t=$(u[e]).find("a.readMore").attr("href");var n=t.match(/location=(\d+)/)[1];a.push({content:$(u[e]).find(".highlight").text(),comment:$(u[e]).find(".noteContent").text(),kindleLocation:n})});var f={asin:o,title:i,highlightedText:a,cover:"http://images.amazon.com/images/P/"+o+".01.TZZ.jpg"};t.progress(f);t.getNextBook()},progress:function(e){var t=this;var n="http://images.amazon.com/images/P/"+e.asin+".01.TZZ.jpg";t.totalHighlights+=e.highlightedText.length;var r="highlight";if(e.highlightedText.length>1){r=r+"s"}t.imported.unshift(e);$("#cv").html("<img src='"+n+"'>");$("#cb").html(e.highlightedText.length+" "+r+' from "'+e.title+'"')},saveData:function(e,t){var n=document.createElement("a");document.body.appendChild(n);n.style="display: none";var r=JSON.stringify(e),i=new Blob([r],{type:"octet/stream"}),s=window.URL.createObjectURL(i);n.href=s;n.download=t;n.click();window.URL.revokeObjectURL(s)},end:function(){var e=this;var t=new Date;var n=t.getFullYear()+"-"+t.getMonth()+1+"-"+t.getDate();var r="kindle_highlights_"+n+".json";var i={};i.totalHighlights=e.totalHighlights;i.highlights=e.imported;e.saveData(i,r);$("#khl").remove();delete window.KHL},start:function(){var e=this;if(window.location.href!="https://kindle.amazon.com/your_highlights"){if(confirm("You must be logged into http://kindle.amazon.com/your_highlights to save your highlights. Go there now?")){window.location.href="https://kindle.amazon.com/your_highlights"}else{return false}}else{e.getNextBook();$("body").prepend("<div id='khl' style='position: fixed; width: 100%; height: 120px; background-color: rgba(100, 100, 100, .75); border: 1px solid black; z-index: 1000;'><div style='display: block; position: relative; margin: 0px 0px 0px 50px; height: 100%; line-height: 120px; font-size: 18px; color: white;'><span id='cv' style='display: inline-block; width: 75px; height: 110px; margin: 5px 25px 5px 0px;'></span><span id='cb' style='display: inline-block; position: absolute; margin: auto; height: 100%; line-height: 120px;'>IMPORTING HIGHLIGHTS...</span></div></div>")}}}})(window);KHL.start()