This commit is contained in:
sienori 2017-10-15 00:40:46 +09:00 committed by GitHub
parent cf55776396
commit e9516278ef
11 changed files with 92 additions and 22 deletions

View file

@ -26,6 +26,12 @@
"ifShowMenuLabel":{ "ifShowMenuLabel":{
"message": "Display context menu" "message": "Display context menu"
}, },
"ifChangeSecondLangLabel":{
"message": "Switch to the second language if the input text of the tool bar translation panel is the same as the target language"
},
"secondTargetLangLabel":{
"message": "Second language"
},
"translatePageMenu":{ "translatePageMenu":{
"message": "Translate this page" "message": "Translate this page"
}, },

View file

@ -26,6 +26,12 @@
"ifShowMenuLabel":{ "ifShowMenuLabel":{
"message": "コンテキストメニューを表示する" "message": "コンテキストメニューを表示する"
}, },
"ifChangeSecondLangLabel":{
"message": "ツールバー翻訳パネルの入力テキストが翻訳先言語と同じ場合は第二言語に切り替える"
},
"secondTargetLangLabel":{
"message": "第二言語"
},
"translatePageMenu":{ "translatePageMenu":{
"message": "ページ全体を翻訳" "message": "ページ全体を翻訳"
}, },

View file

@ -3,7 +3,7 @@ browser.storage.onChanged.addListener(getSetting)
//設定の読み出し //設定の読み出し
function getSetting() { function getSetting() {
browser.storage.sync.get(["targetLang", "ifShowButton", "ifCheckLang", "ifShowMenu"], function (value) { browser.storage.local.get(["targetLang", "ifShowButton", "ifCheckLang", "ifShowMenu"], function (value) {
if (value.targetLang == undefined) initialSetting(); //初回起動時 if (value.targetLang == undefined) initialSetting(); //初回起動時
targetLang = value.targetLang; targetLang = value.targetLang;
ifShowButton = value.ifShowButton; ifShowButton = value.ifShowButton;
@ -27,7 +27,7 @@ function initialSetting() {
targetLang = "en"; targetLang = "en";
break; break;
} }
browser.storage.sync.set({ browser.storage.local.set({
'targetLang': targetLang, 'targetLang': targetLang,
'ifShowButton': true, 'ifShowButton': true,
'ifCheckLang': true, 'ifCheckLang': true,

View file

@ -1,12 +1,10 @@
{ {
"manifest_version": 2, "manifest_version": 2,
"version": "1.1.3", "version": "1.2.1",
"name": "__MSG_extName__", "name": "__MSG_extName__",
"description": "__MSG_extDescription__", "description": "__MSG_extDescription__",
"default_locale": "en", "default_locale": "en",
"applications": { "applications": {
"gecko": { "gecko": {

View file

@ -0,0 +1,6 @@
hr{
width: 100%;
background-color: #d7d7db;
height: 1px;
border: none;
}

View file

@ -3,25 +3,39 @@
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<link rel="stylesheet" type="text/css" href="options.css">
</head> </head>
<body> <body>
<p> <p>
<label id=targetLangLabel>翻訳先の言語:</label> <label><span id=targetLangLabel>翻訳先の言語:</span>
<select id="targetLang"></select> <select id="targetLang"></select></label>
</p> </p>
<p> <p>
<input type="checkbox" name="ifShowButton" value="1"> <label><input type="checkbox" name="ifShowButton" value="1">
<label id=ifShowButtonLabel>テキスト選択時にボタンを表示する</label> <span id=ifShowButtonLabel>テキスト選択時にボタンを表示する</span></label>
</p> </p>
<p> <p>
<input type="checkbox" name="ifCheckLang" value="1"> <label><input type="checkbox" name="ifCheckLang" value="1">
<label id=ifCheckLangLabel>選択したテキストが翻訳先言語と同じ時はボタンを表示しない</label> <span id=ifCheckLangLabel>選択したテキストが翻訳先言語と同じ時はボタンを表示しない</span></label>
</p> </p>
<p> <p>
<input type="checkbox" name="ifShowMenu" value="1"> <label><input type="checkbox" name="ifShowMenu" value="1">
<label id=ifShowMenuLabel>コンテキストメニューを表示する</label> <span id=ifShowMenuLabel>コンテキストメニューを表示する</span></label>
</p> </p>
<hr>
<p>
<label><input type="checkbox" name="ifChangeSecondLang" value="1">
<span id=ifChangeSecondLangLabel>ツールバー翻訳パネルの入力テキストが翻訳先言語と同じ場合は第2言語に切り替える</span></label>
</p>
<p>
<label><span id=secondTargetLangLabel>第2言語:</span>
<select id="secondTargetLang"></select></label>
</p>
<script type="text/javascript" src="options.js"></script> <script type="text/javascript" src="options.js"></script>
</body> </body>

View file

@ -2,31 +2,43 @@ var targetLang = document.getElementById("targetLang");
var ifShowButton = document.getElementsByName("ifShowButton").item(0); var ifShowButton = document.getElementsByName("ifShowButton").item(0);
var ifCheckLang = document.getElementsByName("ifCheckLang").item(0); var ifCheckLang = document.getElementsByName("ifCheckLang").item(0);
var ifShowMenu = document.getElementsByName("ifShowMenu").item(0); var ifShowMenu = document.getElementsByName("ifShowMenu").item(0);
var ifChangeSecondLang = document.getElementsByName("ifChangeSecondLang").item(0);
var secondTargetLang = document.getElementById("secondTargetLang");
targetLang.innerHTML=browser.i18n.getMessage("langList"); targetLang.innerHTML=browser.i18n.getMessage("langList");
secondTargetLang.innerHTML=browser.i18n.getMessage("langList");
document.getElementById("targetLangLabel").innerHTML=browser.i18n.getMessage("langListLabel"); document.getElementById("targetLangLabel").innerHTML=browser.i18n.getMessage("langListLabel");
document.getElementById("ifShowButtonLabel").innerHTML=browser.i18n.getMessage("ifShowButtonLabel"); document.getElementById("ifShowButtonLabel").innerHTML=browser.i18n.getMessage("ifShowButtonLabel");
document.getElementById("ifCheckLangLabel").innerHTML=browser.i18n.getMessage("ifCheckLangLabel"); document.getElementById("ifCheckLangLabel").innerHTML=browser.i18n.getMessage("ifCheckLangLabel");
document.getElementById("ifShowMenuLabel").innerHTML=browser.i18n.getMessage("ifShowMenuLabel"); document.getElementById("ifShowMenuLabel").innerHTML=browser.i18n.getMessage("ifShowMenuLabel");
document.getElementById("ifChangeSecondLangLabel").innerHTML=browser.i18n.getMessage("ifChangeSecondLangLabel");
document.getElementById("secondTargetLangLabel").innerHTML=browser.i18n.getMessage("secondTargetLangLabel");
//設定を読み込んで反映 //設定を読み込んで反映
browser.storage.sync.get(["targetLang", "ifShowButton", "ifCheckLang", "ifShowMenu"], function (value) { browser.storage.local.get(["targetLang", "ifShowButton", "ifCheckLang", "ifShowMenu", "ifChangeSecondLang", "secondTargetLang"], function (value) {
targetLang.value = value.targetLang; targetLang.value = value.targetLang;
ifShowButton.checked=value.ifShowButton; ifShowButton.checked=value.ifShowButton;
ifCheckLang.checked=value.ifCheckLang; ifCheckLang.checked=value.ifCheckLang;
ifShowMenu.checked=value.ifShowMenu; ifShowMenu.checked=value.ifShowMenu;
ifChangeSecondLang.checked=value.ifChangeSecondLang;
secondTargetLang.value=value.secondTargetLang;
}); });
function save() { function save() {
browser.storage.sync.set({ browser.storage.local.set({
'targetLang': targetLang.value, 'targetLang': targetLang.value,
'ifShowButton': ifShowButton.checked, 'ifShowButton': ifShowButton.checked,
'ifCheckLang': ifCheckLang.checked, 'ifCheckLang': ifCheckLang.checked,
'ifShowMenu': ifShowMenu.checked 'ifShowMenu': ifShowMenu.checked,
'ifChangeSecondLang': ifChangeSecondLang.checked,
'secondTargetLang': secondTargetLang.value
}, function () {}); }, function () {});
} }
targetLang.addEventListener("change", save); targetLang.addEventListener("change", save);
ifShowButton.addEventListener("change", save); ifShowButton.addEventListener("change", save);
ifCheckLang.addEventListener("change", save); ifCheckLang.addEventListener("change", save);
ifShowMenu.addEventListener("change", save); ifShowMenu.addEventListener("change", save);
ifChangeSecondLang.addEventListener("change", save);
secondTargetLang.addEventListener("change", save);

View file

@ -7,14 +7,20 @@ langList.innerHTML = browser.i18n.getMessage("langList");
textarea.innerText = initialText; textarea.innerText = initialText;
let targetLang; let targetLang;
let secondTargetLang;
let defaultTargetLang;
let ifChangeSecondLang;
let sourceWord = ""; let sourceWord = "";
browser.storage.onChanged.addListener(getTargetLang); browser.storage.onChanged.addListener(getTargetLang);
getTargetLang(); //翻訳先言語初期化 getTargetLang(); //翻訳先言語初期化
//設定を読み出し //設定を読み出し
function getTargetLang() { function getTargetLang() {
browser.storage.sync.get("targetLang", function (value) { browser.storage.local.get(["targetLang", "secondTargetLang","ifChangeSecondLang"], function (value) {
defaultTargetLang = value.targetLang;
targetLang = value.targetLang; targetLang = value.targetLang;
secondTargetLang = value.secondTargetLang;
ifChangeSecondLang=value.ifChangeSecondLang;
langList.value = targetLang; //リスト初期値をセット langList.value = targetLang; //リスト初期値をセット
langList.addEventListener("change", changeLang); langList.addEventListener("change", changeLang);
}); });
@ -88,8 +94,8 @@ function textAreaClick() {
} }
} }
textarea.addEventListener("keyup", function(event){ textarea.addEventListener("keyup", function (event) {
if(event.keyCode==13) resize(); if (event.keyCode == 13) resize();
inputText(); inputText();
}); });
//文字入力時の処理 //文字入力時の処理
@ -129,11 +135,33 @@ function getRequest(word) {
function showResult(results) { function showResult(results) {
target.innerText = ""; target.innerText = "";
let resultText = ""; let resultText = "";
//第二言語に変更
if (ifChangeSecondLang) {
let lang = results[0].response[2];
let percentage = results[0].response[6];
if (targetLang == defaultTargetLang && lang == defaultTargetLang && percentage > 0 && !changeLangFlag) changeSecondLang();
else if ((lang != defaultTargetLang || percentage == 0) && changeLangFlag) unchangeSecondLang();
}
for (let j = 0; j < results.length; j++) { for (let j = 0; j < results.length; j++) {
for (let i = 0; i < results[j].response[0].length; i++) { for (let i = 0; i < results[j].response[0].length; i++) {
resultText += results[j].response[0][i][0]; resultText += results[j].response[0][i][0];
} }
resultText += "\n"; // resultText += "\n";
} }
target.innerText = resultText; target.innerText = resultText;
} }
let changeLangFlag = false;
function changeSecondLang() {
changeLangFlag = true;
langList.value = secondTargetLang;
changeLang();
}
function unchangeSecondLang() {
changeLangFlag = false;
langList.value = defaultTargetLang;
changeLang();
}

View file

@ -14,7 +14,7 @@ getSetting();
browser.storage.onChanged.addListener(getSetting); browser.storage.onChanged.addListener(getSetting);
//設定を読み出し //設定を読み出し
function getSetting() { function getSetting() {
browser.storage.sync.get(["targetLang", "ifShowButton", "ifCheckLang"], function (value) { browser.storage.local.get(["targetLang", "ifShowButton", "ifCheckLang"], function (value) {
targetLang = value.targetLang; targetLang = value.targetLang;
ifShowButton = value.ifShowButton; ifShowButton = value.ifShowButton;
ifCheckLang = value.ifCheckLang; ifCheckLang = value.ifCheckLang;