Skip to content

Instantly share code, notes, and snippets.

@bamadesigner
Last active September 12, 2022 18:10
Show Gist options
  • Save bamadesigner/692d61ecf5beaa7fea0f986a616ba6c4 to your computer and use it in GitHub Desktop.
Save bamadesigner/692d61ecf5beaa7fea0f986a616ba6c4 to your computer and use it in GitHub Desktop.
Uncheck all checkboxes
/**
* I was a tad agitated when I realized Twitter had auto-added
* 500+ interests to some weird list in my profile. Manually
* unchecking all of the boxes would've taken forever.
*
* https://twitter.com/settings/your_twitter_data/twitter_interests
*
* I wrote this script to help me auto-uncheck the
* boxes cause ain't nobody got time for that.
*
* FYI: Twitter will continue auto adding interests so
* you might want to bookmark this to run occassionally.
*
* I'd also recommend disabling personalization:
* https://twitter.com/settings/account/personalization
*
* Feel free to use my script by copying and pasting the code
* into the console in your browser. I tried to include lots
* of comments that I hope will be helpful.
*
* WARNING: If you use this script on any web page, it will uncheck
* any and all checkboxes. It is not scoped to a particular section.
*
* I tested the script in Firefox and Chrome. Sometimes it got hung
* up on Twitter's API. If that happens, I recommend refreshing and
* running again. Repeat until the job is done.
*
* I feel I have to warn you against copying and pasting code
* from strangers on the Internet. If you want to not be strangers,
* feel free to say hello.
*
* Rachel Cherry
* https://bamadesigner.com
* @bamadesigner
*/
// Will return an array/list of checkboxes that are checked.
var getCheckedCheckboxes = function() {
return Array.from(document.querySelectorAll('input[type="checkbox"]')).filter( cb => cb.checked === true );
};
// Will click the first checked checkbox.
var uncheckCheckbox = function(checkedBoxes) {
// This means we're just getting started or there are no more boxes to check.
if (!Array.isArray(checkedBoxes) || !checkedBoxes.length) {
// Check for any unchecked checkboxes.
checkedBoxes = getCheckedCheckboxes();
if (!checkedBoxes.length) {
console.info("All of the boxes are unchecked!");
return;
}
}
// Let us know how we're doing.
console.info(
checkedBoxes.length +
(1 == checkedBoxes.length ? " box " : " boxes ") +
"to go."
);
// Uncheck the first checkbox from list. shift() removes from list.
let checkbox = checkedBoxes.shift();
if (true === checkbox.checked) {
checkbox.click();
}
// Run again in 700 milliseconds. Pass the list of checkboxes.
setTimeout(uncheckCheckbox, 700, checkedBoxes);
};
// Start the show!
uncheckCheckbox();
@horse-eye
Copy link

Thanks, very neat :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment