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":{
"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":{
"message": "Translate this page"
},

View file

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

View file

@ -3,7 +3,7 @@ browser.storage.onChanged.addListener(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(); //初回起動時
targetLang = value.targetLang;
ifShowButton = value.ifShowButton;
@ -27,7 +27,7 @@ function initialSetting() {
targetLang = "en";
break;
}
browser.storage.sync.set({
browser.storage.local.set({
'targetLang': targetLang,
'ifShowButton': true,
'ifCheckLang': true,

View file

@ -1,13 +1,11 @@
{
"manifest_version": 2,
"version": "1.1.3",
"version": "1.2.1",
"name": "__MSG_extName__",
"description": "__MSG_extDescription__",
"default_locale": "en",
"applications": {
"gecko": {
"id": "simple-translate@sienori"

View file

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

View file

@ -3,25 +3,39 @@
<head>
<meta charset="UTF-8">
<link rel="stylesheet" type="text/css" href="options.css">
</head>
<body>
<p>
<label id=targetLangLabel>翻訳先の言語:</label>
<select id="targetLang"></select>
<label><span id=targetLangLabel>翻訳先の言語:</span>
<select id="targetLang"></select></label>
</p>
<p>
<input type="checkbox" name="ifShowButton" value="1">
<label id=ifShowButtonLabel>テキスト選択時にボタンを表示する</label>
<label><input type="checkbox" name="ifShowButton" value="1">
<span id=ifShowButtonLabel>テキスト選択時にボタンを表示する</span></label>
</p>
<p>
<input type="checkbox" name="ifCheckLang" value="1">
<label id=ifCheckLangLabel>選択したテキストが翻訳先言語と同じ時はボタンを表示しない</label>
<label><input type="checkbox" name="ifCheckLang" value="1">
<span id=ifCheckLangLabel>選択したテキストが翻訳先言語と同じ時はボタンを表示しない</span></label>
</p>
<p>
<input type="checkbox" name="ifShowMenu" value="1">
<label id=ifShowMenuLabel>コンテキストメニューを表示する</label>
<label><input type="checkbox" name="ifShowMenu" value="1">
<span id=ifShowMenuLabel>コンテキストメニューを表示する</span></label>
</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>
</body>

View file

@ -2,27 +2,37 @@ var targetLang = document.getElementById("targetLang");
var ifShowButton = document.getElementsByName("ifShowButton").item(0);
var ifCheckLang = document.getElementsByName("ifCheckLang").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");
secondTargetLang.innerHTML=browser.i18n.getMessage("langList");
document.getElementById("targetLangLabel").innerHTML=browser.i18n.getMessage("langListLabel");
document.getElementById("ifShowButtonLabel").innerHTML=browser.i18n.getMessage("ifShowButtonLabel");
document.getElementById("ifCheckLangLabel").innerHTML=browser.i18n.getMessage("ifCheckLangLabel");
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;
ifShowButton.checked=value.ifShowButton;
ifCheckLang.checked=value.ifCheckLang;
ifShowMenu.checked=value.ifShowMenu;
ifChangeSecondLang.checked=value.ifChangeSecondLang;
secondTargetLang.value=value.secondTargetLang;
});
function save() {
browser.storage.sync.set({
browser.storage.local.set({
'targetLang': targetLang.value,
'ifShowButton': ifShowButton.checked,
'ifCheckLang': ifCheckLang.checked,
'ifShowMenu': ifShowMenu.checked
'ifShowMenu': ifShowMenu.checked,
'ifChangeSecondLang': ifChangeSecondLang.checked,
'secondTargetLang': secondTargetLang.value
}, function () {});
}
@ -30,3 +40,5 @@ targetLang.addEventListener("change", save);
ifShowButton.addEventListener("change", save);
ifCheckLang.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;
let targetLang;
let secondTargetLang;
let defaultTargetLang;
let ifChangeSecondLang;
let sourceWord = "";
browser.storage.onChanged.addListener(getTargetLang);
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;
secondTargetLang = value.secondTargetLang;
ifChangeSecondLang=value.ifChangeSecondLang;
langList.value = targetLang; //リスト初期値をセット
langList.addEventListener("change", changeLang);
});
@ -129,11 +135,33 @@ function getRequest(word) {
function showResult(results) {
target.innerText = "";
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 i = 0; i < results[j].response[0].length; i++) {
resultText += results[j].response[0][i][0];
}
resultText += "\n"; //
resultText += "\n";
}
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);
//設定を読み出し
function getSetting() {
browser.storage.sync.get(["targetLang", "ifShowButton", "ifCheckLang"], function (value) {
browser.storage.local.get(["targetLang", "ifShowButton", "ifCheckLang"], function (value) {
targetLang = value.targetLang;
ifShowButton = value.ifShowButton;
ifCheckLang = value.ifCheckLang;