-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added options page to remove whitelisted domains and revoke temporary…
… permissions
- Loading branch information
1 parent
83dfa39
commit 15ec31f
Showing
8 changed files
with
254 additions
and
15 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
.mdl-card__title { | ||
color: #fff; | ||
background: url('../img/icon_128.png') bottom 30% right 10% no-repeat #353f40; | ||
} | ||
|
||
.whitelist-card { | ||
width: 700px; | ||
margin: 20px auto; | ||
} | ||
|
||
.mdl-layout__header, .mdl-mega-footer{ | ||
background: #353f40; | ||
} | ||
|
||
.options-no-whitelist { | ||
margin-top: 60px; | ||
font-weight: bolder; | ||
} |
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,4 +1,6 @@ | ||
const REQ_MAIN_FRAME = 'main_frame'; | ||
const REQ_BLOCKED_URLS = 'blocked_urls'; | ||
const REQ_ALLOW_TEMPORARILY = 'temporarily_allow_domains'; | ||
const REQ_ALLOW_ALWAYS = 'whitelist_domains'; | ||
const REQ_ALLOW_ALWAYS = 'whitelist_domains'; | ||
const REQ_REMOVE_FROM_WHITELIST = 'remove_whitelisted_domains'; | ||
const REQ_REVOKE_FROM_TEMP_LIST = 'revoke_temp_domains'; |
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 |
---|---|---|
@@ -0,0 +1,86 @@ | ||
function setChildTextNode(elementId, text) { | ||
document.getElementById(elementId).innerText = text; | ||
} | ||
|
||
function init() { | ||
document.title = chrome.i18n.getMessage("extensionName") + ' - ' + chrome.i18n.getMessage("textSettingsTitle"); | ||
setChildTextNode('textSettingsTitle', chrome.i18n.getMessage("textSettingsTitle")); | ||
setChildTextNode('textTitleWhitelist', chrome.i18n.getMessage("textSettingsWhiteListTitle")); | ||
setChildTextNode('textWhitelistList', chrome.i18n.getMessage("textSettingsWhiteListDescription")); | ||
setChildTextNode('buttonRemoveFromWhitelist', chrome.i18n.getMessage("buttonRemoveFromWhitelist")); | ||
setChildTextNode('buttonRevokeAllTemp', chrome.i18n.getMessage("buttonRevokeAllTemporary")); | ||
setChildTextNode('textVersionInfo', chrome.i18n.getMessage("extensionName") + ' ' + chrome.app.getDetails().version); | ||
|
||
document.getElementById('buttonRemoveFromWhitelist').onclick = removeFromWhitelist; | ||
document.getElementById('buttonRevokeAllTemp').onclick = revokeAllTemporarilyAllowed; | ||
loadDomainList(); | ||
} | ||
|
||
function revokeAllTemporarilyAllowed() { | ||
chrome.extension.sendRequest({type: REQ_REVOKE_FROM_TEMP_LIST}, function (response) { | ||
var data = {message: chrome.i18n.getMessage("textRevokedFromTemp")}; | ||
document.getElementById('options-snackbar').MaterialSnackbar.showSnackbar(data); | ||
}); | ||
} | ||
|
||
function removeFromWhitelist() { | ||
var domains = getSelectedDomains(); | ||
if (domains.length > 0) { | ||
chrome.extension.sendRequest({type: REQ_REMOVE_FROM_WHITELIST, list: domains}, function (response) { | ||
var data = {message: chrome.i18n.getMessage("textRemovedFromWhitelist")}; | ||
document.getElementById('options-snackbar').MaterialSnackbar.showSnackbar(data); | ||
loadDomainList(); | ||
}); | ||
} | ||
} | ||
|
||
function getSelectedDomains() { | ||
var checkedBoxes = document.querySelectorAll('input[data-domain]:checked'); | ||
|
||
var domains = []; | ||
checkedBoxes.forEach(function (elm) { | ||
var domain = elm.getAttribute('data-domain'); | ||
domains.push(domain); | ||
}); | ||
return domains; | ||
} | ||
|
||
function loadDomainList() { | ||
chrome.storage.local.get('whiteListedDomains', function (object) { | ||
var domains = object.whiteListedDomains; | ||
displayWhitelistedDomains(domains); | ||
}); | ||
} | ||
|
||
function displayWhitelistedDomains(domains) { | ||
|
||
document.getElementById('whitelist_list').innerHTML = ''; | ||
document.getElementById('no_whitelisted_domains').innerText = ''; | ||
|
||
if (!domains || domains.length === 0) { | ||
setChildTextNode('no_whitelisted_domains', chrome.i18n.getMessage("textNoWhitelistedDomains")); | ||
} else { | ||
var container = document.getElementById('whitelist_list'); | ||
var htmlTmpl = document.getElementById('template_list_item').innerHTML; | ||
domains.forEach(function (domain) { | ||
var punycodeDomain = punycode.toUnicode(domain); | ||
var itemHtml = htmlTmpl.replace(/__DOMAIN_TEXT__/g, punycodeDomain); | ||
var itemHtml = itemHtml.replace(/__DOMAIN__/g, domain); | ||
var itemHtml = itemHtml.replace(/__LIST_ID__/g, hash(domain)); | ||
container.innerHTML += itemHtml; | ||
}); | ||
} | ||
} | ||
|
||
function hash(str) { // fast workaround | ||
var hash = 0; | ||
if (str.length === 0) return hash; | ||
for (i = 0; i < str.length; i++) { | ||
char = str.charCodeAt(i); | ||
hash = ((hash << 5) - hash) + char; | ||
hash = hash & hash; // Convert to 32bit integer | ||
} | ||
return hash; | ||
} | ||
|
||
document.addEventListener('DOMContentLoaded', init); |
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