Add files via upload

This commit is contained in:
sienori 2017-06-19 01:40:30 +09:00 committed by GitHub
parent a8f798ff46
commit 7b49200253
5 changed files with 81 additions and 0 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 225 B

View 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"]
}
]
}

View file

@ -0,0 +1,6 @@
#button {
width: 20px;
height: 20px;
background-color: steelblue;
}

View 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>

View 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);