-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
262 additions
and
131 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
Oops, something went wrong.