Skip to content

Commit

Permalink
Merge branch 'release/1.0.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
yusukesaitoh committed May 23, 2020
2 parents 1bb3fde + bc4f94e commit 2dabfb3
Show file tree
Hide file tree
Showing 17 changed files with 262 additions and 131 deletions.
9 changes: 9 additions & 0 deletions app/_locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,15 @@
"titleShowCalmText": {
"message": "Show \"Calm\" next to the logo"
},
"titleIsFollowerNumberHidden": {
"message": "Hide number of followers"
},
"titleIsReactionNumberAlwaysHidden": {
"message": "Hide numbers of replies, retweets, and likes when mouse cursor is hovered"
},
"titleAdditionalSettings": {
"message": "Additional settings"
},
"textCalm": {
"message": "Calm"
}
Expand Down
11 changes: 10 additions & 1 deletion app/_locales/ja/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,20 @@
"message": "おすすめトレンド、ユーザーを隠す"
},
"titleIsReactionNumberHidden": {
"message": "ツイートへのリプライ、リツイート、いいね数を隠す"
"message": "ツイートへのリプライ数、リツイート数、いいね数を隠す"
},
"titleShowCalmText": {
"message": "ロゴの隣に「おだやか」を表示する"
},
"titleIsFollowerNumberHidden": {
"message": "フォロワー数を隠す"
},
"titleIsReactionNumberAlwaysHidden": {
"message": "カーソルをツイートにのせてもリプライ数、リツイート数、いいね数を隠す"
},
"titleAdditionalSettings": {
"message": "追加設定"
},
"textCalm": {
"message": "おだやか"
}
Expand Down
5 changes: 2 additions & 3 deletions app/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "__MSG_appName__",
"short_name": "__MSG_appShortName__",
"description": "__MSG_appDescription__",
"version": "1.0.1",
"version": "1.0.2",
"manifest_version": 2,
"default_locale": "en",
"icons": {
Expand Down Expand Up @@ -30,7 +30,6 @@
"run_at": "document_end"
}],
"permissions": [
"tabs",
"storage"
]
}
}
11 changes: 10 additions & 1 deletion app/pages/popup.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,15 @@ <h1>__MSG_appName__</h1>
<input type="checkbox" id="showCalmText" checked>
<span>__MSG_titleShowCalmText__</span>
</label>
<script src="../scripts/popup.js"></script>
<h2>__MSG_titleAdditionalSettings__</h2>
<label class="check">
<input type="checkbox" id="isFollowerNumberHidden">
<span>__MSG_titleIsFollowerNumberHidden__</span>
</label>
<label class="check">
<input type="checkbox" id="isReactionNumberAlwaysHidden">
<span>__MSG_titleIsReactionNumberAlwaysHidden__</span>
</label>
<script src="../scripts/popup.js"></script>
</body>
</html>
12 changes: 4 additions & 8 deletions app/scripts/background.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
chrome.runtime.onInstalled.addListener((details) => {
console.log('previousVersion', details.previousVersion);
chrome.runtime.onMessage.addListener((request, sender) => {
if ((request.from === 'content') && (request.subject === 'showPageAction')) {
chrome.pageAction.show(sender.tab!.id!);
}
});

chrome.tabs.onUpdated.addListener((tabId, changeInfo, tab) => {
if (tab.url!.includes('https://twitter.com/')) {
chrome.pageAction.show(tabId);
}
});
58 changes: 39 additions & 19 deletions app/scripts/contentscript.ts
Original file line number Diff line number Diff line change
@@ -1,33 +1,53 @@
toggleClass(["isExploreHidden", "isTrendsHidden", "isReactionNumberHidden", "showCalmText"]);
toggleClass(["isExploreHidden", "isTrendsHidden", "isReactionNumberHidden", "showCalmText", "isReactionNumberAlwaysHidden", "isFollowerNumberHidden",]);
addCalmTitle();
setTimeout(changeCalmColor, 50);

function toggleClass(keys: string[]) {
chrome.storage.local.get(keys, function(data) {
keys.forEach(key => {
if (typeof data[key] === "undefined") {
data[key] = true;
}
let body = document.getElementsByTagName('body')[0];

if (data[key]) {
body.classList.add(key);
} else {
body.classList.remove(key);
}
});
chrome.storage.local.get(keys, function (data) {
keys.forEach(key => {
if (key === "isFollowerNumberHidden" || key === "isReactionNumberAlwaysHidden") {
if (typeof data[key] === "undefined") {
data[key] = false;
}
} else {
if (typeof data[key] === "undefined") {
data[key] = true;
}
}
let body = document.getElementsByTagName('body')[0];
if (data[key]) {
body.classList.add(key);
} else {
body.classList.remove(key);
}
});
});
}

chrome.runtime.onMessage.addListener(function(request, sender, sendResponse){
toggleClass([request.key]);
chrome.runtime.onMessage.addListener(function (request, sender, sendResponse) {
toggleClass([request.key]);
});

chrome.runtime.sendMessage({ from: 'content', subject: 'showPageAction' });

function addCalmTitle() {
let calmText = chrome.i18n.getMessage("textCalm");
let css = "body.showCalmText header[role=\"banner\"] h1[role=\"heading\"]::after { content:\"" + calmText + "\"; }";
let calmText = chrome.i18n.getMessage("textCalm");
let css = "body.showCalmText header[role=\"banner\"] h1[role=\"heading\"]::after { content:\"" + calmText + "\";}";
let head = document.head || document.getElementsByTagName('head')[0];
let style = document.createElement('style');
head.appendChild(style);
style.type = 'text/css';
style.appendChild(document.createTextNode(css));
}

function changeCalmColor() {
let body = document.body || document.getElementsByTagName('body')[0];
if (body.style.backgroundColor !== 'rgb(255, 255, 255)') {
let css = "body.showCalmText header[role=\"banner\"] h1[role=\"heading\"]::after { color: rgb(255, 255, 255);}";
let head = document.head || document.getElementsByTagName('head')[0];
let style = document.createElement('style');
head.appendChild(style);
style.type = 'text/css';
style.appendChild(document.createTextNode(css));
}
}
}
84 changes: 44 additions & 40 deletions app/scripts/popup.ts
Original file line number Diff line number Diff line change
@@ -1,54 +1,58 @@
localize();
initValues(["isExploreHidden", "isTrendsHidden", "isReactionNumberHidden", "showCalmText"]);
initValues(["isExploreHidden", "isTrendsHidden", "isReactionNumberHidden", "isFollowerNumberHidden", "isReactionNumberAlwaysHidden", "showCalmText"]);

function localize() {
var objects = document.getElementsByTagName('html');
for (var j = 0; j < objects.length; j++)
{
var obj = objects[j];

var valStrH = obj.innerHTML.toString();
var valNewH = valStrH.replace(/__MSG_(\w+)__/g, function(match, v1)
{
return v1 ? chrome.i18n.getMessage(v1) : "";
});

if(valNewH != valStrH)
{
obj.innerHTML = valNewH;
}
var objects = document.getElementsByTagName('html');
for (var j = 0; j < objects.length; j++) {
var obj = objects[j];

var valStrH = obj.innerHTML.toString();
var valNewH = valStrH.replace(/__MSG_(\w+)__/g, function (match, v1) {
return v1 ? chrome.i18n.getMessage(v1) : "";
});

if (valNewH != valStrH) {
obj.innerHTML = valNewH;
}
}

}

function addClickEventListeners(keys: string[]) {
keys.forEach(key => {
var input = document.getElementById(key);
input!.addEventListener('click', function(event) {
var checkbox = event.target as HTMLInputElement;
chrome.storage.local.set({[key] : checkbox!.checked}, function () {});

chrome.tabs.query( {active: true, currentWindow: true}, function(tabs){
let tabId = tabs[0].id;
chrome.tabs.sendMessage(tabId!, {key: key}, function(){});
});
}, false);
});
keys.forEach(key => {
var input = document.getElementById(key);
input!.addEventListener('click', function (event) {
var checkbox = event.target as HTMLInputElement;
chrome.storage.local.set({ [key]: checkbox!.checked }, function () { });

chrome.tabs.query({ active: true, currentWindow: true }, function (tabs) {
let tabId = tabs[0].id;
chrome.tabs.sendMessage(tabId!, { key: key }, function () { });
});
}, false);
});
}

function toggleChecked(keys: string[]) {
chrome.storage.local.get(keys, function(data) {
keys.forEach(key => {
console.log(key + ": " + data[key]);
if (typeof data[key] === "undefined") {
data[key] = true;
}
var input = document.getElementById(key) as HTMLInputElement;
input!.checked = data[key];
});
chrome.storage.local.get(keys, function (data) {
keys.forEach(key => {
console.log(key + ": " + data[key]);
if (key === "isFollowerNumberHidden" || key === "isReactionNumberAlwaysHidden") {
if (typeof data[key] === "undefined") {
data[key] = false;
}
} else {
if (typeof data[key] === "undefined") {
data[key] = true;
}
}
var input = document.getElementById(key) as HTMLInputElement;
input!.checked = data[key];
});
});
}

function initValues(keys: string[]) {
toggleChecked(keys);
addClickEventListeners(keys);
}
toggleChecked(keys);
addClickEventListeners(keys);
}
Loading

0 comments on commit 2dabfb3

Please sign in to comment.