Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(notification): add hide notification #26

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions app/_locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@
"titleShowCalmText": {
"message": "Show \"Calm\" next to the logo"
},
"titleIsNotificationHidden": {
"message": "Hide Notifications Badge"
},
"titleIsMessageNotificationHidden": {
"message": "Hide Message Notifications Badge"
},
"titleIsFollowingNumberHidden": {
"message": "Hide number of following"
},
Expand Down
120 changes: 63 additions & 57 deletions app/pages/popup.html
Original file line number Diff line number Diff line change
@@ -1,60 +1,66 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>__MSG_appName__</title>
<link rel="stylesheet" type="text/css" href="../styles/popup.css" />
</head>

<head>
<meta charset="utf-8" />
<title>__MSG_appName__</title>
<link rel="stylesheet" type="text/css" href="../styles/popup.css">
</head>

<body>
<h1>__MSG_appName__</h1>
<label class="check">
<input type="checkbox" id="isExploreHidden" checked>
<span>__MSG_titleIsExploreHidden__</span>
</label>
<label class="check">
<input type="checkbox" id="isTrendsHidden" checked>
<span>__MSG_titleIsTrendsHidden__</span>
</label>
<label class="check">
<input type="checkbox" id="isReactionNumberHidden" checked>
<span>__MSG_titleIsReactionNumberHidden__</span>
</label>
<label class="check">
<input type="checkbox" id="showCalmText" checked>
<span>__MSG_titleShowCalmText__</span>
</label>
<h2>__MSG_titleAdditionalSettings__</h2>
<label class="check">
<input type="checkbox" id="isFollowingNumberHidden">
<span>__MSG_titleIsFollowingNumberHidden__</span>
</label>
<label class="check">
<input type="checkbox" id="isFollowerNumberHidden">
<span>__MSG_titleIsFollowerNumberHidden__</span>
</label>
<label class="check">
<input type="checkbox" id="isReactionNumberDetailHidden">
<span>__MSG_titleIsReactionNumberDetailHidden__</span>
</label>
<label class="check">
<input type="checkbox" id="isReactionNumberAlwaysHidden">
<span>__MSG_titleIsReactionNumberAlwaysHidden__</span>
</label>
<label class="check">
<input type="checkbox" id="isWhoToFollowHidden">
<span>__MSG_titleIsWhoToFollowHidden__</span>
</label>
<label class="check">
<input type="checkbox" id="isTopicsToFollowHidden">
<span>__MSG_titleIsTopicsToFollowHidden__</span>
</label>
<label class="check">
<input type="checkbox" id="isFontChanged">
<span>__MSG_titleIsFontChanged__</span>
</label>
<script src="../scripts/popup.js"></script>
</body>

</html>
<body>
<h1>__MSG_appName__</h1>
<label class="check">
<input type="checkbox" id="isExploreHidden" checked />
<span>__MSG_titleIsExploreHidden__</span>
</label>
<label class="check">
<input type="checkbox" id="isTrendsHidden" checked />
<span>__MSG_titleIsTrendsHidden__</span>
</label>
<label class="check">
<input type="checkbox" id="isReactionNumberHidden" checked />
<span>__MSG_titleIsReactionNumberHidden__</span>
</label>
<label class="check">
<input type="checkbox" id="showCalmText" checked />
<span>__MSG_titleShowCalmText__</span>
</label>
<h2>__MSG_titleAdditionalSettings__</h2>
<label class="check">
<input type="checkbox" id="isFollowingNumberHidden" />
<span>__MSG_titleIsFollowingNumberHidden__</span>
</label>
<label class="check">
<input type="checkbox" id="isFollowerNumberHidden" />
<span>__MSG_titleIsFollowerNumberHidden__</span>
</label>
<label class="check">
<input type="checkbox" id="isReactionNumberDetailHidden" />
<span>__MSG_titleIsReactionNumberDetailHidden__</span>
</label>
<label class="check">
<input type="checkbox" id="isReactionNumberAlwaysHidden" />
<span>__MSG_titleIsReactionNumberAlwaysHidden__</span>
</label>
<label class="check">
<input type="checkbox" id="isWhoToFollowHidden" />
<span>__MSG_titleIsWhoToFollowHidden__</span>
</label>
<label class="check">
<input type="checkbox" id="isTopicsToFollowHidden" />
<span>__MSG_titleIsTopicsToFollowHidden__</span>
</label>
<label class="check">
<input type="checkbox" id="isNotificationHidden" />
<span>__MSG_titleIsNotificationHidden__</span>
</label>
<label class="check">
<input type="checkbox" id="isMessageNotificationHidden" />
<span>__MSG_titleIsMessageNotificationHidden__</span>
</label>
<label class="check">
<input type="checkbox" id="isFontChanged" />
<span>__MSG_titleIsFontChanged__</span>
</label>
<script src="../scripts/popup.js"></script>
</body>
</html>
60 changes: 45 additions & 15 deletions app/scripts/contentscript.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,35 @@
toggleClass(["isExploreHidden", "isTrendsHidden", "isReactionNumberHidden", "showCalmText", "isFollowingNumberHidden", "isFollowerNumberHidden", "isReactionNumberAlwaysHidden", "isReactionNumberDetailHidden", "isWhoToFollowHidden", "isTopicsToFollowHidden", "isFontChanged"]);
toggleClass([
"isExploreHidden",
"isTrendsHidden",
"isReactionNumberHidden",
"showCalmText",
"isFollowingNumberHidden",
"isFollowerNumberHidden",
"isReactionNumberAlwaysHidden",
"isReactionNumberDetailHidden",
"isWhoToFollowHidden",
"isTopicsToFollowHidden",
"isNotificationHidden",
"isMessageNotificationHidden",
"isFontChanged",
]);
addCalmTitle();
for (let i = 0; i < 2; i++) {
setTimeout(changeCalmColor, (i + 1) * 100);
}

