[URGENT] Fixing unchecking
This commit is contained in:
parent
54998a68a4
commit
136b0ecae1
2 changed files with 90 additions and 7 deletions
86
test/frame.html
Normal file
86
test/frame.html
Normal file
|
@ -0,0 +1,86 @@
|
||||||
|
<!--
|
||||||
|
* Unchecker - Simple extension letting you uncheck all checkboxes on a page
|
||||||
|
* Copyright (c) Ad5001 2021-2023
|
||||||
|
*
|
||||||
|
* This Source Code Form is subject to the terms of the Mozilla Public License,
|
||||||
|
* v. 2.0. If a copy of the MPL was not distributed with this file, You can
|
||||||
|
* obtain one at http://mozilla.org/MPL/2.0/.
|
||||||
|
-->
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<title>Unchecker tests in iframe</title>
|
||||||
|
<style>
|
||||||
|
legend {
|
||||||
|
background-color: #000;
|
||||||
|
color: #fff;
|
||||||
|
padding: 3px 6px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.toggled {
|
||||||
|
border-color: blue;
|
||||||
|
}
|
||||||
|
|
||||||
|
input {
|
||||||
|
margin: .4rem;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
<script src="test.js"></script>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<fieldset>
|
||||||
|
<legend>Example radio list</legend>
|
||||||
|
|
||||||
|
<input type="radio" id="choice-value1" name="choice-value">
|
||||||
|
<label for="choice-value">Example, irrelevant choice value 1</label><br/>
|
||||||
|
|
||||||
|
<input type="radio" id="choice-value2" name="choice-value">
|
||||||
|
<label for="choice-value">Example, irrelevant choice value 2</label><br/>
|
||||||
|
</fieldset>
|
||||||
|
<br>
|
||||||
|
<fieldset>
|
||||||
|
<legend>Third party partners example</legend>
|
||||||
|
|
||||||
|
<input type="checkbox" id="ga-choice" checked="true">
|
||||||
|
<label for="ga-choice">Google Analytics</label><br/>
|
||||||
|
|
||||||
|
<input type="checkbox" id="facebook-ads" checked="true">
|
||||||
|
<label for="facebook-ads">Facebook Partnering</label><br/>
|
||||||
|
|
||||||
|
<input type="checkbox" id="amazon-sales" checked="true">
|
||||||
|
<label for="amazon-sales">Amazon</label><br/>
|
||||||
|
|
||||||
|
<input type="checkbox" id="salesforce" checked="true">
|
||||||
|
<label for="salesforce">Salesforce</label><br/>
|
||||||
|
</fieldset>
|
||||||
|
<br>
|
||||||
|
<fieldset>
|
||||||
|
<legend>Third party partners second</legend>
|
||||||
|
|
||||||
|
<table>
|
||||||
|
<tr>
|
||||||
|
<td>Google Analytics</td>
|
||||||
|
<td><button role="toggle" class="toggled" name="ga-choice">On</button></td>
|
||||||
|
<td><button role="toggle" name="ga-choice">Off</button></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>Facebook Partnering</td>
|
||||||
|
<td><button role="toggle" class="toggled" name="facebook-ads">On</button></td>
|
||||||
|
<td><button role="toggle" name="facebook-ads">Off</button></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>Amazon</td>
|
||||||
|
<td><button role="toggle" class="toggled" name="amazon-sales">On</button></td>
|
||||||
|
<td><button role="toggle" name="amazon-sales">Off</button></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>Salesforce</td>
|
||||||
|
<td><button role="toggle" class="toggled" name="salesforce">On</button></td>
|
||||||
|
<td><button role="toggle" name="salesforce">Off</button></td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
</fieldset>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
|
11
uncheck.js
11
uncheck.js
|
@ -7,16 +7,14 @@
|
||||||
* obtain one at http://mozilla.org/MPL/2.0/.
|
* obtain one at http://mozilla.org/MPL/2.0/.
|
||||||
**/
|
**/
|
||||||
|
|
||||||
const CHECKBOX_QUERY = 'input[type="checkbox"]'
|
|
||||||
|
|
||||||
const uncheckAll = () => {
|
const uncheckAll = () => {
|
||||||
document.body.querySelectorAll(CHECKBOX_QUERY).forEach(function(el){
|
document.body.querySelectorAll('input[type="checkbox"]').forEach(function(el){
|
||||||
el.checked = false
|
el.checked = false
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
const checkAll = () => {
|
const checkAll = () => {
|
||||||
document.body.querySelectorAll(CHECKBOX_QUERY).forEach(function(el){
|
document.body.querySelectorAll('input[type="checkbox"]').forEach(function(el){
|
||||||
el.checked = true
|
el.checked = true
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -32,15 +30,14 @@ const MENU_CONTEXTS = ["all"]
|
||||||
function toggleScript(tab) {
|
function toggleScript(tab) {
|
||||||
|
|
||||||
function gotTitle(title) {
|
function gotTitle(title) {
|
||||||
console.log(title === TITLE_UNCHECK ? "Unchecking all checkboxes..." : "Checking all checkboxes...")
|
console.log((title === TITLE_UNCHECK ? "Unchecking all checkboxes..." : "Checking all checkboxes...") + " at tab " + tab.id)
|
||||||
if(title === TITLE_UNCHECK) {
|
if(title === TITLE_UNCHECK) {
|
||||||
browser.action.setIcon({tabId: tab.id, path: "icons/off.svg"})
|
browser.action.setIcon({tabId: tab.id, path: "icons/off.svg"})
|
||||||
browser.action.setTitle({tabId: tab.id, title: TITLE_CHECK})
|
browser.action.setTitle({tabId: tab.id, title: TITLE_CHECK})
|
||||||
browser.scripting.executeScript({
|
browser.scripting.executeScript({
|
||||||
func: uncheckAll,
|
func: uncheckAll,
|
||||||
target: {
|
target: {
|
||||||
tabId: tab.id,
|
tabId: tab.id
|
||||||
allFrames: true,
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
if(browser.menus)
|
if(browser.menus)
|
||||||
|
|
Loading…
Reference in a new issue