Skip to content

Commit

Permalink
safari version 0.3.9
Browse files Browse the repository at this point in the history
  • Loading branch information
andy-portmen committed Oct 5, 2015
1 parent 1b42336 commit 9f50cd8
Show file tree
Hide file tree
Showing 15 changed files with 109 additions and 162 deletions.
4 changes: 2 additions & 2 deletions src/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
<key>Author</key>
<string>Andy Portmen</string>
<key>Builder Version</key>
<string>10600.7.12</string>
<string>11601.1.56</string>
<key>CFBundleDisplayName</key>
<string>igTranslator for Google</string>
<key>CFBundleIdentifier</key>
<string>com.add0n.dictionary</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleShortVersionString</key>
<string>0.3.6</string>
<string>0.3.9</string>
<key>CFBundleVersion</key>
<string>2</string>
<key>Chrome</key>
Expand Down
76 changes: 44 additions & 32 deletions src/data/content_script/inject.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,45 +88,58 @@ function init() {
if (text_direction == 'ltr') e.style.textAlign = "left";
}
}

function getSelectedRect(w) {
try {
var range = w.getRangeAt(0).cloneRange();
if (range.startOffset != range.endOffset) {
var rect = range.getBoundingClientRect();
return rect;
}
else {
var arr = range.startContainer.childNodes;
for (var i = 0; i < arr.length; i++) {
var target = arr[i].nodeName.toLowerCase();
if (target == 'textarea' || target == 'input') {
var rect = getTextBoundingRect(arr[i], arr[i].selectionStart, arr[i].selectionEnd);
if (rect.top && rect.left && rect.height && rect.width) return rect;
if (w.rangeCount) {
var range = w.getRangeAt(0).cloneRange();
if (range.startOffset !== range.endOffset) {
var rect = range.getBoundingClientRect();
return rect;
}
else if (range.startOffset == 0 && range.endOffset == 0) {
return null;
}
else {
var arr = range.startContainer.childNodes;
for (var i = 0; i < arr.length; i++) {
var target = arr[i].nodeName.toLowerCase();
if (target.indexOf('text') !== -1 || target.indexOf('input') !== -1) {
var rect = getTextBoundingRect(arr[i], arr[i].selectionStart, arr[i].selectionEnd);
if (rect.top && rect.left && rect.height && rect.width) {
return rect;
}
else {
return null;
}
}
}
range.collapse(false);
var dummy = document.createElement("span");
range.insertNode(dummy);
var rect = dummy.getBoundingClientRect();
dummy.parentNode.removeChild(dummy);
return rect;
}
range.collapse(false);
var dummy = document.createElement("span");
range.insertNode(dummy);
var rect = dummy.getBoundingClientRect();
dummy.parentNode.removeChild(dummy);
return rect;
}
else {
return null;
}
}
catch (e) {
return null;
}
}

function requestBubbleTranslation(e) {
header.textContent = '';
content.textContent = '';
translateIcon.style.display = 'none';
var rect = requestBubbleTranslation.rect;
//iFrame.style.top = (rect.top + window.scrollY + rect.height) + 'px';
iFrame.style.top = (e.clientY + window.scrollY + 40) + 'px';
//iFrame.style.left = (rect.left + window.scrollX - 23 + rect.width / 2) + 'px';
iFrame.style.left = (e.clientX + window.scrollX - 40) + 'px';
if (rect && rect.top) iFrame.style.top = (rect.top + window.scrollY + rect.height) + 'px';
else iFrame.style.top = (e.clientY + window.scrollY + 40) + 'px';
if (rect && rect.left) iFrame.style.left = (rect.left + window.scrollX - 23 + rect.width / 2) + 'px';
else iFrame.style.left = (e.clientX + window.scrollX - 40) + 'px';
iFrame.style.width = (170) + "px";
iFrame.style.height = (70) + "px";
iFrame.style.display = 'block';
Expand All @@ -136,14 +149,14 @@ function init() {
allowMouseOverTranslation = false;
background.send("translation-request", requestBubbleTranslation.text);
}

var timeoutIconShow, timeoutIconHide;
function showTranslateIcon(e) {
var rect = requestBubbleTranslation.rect;
//translateIcon.style.top = (rect.top + window.scrollY - 18) + 'px';
translateIcon.style.top = (e.clientY + window.scrollY - 35) + 'px';
//translateIcon.style.left = (rect.left + window.scrollX + rect.width - 2) + 'px';
translateIcon.style.left = (e.clientX + window.scrollX + 10) + 'px';
if (rect && rect.top) translateIcon.style.top = (rect.top + window.scrollY - 18) + 'px';
else translateIcon.style.top = (e.clientY + window.scrollY - 30) + 'px';
if (rect && rect.left) translateIcon.style.left = (rect.left + window.scrollX + rect.width - 2) + 'px';
else translateIcon.style.left = (e.clientX + window.scrollX + 10) + 'px';
if (timeoutIconShow) window.clearTimeout(timeoutIconShow);
if (timeoutIconHide) window.clearTimeout(timeoutIconHide);
timeoutIconShow = window.setTimeout(function () {
Expand All @@ -153,7 +166,7 @@ function init() {
translateIcon.style.display = "none";
}, translateIconTime * 1000); /* hide TranslateIcon automatically */
}

/* iFrame */
var iFrame = html("iframe", {
src: "about:blank",
Expand Down Expand Up @@ -572,7 +585,6 @@ function init() {
}
else { /* dblclick or mouseup translations */
var selectedText = getSelectedText(target);
console.error(selectedText)
if (selectedText && selectedText.length >= minimumNumberOfCharacters) {
requestBubbleTranslation.text = selectedText;
requestBubbleTranslation.rect = getSelectedRect(window.getSelection());
Expand Down Expand Up @@ -756,4 +768,4 @@ function getTextBoundingRect(input, selectionStart, selectionEnd, debug) {
}
return '';
}
}
}
12 changes: 5 additions & 7 deletions src/data/firefox/sound.html
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="application/xhtml+xml; charset=UTF-8" />
</head>
<body>

</body>
</html>
<head>
<meta http-equiv="content-type" content="application/xhtml+xml; charset=UTF-8" />
</head>
<body></body>
</html>
4 changes: 2 additions & 2 deletions src/data/options/options.css
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ label>input {
select {
padding: 0 0 0 0;
width: 180px;
height: 25px;
height: 30px;
color: #2b2b2b !important;
font-size: 14px;
text-align: center;
Expand Down Expand Up @@ -105,7 +105,7 @@ option {
padding: 0;
margin: 0;
width: 150px;
height: 25px;
height: 30px;
font-size: 14px;
cursor: pointer;
text-align: center;
Expand Down
4 changes: 2 additions & 2 deletions src/data/options/options.html
Original file line number Diff line number Diff line change
Expand Up @@ -343,8 +343,8 @@
<p class="note">To choose an RGB color you can use <a target="_blank" href="http://www.rapidtables.com/web/color/RGB_Color.htm#color%20picker">Color Picker</a> website. First, select a desired color and then enter the values of R, G and B in the above field.</p>
<p class="spacer"></p>
<!-- -->
<label><span>Do not inject translation bubble in the: </span><input style="width: 100%" data-pref="settings.exclude" type="text"></input><span></span></label>
<p class="note">Translation bubble is injected in all pages except the list above. You need to disable and re-enable the extension for the change to take effect (Firefox only).</p>
<label><span>Do NOT show translation bubble in: </span><input style="width: 70%; height: 30px;" data-pref="settings.exclude" type="text"></input><span></span></label>
<p class="note">Translation bubble is shown in all pages except the list above. Note: You need to disable and re-enable the addon for the changes to take effect (This Option is ONLY for Firefox).</p>
<p class="spacer"></p>
</td>
</tr>
Expand Down
Binary file modified src/dictionary.safariextz
Binary file not shown.
Binary file modified src/igtranslator.xpi
Binary file not shown.
2 changes: 2 additions & 0 deletions src/lib/chrome/chrome.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ var app = {

timer: window,

loadReason: "install",

storage: (function () {
var objs = {};
chrome.storage.local.get(null, function (o) {
Expand Down
24 changes: 16 additions & 8 deletions src/lib/common.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**** wrapper (start) ****/
if (typeof require !== 'undefined') {
app = require('./firefox/firefox');
config = require('./config');
var app = require('./firefox/firefox');
var config = require('./config');
}
/**** wrapper (end) ****/

Expand All @@ -12,7 +12,7 @@ const languagesNoVoice = [
"ig","ga","jw","kn","km","lo","lt",
"ms","mt","mi","mr","mn","ne","fa",
"pa","sl","so","te","uk","ur","yi",
"yo","zu"
"yo","zu", "si", "st"
];

function m (i) {
Expand All @@ -32,8 +32,10 @@ function m (i) {
var version = config.welcome.version;
if (app.version() !== version) {
app.timer.setTimeout(function () {
app.tab.open(m(0) + app.version() + (version ? "&p=" + version + "&type=upgrade" : "&type=install"));
config.welcome.version = app.version();
if (app.loadReason === "install" || app.loadReason === "startup") {

This comment has been minimized.

Copy link
@bazilio-ua

bazilio-ua Oct 6, 2015

please, delete 'app.loadReason === "startup"' from condition, it's annoying, open new tab on each browser start

This comment has been minimized.

Copy link
@andy-portmen

andy-portmen Oct 7, 2015

Author Owner

There is a condition on line 33, the FAQ page is opened only after upgrade which is once per like two months!

This comment has been minimized.

Copy link
@bazilio-ua

bazilio-ua Oct 7, 2015

I think for some reason condition on line 33 is always true (on Safari), perhaps because plugin is not be installed from apple's 'extensions.apple.com' due error 'This developer's server appears to be busy. Please try again later.'
And on each browser start or enable/disable extension from Safari setting -- opened new tab and generating URL
on Safari 5.1.10 - http://add0n.com/google-translator.html?version=undefined&p=undefined&type=upgrade
on Safari 6.2.8 - http://add0n.com/google-translator.html?version=0.3.9&p=0.3.6&type=upgrade

This comment has been minimized.

Copy link
@andy-portmen

andy-portmen Oct 22, 2015

Author Owner

in the latest release (0.4.0), the update URL is changed. Can you confirm the problem is resolved?

This comment has been minimized.

Copy link
@bazilio-ua

bazilio-ua Oct 22, 2015

version (0.4.0)
on Safari 6.2.8 (Mountain Lion) is OK
on Safari 5.1.10 (Snow Leopard) -- looks like to unable resolve "version" from "config.welcome.version"
which always is 'undefined' and as result is execution code after line 33 each time browser start

This comment has been minimized.

Copy link
@bazilio-ua

bazilio-ua Oct 22, 2015

Now just looked at the code in release (0.3.0) which is working fine with Safari 5.1.10:
there is a completely different mechanism to determine 'version' via 'storage'.

Maybe just make quick fix "cannot access Google translate server" for release (0.3.0) for legacy Safari?

app.tab.open(m(0) + app.version() + (version ? "&p=" + version + "&type=upgrade" : "&type=install"));
config.welcome.version = app.version();
}
}, config.welcome.timeout);
}

Expand Down Expand Up @@ -234,12 +236,16 @@ function getTranslation(word) {
word = word.toLowerCase();
word = encodeURIComponent(word);

var gRand = function () {
return Math.floor(Math.random() * 1000000) + '|' + Math.floor(Math.random() * 1000000)
};

/* urls for old engine */
var url_old_1 = m(1) + config.translator.from + '&tl=' + config.translator.to + '&hl=en&sc=2&ie=UTF-8&oe=UTF-8&uptl=' + config.translator.to + '&alttl=en&oc=3&otf=2&ssel=0&tsel=0&q=' + word;
var url_old_2 = m(1) + config.translator.from + '&tl=' + config.translator.alt + '&hl=en&sc=2&ie=UTF-8&oe=UTF-8&uptl=' + config.translator.alt + '&alttl=en&oc=3&otf=2&ssel=0&tsel=0&q=' + word;
/* urls for new engine */
var url_new_1 = m(6) + config.translator.from + '&tl=' + config.translator.to + '&hl=en&dt=bd&dt=ex&dt=ld&dt=md&dt=qc&dt=rw&dt=rm&dt=ss&dt=t&dt=at&dt=sw&ie=UTF-8&oe=UTF-8&ssel=0&tsel=0&q=' + word;
var url_new_2 = m(6) + config.translator.from + '&tl=' + config.translator.alt + '&hl=en&dt=bd&dt=ex&dt=ld&dt=md&dt=qc&dt=rw&dt=rm&dt=ss&dt=t&dt=at&dt=sw&ie=UTF-8&oe=UTF-8&ssel=0&tsel=0&q=' + word;
var url_new_1 = m(6) + config.translator.from + '&tl=' + config.translator.to + '&hl=en&dt=bd&dt=ex&dt=ld&dt=md&dt=qc&dt=rw&dt=rm&dt=ss&dt=t&dt=at&dt=sw&ie=UTF-8&oe=UTF-8&ssel=0&tsel=0&tk=' + gRand() + '&q=' + word;
var url_new_2 = m(6) + config.translator.from + '&tl=' + config.translator.alt + '&hl=en&dt=bd&dt=ex&dt=ld&dt=md&dt=qc&dt=rw&dt=rm&dt=ss&dt=t&dt=at&dt=sw&ie=UTF-8&oe=UTF-8&ssel=0&tsel=0&tk=' + gRand() + '&q=' + word;

var d = app.Promise.defer();
/* using cache */
Expand Down Expand Up @@ -535,7 +541,6 @@ app.content_script.receive("remove-from-phrasebook", function (data) {

app.content_script.receive("play-voice", playVoice);

/* options page */
app.options.receive("changed", function (o) {
config.set(o.pref, o.value);
app.options.send("set", {
Expand All @@ -552,10 +557,13 @@ app.options.receive("get", function (pref) {
value: config.get(pref)
});
});

app.options.receive("get-history-update", function () {
app.options.send("history-update", config.history.data);
});

app.options.receive("set-history-update", function (data) {
config.history.data = data;
});

app.options.receive("clearOptionsHistory", clearHistory);
Loading

0 comments on commit 9f50cd8

Please sign in to comment.