Add files via upload
This commit is contained in:
parent
a8f798ff46
commit
7b49200253
BIN
simple-translate/icons/border-48.png
Normal file
BIN
simple-translate/icons/border-48.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 225 B |
20
simple-translate/manifest.json
Normal file
20
simple-translate/manifest.json
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
{
|
||||||
|
|
||||||
|
"manifest_version": 2,
|
||||||
|
"name": "Simple Translate",
|
||||||
|
"version": "1.0",
|
||||||
|
|
||||||
|
"description": "Adds a red border to all webpages matching mozilla.org.",
|
||||||
|
|
||||||
|
"icons": {
|
||||||
|
"48": "icons/border-48.png"
|
||||||
|
},
|
||||||
|
|
||||||
|
"content_scripts": [
|
||||||
|
{
|
||||||
|
"matches": ["<all_urls>"],
|
||||||
|
"js": ["simple-translate.js"]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
||||||
|
}
|
6
simple-translate/popup/popup.css
Normal file
6
simple-translate/popup/popup.css
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
#button {
|
||||||
|
width: 20px;
|
||||||
|
height: 20px;
|
||||||
|
background-color: steelblue;
|
||||||
|
|
||||||
|
}
|
14
simple-translate/popup/popup.html
Normal file
14
simple-translate/popup/popup.html
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
|
||||||
|
<html>
|
||||||
|
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<link rel="stylesheet" href="popup.css">
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<div id=button></div>
|
||||||
|
</body>
|
||||||
|
|
||||||
|
</html>
|
41
simple-translate/simple-translate.js
Normal file
41
simple-translate/simple-translate.js
Normal file
|
@ -0,0 +1,41 @@
|
||||||
|
var style = document.createElement("style");
|
||||||
|
style.setAttribute("type", "text/css");
|
||||||
|
style.innerHTML = "" +
|
||||||
|
"#simple-translate-button {" +
|
||||||
|
"background-color :rgba(87, 199, 232, 0.6);" +
|
||||||
|
"height :20px;" +
|
||||||
|
"width :20px;" +
|
||||||
|
"position :fixed;" +
|
||||||
|
"z-index: 150;" +
|
||||||
|
"left :0px;" +
|
||||||
|
"top :0px;" +
|
||||||
|
"display :none;" +
|
||||||
|
"cursor :pointer;" +
|
||||||
|
"}";
|
||||||
|
document.getElementsByTagName("head")[0].appendChild(style); //headに上記スタイルを追記
|
||||||
|
document.body.insertAdjacentHTML("beforeend", "<div id='simple-translate-button'></div>"); //body末尾にボタン配置
|
||||||
|
|
||||||
|
var button = document.getElementById("simple-translate-button");
|
||||||
|
var selectionWord;
|
||||||
|
|
||||||
|
function showPanel() {
|
||||||
|
console.log(selectionWord);
|
||||||
|
}
|
||||||
|
|
||||||
|
function popupButton(e) {
|
||||||
|
button.style.display = 'block';
|
||||||
|
button.style.left = e.clientX + 20 + 'px';
|
||||||
|
button.style.top = e.clientY + 0 + 'px';
|
||||||
|
}
|
||||||
|
|
||||||
|
function Select(e) {
|
||||||
|
button.style.display = 'none'; //マウスクリックでボタンを非表示に
|
||||||
|
setTimeout(function () { //誤動作防止の為ディレイを設ける
|
||||||
|
selectionWord = String(window.getSelection());
|
||||||
|
if (selectionWord.length !== 0 && e.button == 0) { //選択範囲が存在かつ左クリックのとき
|
||||||
|
popupButton(e);
|
||||||
|
}
|
||||||
|
}, 100);
|
||||||
|
}
|
||||||
|
window.addEventListener("mouseup", Select, false);
|
||||||
|
button.addEventListener("click", showPanel, false);
|
Loading…
Reference in a new issue