diff --git a/AUTHORS.md b/AUTHORS.md index 57e7455..e4dbe02 100644 --- a/AUTHORS.md +++ b/AUTHORS.md @@ -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/) \ No newline at end of file diff --git a/js/background.js b/js/background.js new file mode 100644 index 0000000..fedbeab --- /dev/null +++ b/js/background.js @@ -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"] + }) + } +}) \ No newline at end of file diff --git a/js/popup.js b/js/popup.js index 08f4641..617177a 100644 --- a/js/popup.js +++ b/js/popup.js @@ -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%', @@ -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) }) @@ -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) { diff --git a/manifest.json b/manifest.json index 33b6ce5..7f54e0d 100644 --- a/manifest.json +++ b/manifest.json @@ -25,11 +25,11 @@ "matches": [""] } ], - "content_scripts": [ - { - "matches": [""], - "js": ["js/filters.js"] - } + "background": { + "service_worker": "js/background.js" + }, + "host_permissions": [ + "" ], "permissions": [ "scripting",