Last active
September 21, 2020 14:45
-
-
Save cia-rana/f6dd55631940b3444ad721c737764bd6 to your computer and use it in GitHub Desktop.
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
// Ref. https://sekailab.com/wp/2020/03/25/deepl-translation-with-kindle-cloud-reader/ | |
function () { | |
/* Kindle Translator V 0.4*/ | |
/* based on ACRExtensions via https://github.com/binarycrafts/ACRExtensions */ | |
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)) { | |
txtDoc = textIFrameDoc; | |
return false; | |
} | |
}); | |
if (txtDoc) { | |
r = txtDoc.createRange(); | |
r.setStartBefore($('#'+sId, txtDoc).get(0)); | |
r.setEndAfter($('#'+eId, txtDoc).get(0)); | |
} | |
} | |
$('#ACRExtensions_copyC', kDoc).remove(); | |
var styles = $('<style>.spinner, .dictionary.i18n.expanded {display:none !important;} div#kindleReader_menu_contextMenu { max-height: 35px;}</style>'); | |
var sepEl = $('<div id="ACRExtensions_copyC_sep" class="kindle_menu_separator"></div>'); | |
var copyC = $('<div id="ACRExtensions_copyC" class="kindle_menu_button button_enabled ui-corner-left">DeepL</div>'); | |
$('#kindle_menu_border', kDoc).append(sepEl).append(copyC).append(styles); | |
setTimeout(function(){ | |
sepEl.show(); | |
copyC.removeClass('button_hidden'); | |
}, 1); | |
$('#ACRExtensions_copyC', kDoc).click(function (evt) { | |
if (r) { | |
var newW = window.open('https://www.deepl.com/translator#en/ja/' + encodeURIComponent(r), 'DeepL' , "height=600,width=776,location=0,menubar=0,scrollbars=1,toolbar=0"); | |
} | |
}); | |
return res; | |
}; | |
alert('Kindle Translator Extension is now active.'); | |
} else { | |
alert('Kindle Translator Extension is already active.'); | |
} | |
} else { | |
alert('Error: Kindle Translator Extension is not active. The Amazon Cloud Reader window could not be found.'); | |
} | |
})(); |
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
var w=null,kDoc=null,kObj=null;if(void 0!==window.KindleReaderContextMenu)w=window;else if(window.length)for(var i=0;i<window.length;i++)if(void 0!==window[i].KindleReaderContextMenu){w=window[i];break}if("object"==typeof w)if(kObj=w.KindleReaderContextMenu,kDoc=w.document,void 0===kObj.ACRExtensions){kObj.ACRExtensions=!0;var oldMethod=kObj.show;kObj.show=function(){var e=oldMethod.apply(kObj,arguments),n=null,o=null;if(void 0!==arguments[3]&&void 0!==arguments[3].start){var t=arguments[3].start,i=arguments[3].end;$("iframe",kDoc).each(function(e,o){var i=$(o).contents().get(0);if($("#"+t,i).get(0))return n=i,!1}),n&&((o=n.createRange()).setStartBefore($("#"+t,n).get(0)),o.setEndAfter($("#"+i,n).get(0)))}$("#ACRExtensions_copyC",kDoc).remove();var d=$("<style>.spinner, .dictionary.i18n.expanded {display:none !important;} div#kindleReader_menu_contextMenu { max-height: 35px;}</style>"),a=$('<div id="ACRExtensions_copyC_sep" class="kindle_menu_separator"></div>'),r=$('<div id="ACRExtensions_copyC" class="kindle_menu_button button_enabled ui-corner-left">DeepL</div>');return $("#kindle_menu_border",kDoc).append(a).append(r).append(d),setTimeout(function(){a.show(),r.removeClass("button_hidden")},1),$("#ACRExtensions_copyC",kDoc).click(function(e){if(o)window.open("https://www.deepl.com/translator#en/ja/"+encodeURIComponent(o),"DeepL","height=600,width=776,location=0,menubar=0,scrollbars=1,toolbar=0")}),e},alert("Kindle Translator Extension is now active.")}else alert("Kindle Translator Extension is already active.");else alert("Error: Kindle Translator Extension is not active. The Amazon Cloud Reader window could not be found."); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment