Permalink
Browse files

add popup.html

  • Loading branch information...
ikemo3 committed Dec 14, 2018
1 parent 6d5f0b4 commit f6ea702c47b0d02051cea4acb55fd1da4c519f4e
@@ -1,5 +1,10 @@
# v1.5.1

## Enhancements.

* Add 'Search in English' popup.
* Add 'Search excluding "ikagadesitaka"' (Japanese only.)

## Improvements.

* Add soft/hard option for Banned Words.
@@ -78,6 +78,9 @@
"developerMode": {
"message": "Developer Mode"
},
"exceptIkagadesitaka": {
"message": "Search excluding 'ikagadesitaka(Japanese)'"
},
"exportButton": {
"message": "Export"
},
@@ -144,6 +147,9 @@
"optionTitle": {
"message": "Gossip Site Blocker: Option"
},
"searchInEnglish": {
"message": "Search in English"
},
"softBlock": {
"message": "Soft block(hide)"
},
@@ -78,6 +78,9 @@
"developerMode": {
"message": "開発者モード"
},
"exceptIkagadesitaka": {
"message": "「いかがでしたか」を除外して検索"
},
"exportButton": {
"message": "エクスポート"
},
@@ -144,6 +147,9 @@
"optionTitle": {
"message": "ゴシップサイトブロッカー: オプション"
},
"searchInEnglish": {
"message": "英語で検索"
},
"softBlock": {
"message": "ソフトブロック(非表示)"
},
@@ -11,7 +11,8 @@
"128": "icons/icon-128.png"
},
"browser_action": {
"default_icon": "icons/icon-16.png"
"default_icon": "icons/icon-16.png",
"default_popup": "popup/popup.html"
},
"content_scripts": [
{
@@ -248,7 +249,8 @@
"open_in_tab": true
},
"permissions": [
"storage"
"storage",
"tabs"
],
"web_accessible_resources": [
"icons/*"
@@ -0,0 +1,3 @@
body {
width: 15rem;
}
@@ -0,0 +1,19 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8"/>
<link rel="stylesheet" href="popup.css"/>
</head>
<body>

<div id="exceptIkagadesitakaDiv">
<button id="exceptIkagadesitakaButton" data-i18n-text="exceptIkagadesitaka">Search excluding 'ikagadesitaka(Japanese)'</button>
</div>
<div id="searchInEnglishDiv">
<button id="searchInEnglishButton" data-i18n-text="searchInEnglish">Search In English</button>
</div>

<script src="popup.js"></script>
<script src="../option/l10n.js"></script>
</body>
</html>

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
@@ -0,0 +1,47 @@
function getCurrentTab(): Promise<chrome.tabs.Tab> {
return new Promise((resolve, reject) => {
chrome.tabs.query({active: true, currentWindow: true}, ((tabs) => {
if (tabs.length === 0) {
reject();
return;
}

const currentTab = tabs[0];
resolve(currentTab);
}));
});
}

const exceptIkagadesitakaDiv = document.getElementById("exceptIkagadesitakaDiv") as HTMLDivElement;
const exceptIkagadesitakaButton = document.getElementById("exceptIkagadesitakaButton") as HTMLButtonElement;
const searchInEnglishDiv = document.getElementById("searchInEnglishDiv") as HTMLDivElement;
const searchInEnglishButton = document.getElementById("searchInEnglishButton") as HTMLButtonElement;

searchInEnglishButton.addEventListener("click", async () => {
const currentTab = await getCurrentTab();
const url = currentTab.url;

chrome.tabs.update(currentTab.id!, {url: url + "&gl=us&hl=en"});
});

exceptIkagadesitakaButton.addEventListener("click", async () => {
const currentTab = await getCurrentTab();
const url = new URL(currentTab.url!);
const q = url.searchParams.get("q");
const ikagadesuka = "\u3044\u304B\u304C\u3067\u3057\u305F\u304B";
url.searchParams.set("q", q + " -" + ikagadesuka);

chrome.tabs.update(currentTab.id!, {url: url.toString()});
});

(async () => {
const lang = chrome.i18n.getUILanguage();

if (lang === "ja") {
exceptIkagadesitakaDiv.style.display = "block";
searchInEnglishDiv.style.display = "block";
} else {
exceptIkagadesitakaDiv.style.display = "none";
searchInEnglishDiv.style.display = "block";
}
})();

0 comments on commit f6ea702

Please sign in to comment.