-
Notifications
You must be signed in to change notification settings - Fork 1
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
1 parent
05092b1
commit 4213a9e
Showing
3 changed files
with
16 additions
and
50 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,4 @@ | ||
//Listeners for colorblind filter buttons | ||
//Injects a javascript file on click event, the js file applies a filter to simulate colorblindness | ||
|
||
// stores the currently selected filter so that when the user stops hovering | ||
// over options, the currently selected filter will still be applied to the popup | ||
window.selectedFilter = null; | ||
|
||
/** | ||
* get the selected filter on popup open | ||
*/ | ||
window.onload = function() { | ||
if (!chrome || !chrome.storage || !chrome.storage.local) return; | ||
chrome.storage.local.get(["key"], function(result) { | ||
try { | ||
document.getElementById(result.key).click(); | ||
} catch (e) { | ||
console.log(e); | ||
} | ||
}); | ||
}; | ||
|
||
/** | ||
* Sets the selected filter in storage | ||
* @param {String} value the selected input | ||
*/ | ||
function setSelected(value) { | ||
try { | ||
chrome.storage.local.set({ key: value }, function() { | ||
document.getElementById(value).checked = true; | ||
}); | ||
} catch {} | ||
} | ||
|
||
function injectFilter(fileName) { | ||
chrome.tabs.executeScript({ file: fileName }); | ||
} | ||
|
||
document.querySelectorAll(['[id^="radio"]']).forEach(radioButton => { | ||
const filter = radioButton.parentElement.id.replace("option-", ""); | ||
radioButton.addEventListener("click", function() { | ||
// page-specific filters | ||
setSelected(radioButton.id); | ||
injectFilter(`filters/${filter}.js`); | ||
// popup-specific filters | ||
applyFilter((window.selectedFilter = filter)); | ||
}); | ||
chrome.scripting.executeScript({ | ||
target: {tabId: chrome.window.getCurrent, allFrames: true}, | ||
files: ['colorblindListener.js'], | ||
}); |
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