Skip to content

Commit

Permalink
fix: reduce needed permissions
Browse files Browse the repository at this point in the history
Reduce needed permissions for extension
Utilize service worker script
Fix state tracking for current active filter

Reorder authors
  • Loading branch information
cadomac committed Aug 3, 2023
1 parent 7aa5ebd commit bd5ac1b
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 12 deletions.
3 changes: 2 additions & 1 deletion AUTHORS.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
[Cameron MacDonald](https://www.linkedin.com/in/macdonaldcameron/)

[Sean Isaac Geronimo Anderson](https://www.linkedin.com/in/seanisaacgeronimoanderson/)

[Rowan Garrigan](https://devpost.com/BattyHats)

[Márcio Porto](https://www.linkedin.com/in/marcioporto/)

[Cameron MacDonald](https://www.linkedin.com/in/macdonaldcameron/)

[Ana George](https://www.linkedin.com/in/ana-george/)
10 changes: 10 additions & 0 deletions js/background.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
chrome.tabs.onUpdated.addListener((tabId, changeInfo, tab) => {
console.log("loaded")
if (changeInfo.status === "complete" && tab.active) {
console.log("active")
chrome.scripting.executeScript({
target: {tabId: tab.id},
files: ["js/filters.js"]
})
}
})
22 changes: 16 additions & 6 deletions js/popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,18 @@ $.all = function (selector, context) {
)
}

var ul = document.createElement('ul'),
current = 'NoFilter',
let current;

if (!localStorage.getItem("currentFilter")) {
localStorage.setItem("currentFilter", "NoFilter");
current = "NoFilter";
} else {
current = localStorage.getItem("currentFilter");
}

let ul = document.createElement('ul'),
vision = {
NoFilter: '',
"NoFilter": '',
'HueRotate': '6%',
'TrueColor': '6%',
'TrueColorG': '6%',
Expand All @@ -20,11 +28,12 @@ var ul = document.createElement('ul'),
}

Object.keys(vision).forEach(function (el) {
var li = document.createElement('li')
let li = document.createElement('li')
li.dataset['type'] = el
li.textContent = el
li.addEventListener('click', handler, false)
el == current && li.classList.add('current')
console.log(el, localStorage.getItem("currentFilter"))
el == localStorage.getItem("currentFilter") && li.classList.add('current')
ul.appendChild(li)
})

Expand All @@ -35,7 +44,8 @@ function handler(e) {
$.all('li').forEach(function(li) {
li.classList.remove('current')
})
this.classList.add('current')
this.classList.add('current');
localStorage.setItem("currentFilter", current);
chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
let currTab = tabs[0];
if (currTab) {
Expand Down
10 changes: 5 additions & 5 deletions manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@
"matches": ["<all_urls>"]
}
],
"content_scripts": [
{
"matches": ["<all_urls>"],
"js": ["js/filters.js"]
}
"background": {
"service_worker": "js/background.js"
},
"host_permissions": [
"<all_urls>"
],
"permissions": [
"scripting",
Expand Down

0 comments on commit bd5ac1b

Please sign in to comment.