-
-
Notifications
You must be signed in to change notification settings - Fork 114
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
Add Whitelist #372
base: master
Are you sure you want to change the base?
Add Whitelist #372
Changes from all commits
858863d
56ccb0c
af9cbe5
19d3448
5dbb116
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -62,6 +62,40 @@ function changeStatistics() | |
elTotal.textContent = totalCounter.toLocaleString(); | ||
} | ||
|
||
/** | ||
* Set the whitelist button text | ||
*/ | ||
function setWhitelistText() | ||
{ | ||
let element = document.getElementById('whitelist_btn'); | ||
let currentSite, siteFound; | ||
browser.tabs.query({active: true, currentWindow: true}, function(tabs) { | ||
currentSite = tabs[0].url; | ||
}); | ||
|
||
browser.runtime.sendMessage({ | ||
function: "getData", | ||
params: ['whitelist'] | ||
}).then((data) => { | ||
data.response.forEach(site => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should be replaced by the following: |
||
if (currentSite.indexOf(site) != -1) { | ||
siteFound = true | ||
} | ||
}); | ||
if (!siteFound) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Swap both cases |
||
if (data.response.length != 0) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove this If. It causes the button to retain the "btn-danger" class when a page is added and immediately removed. |
||
element.classList.replace('btn-danger', 'btn-primary') | ||
} | ||
element.textContent = translate('popup_html_configs_whitelist_button_add') | ||
document.getElementById('whitelist_btn').onclick = changeWhitelist; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Pass the desired state here: |
||
} else { | ||
element.classList.replace('btn-primary', 'btn-danger') | ||
element.textContent = translate('popup_html_configs_whitelist_button_remove') | ||
document.getElementById('whitelist_btn').onclick = () => {changeWhitelist(true)}; | ||
} | ||
}).catch(handleError); | ||
} | ||
|
||
/** | ||
* Set the value for the hashStatus on startUp. | ||
*/ | ||
|
@@ -155,6 +189,39 @@ function setSwitchButton(id, varname) | |
element.checked = this[varname]; | ||
} | ||
|
||
/** | ||
* Adds (or removes) the site the user is on to the whitelist | ||
* Whitelisted sites do not get filtered | ||
* @param {boolean} remove If true remove current site instead of adding | ||
*/ | ||
function changeWhitelist(removeWl = false) { | ||
if (removeWl != true) { // Handle click obj | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Assignment is useless. It is better to pass the correct state in the onclick event |
||
removeWl = false | ||
} | ||
let site; | ||
browser.tabs.query({active: true, currentWindow: true}, function(tabs) { // Couldn't figure out how to access currentUrl var | ||
site = tabs[0].url; // So this is used instead | ||
}); | ||
browser.runtime.sendMessage({ | ||
function: "getData", | ||
params: ['whitelist'] | ||
}).then((data) => { | ||
let siteUrl = new URL(site) | ||
let domain = siteUrl.hostname | ||
if (removeWl == false) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Swap both cases |
||
data.response.push(domain) | ||
} else { | ||
data.response = data.response.filter(wlSite => wlSite != domain) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unsafe comparison, better |
||
} | ||
browser.runtime.sendMessage({ | ||
function: "setData", | ||
params: ['whitelist', data.response] | ||
}).then(() => { | ||
setWhitelistText(); | ||
}).catch(handleError); | ||
}).catch(handleError); | ||
} | ||
|
||
/** | ||
* Reset the global statistic | ||
*/ | ||
|
@@ -220,6 +287,7 @@ function setText() | |
injectText('configs_switch_filter','popup_html_configs_switch_filter'); | ||
injectText('configs_head','popup_html_configs_head'); | ||
injectText('configs_switch_statistics','configs_switch_statistics'); | ||
setWhitelistText(); | ||
document.getElementById('donate').title = translate('donate_button'); | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
!==