Skip to content

Commit

Permalink
Fix ACRExtensions doesn't work on the latest read.amazon.com #14
Browse files Browse the repository at this point in the history
  • Loading branch information
ccimpoi committed Jan 3, 2021
1 parent dc16a1f commit 2ffbd7b
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 73 deletions.
9 changes: 5 additions & 4 deletions README.md
Expand Up @@ -10,13 +10,14 @@ This bookmarklet enables you easily copy the text you select in the Amazon Cloud

Once activated, the bookmarklet will create an extra Copy button in addition to Highlight and Note that will open the selected text in a popup window so the user can easily copy it and also keep the basic HTML formatting.

Once activated, the bookmarklet will override the Highlight function and add a prompt where the user can choose to continue with the highlighting action or copy the text in a new popup window and keep the basic HTML formatting.

Please note that altough the text remains highlighted after copying, the highlight is not actually saved to the server and is only a local cache.

In your browser do an "Add bookmark" action on the Bookmarks Bar and enter "ACRExtensions" for the name and copy and paste the bookmarklet code from the [raw source](https://raw.github.com/binarycrafts/ACRExtensions/master/bookmarklet/bookmarklet.js).

Once you have the bookmarklet set up you just need to click on it once right after the Amazon Cloud Read app is loaded.

Important note regarding the issue of the Copy button not showing up. This is pretty hard to reproduce but it still happens some times. The fix is to reload the browser page and click again on the bookmarklet button. It always works for me.

Source available in the bookmarklet folder.

Tested in Chrome and FF on Ubuntu and OSX. The bookmarklet uses document ranges so it may not work in all browsers especially IE.

Tested in Chrome and FF on OSX. The bookmarklet uses document ranges so it may not work in all browsers especially IE.
105 changes: 36 additions & 69 deletions bookmarklet/bookmarklet.js
@@ -1,76 +1,43 @@
javascript: (function () {

var w = null;
var kDoc = null;
var kObj = null;

if (typeof window.KindleReaderContextMenu !== 'undefined') {
w = window;
} else if (window.length) {
for (var i=0;i<window.length;i++) {
if (typeof window[i].KindleReaderContextMenu !== 'undefined') {
w = window[i];
break;
}
}
}

if (typeof w === 'object') {
kObj = w.KindleReaderContextMenu;
kDoc = w.document;

if (typeof kObj.ACRExtensions === 'undefined') {
kObj.ACRExtensions = true;
var oldMethod = kObj.show;
kObj.show = function () {
var res = oldMethod.apply(kObj, arguments);
var txtDoc = null;
var r = null;

if (typeof (arguments[3]) !== 'undefined' && typeof (arguments[3]['start']) !== 'undefined') {
var sId = arguments[3]['start'];
var eId = arguments[3]['end'];

$('iframe', kDoc).each(function (j, textIframe) {
var textIFrameDoc = $(textIframe).contents().get(0);
if ($('#'+sId, textIFrameDoc).get(0) && $('#'+eId, textIFrameDoc).get(0)) {
txtDoc = textIFrameDoc;
return false;
if (typeof window.ACRExtensions === 'undefined') {
window.ACRExtensions = true;
var _xhrSendProto = window.XMLHttpRequest.prototype.send;
window.XMLHttpRequest.prototype.send = function() {
var _this = this;
try {
var args = JSON.parse(arguments[0]);
if (args.Operation == 'updateAnnotations') {
var sId = args.Input.annotations[0].start;
var eId = args.Input.annotations[0].end;
if (!window.confirm('Press OK to highlight or Cancel to copy the text.')) {
var txtDoc = null;
$('iframe', $('iframe#KindleReaderIFrame', window.document).contents()).each(function (i, textIframe) {
var textIFrameDoc = $(textIframe).contents().get(0);
if ($('#'+sId, textIFrameDoc).get(0) && $('#'+eId, textIFrameDoc).get(0)) {
txtDoc = textIFrameDoc;

return false;
}
});

if (txtDoc) {
console.log(txtDoc);
r = txtDoc.createRange();
r.setStartBefore($('#'+sId, txtDoc).get(0));
r.setEndAfter($('#'+eId, txtDoc).get(0));
var newW = window.open('', 'ACRExtensions', "height=400,width=400,location=0,menubar=0,scrollbars=1,toolbar=0");
newW.document.body.appendChild(r.cloneContents());
}

return _xhrSendProto.apply(_this, []);
}
});

if (txtDoc) {
r = txtDoc.createRange();
r.setStartBefore($('#'+sId, txtDoc).get(0));
r.setEndAfter($('#'+eId, txtDoc).get(0));
}
}

$('#ACRExtensions_copyB_sep', kDoc).remove();
$('#ACRExtensions_copyB', kDoc).remove();
var sepEl = $('<div id="ACRExtensions_copyB_sep" class="kindle_menu_separator"></div>');
var copyB = $('<div id="ACRExtensions_copyB" class="kindle_menu_button button_enabled ui-corner-left">Copy</div>');
$('#kindle_menu_border', kDoc).append(sepEl).append(copyB);
setTimeout(function(){
sepEl.show();
copyB.removeClass('button_hidden');
}, 1);
$('#ACRExtensions_copyB', kDoc).click(function (evt) {
if (r) {
var newW = window.open('', 'ACRExtensions', "height=400,width=400,location=0,menubar=0,scrollbars=1,toolbar=0");
newW.document.body.appendChild(r.cloneContents());
}
});

return res;
};

alert('ACRExtensions is now active.');
} else {
alert('ACRExtensions is already active.');
} catch (e) {};

return _xhrSendProto.apply(_this, arguments);
}
}
} else {
alert('Error: ACRExtensions is not active. Te Amazon Cloud Reader window could not be found.');
}

})();

0 comments on commit 2ffbd7b

Please sign in to comment.