Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix ACRExtensions doesn't work on the latest read.amazon.com #14
- Loading branch information
Showing
2 changed files
with
41 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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.'); | ||
} | ||
|
||
})(); | ||
|