function toggleClass(keys: string[]) {
chrome.storage.local.get(keys, function (data) {
keys.forEach(key => {
if (key === "isFollowingNumberHidden" || key === "isFollowerNumberHidden" || key === "isReactionNumberAlwaysHidden" || key === "isReactionNumberDetailHidden" || key === "isWhoToFollowHidden" || key === "isTopicsToFollowHidden" || key === "isFontChanged") {
keys.forEach((key) => {
if (
key === "isFollowingNumberHidden" ||
key === "isFollowerNumberHidden" ||
key === "isReactionNumberAlwaysHidden" ||
key === "isReactionNumberDetailHidden" ||
key === "isWhoToFollowHidden" ||
key === "isTopicsToFollowHidden" ||
key === "isFontChanged"
) {
if (typeof data[key] === "undefined") {
data[key] = false;
}
Expand All @@ -16,7 +38,7 @@ function toggleClass(keys: string[]) {
data[key] = true;
}
}
let body = document.getElementsByTagName('body')[0];
let body = document.getElementsByTagName("body")[0];
if (data[key]) {
body.classList.add(key);
} else {
Expand All @@ -31,28 +53,36 @@ chrome.runtime.onMessage.addListener(function (request, sender, sendResponse) {
sendResponse();
});

chrome.runtime.sendMessage({ from: 'content', subject: 'showPageAction' });
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 head = document.head || document.getElementsByTagName('head')[0];
let style = document.createElement('style');
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.type = "text/css";
style.appendChild(document.createTextNode(css));
}

function changeCalmColor() {
let body = document.body || document.getElementsByTagName('body')[0];
let body = document.body || document.getElementsByTagName("body")[0];
if (body.style.backgroundColor !== null) {
const logo = (<HTMLElement>document.querySelector('header[role="banner"] h1[role="heading"] > a svg'));
const logo = <HTMLElement>(
document.querySelector('header[role="banner"] h1[role="heading"] > a svg')
);
if (logo !== null) {
let css = "body.showCalmText header[role=\"banner\"] h1[role=\"heading\"]::after { color: " + window.getComputedStyle(logo).color + ";}";
let head = document.head || document.getElementsByTagName('head')[0];
let style = document.createElement('style');
let css =
'body.showCalmText header[role="banner"] h1[role="heading"]::after { color: ' +
window.getComputedStyle(logo).color +
";}";
let head = document.head || document.getElementsByTagName("head")[0];
let style = document.createElement("style");
head.appendChild(style);
style.type = 'text/css';
style.type = "text/css";
style.appendChild(document.createTextNode(css));
}
}
Expand Down
56 changes: 42 additions & 14 deletions app/scripts/popup.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,22 @@
localize();
initValues(["isExploreHidden", "isTrendsHidden", "isReactionNumberHidden", "showCalmText", "isFollowingNumberHidden", "isFollowerNumberHidden", "isReactionNumberAlwaysHidden", "isReactionNumberDetailHidden", "isWhoToFollowHidden", "isTopicsToFollowHidden", "isFontChanged"]);
initValues([
"isExploreHidden",
"isTrendsHidden",
"isReactionNumberHidden",
"showCalmText",
"isFollowingNumberHidden",
"isFollowerNumberHidden",
"isReactionNumberAlwaysHidden",
"isReactionNumberDetailHidden",
"isWhoToFollowHidden",
"isTopicsToFollowHidden",
"isNotificationHidden",
"isMessageNotificationHidden",
"isFontChanged",
]);

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

Expand All @@ -15,29 +29,43 @@ function localize() {
obj.innerHTML = valNewH;
}
}

}

function addClickEventListeners(keys: string[]) {
keys.forEach(key => {
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 () { });
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);
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 => {
keys.forEach((key) => {
console.log(key + ": " + data[key]);
if (key === "isFollowingNumberHidden" || key === "isFollowerNumberHidden" || key === "isReactionNumberAlwaysHidden" || key === "isReactionNumberDetailHidden" || key === "isWhoToFollowHidden" || key === "isTopicsToFollowHidden" || key === "isFontChanged") {
if (
key === "isFollowingNumberHidden" ||
key === "isFollowerNumberHidden" ||
key === "isReactionNumberAlwaysHidden" ||
key === "isReactionNumberDetailHidden" ||
key === "isWhoToFollowHidden" ||
key === "isTopicsToFollowHidden" ||
key === "isFontChanged"
) {
if (typeof data[key] === "undefined") {
data[key] = false;
}
Expand Down
Loading