Skip to content

Instantly share code, notes, and snippets.

@r007
Last active November 4, 2015 17:27
Show Gist options
  • Save r007/e3cf3888dc798ef4ce80 to your computer and use it in GitHub Desktop.
Save r007/e3cf3888dc798ef4ce80 to your computer and use it in GitHub Desktop.
Select All Checkboxes on Facebook Pixel Page
// ----------Select all helper for Facebook pixel----------------------------------------------
//
// ==UserScript==
// @name Select All Checkboxes on Facebook Pixel Page
// @namespace r007.github.com/
// @version 0.01
// @description Multi-select a range of checkboxes
// @include http*://business.facebook.com/ads/manager/*
// ==/UserScript==
var allchecks, thisLink, haveCheckboxes = false;
allchecks = document.evaluate(
'//input[@type="checkbox"]',
document,
null,
XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,
null);
window.setInterval(function() {
if (!haveCheckboxes) {
haveCheckboxes = true;
check_elements();
}
}, 100);
function check_elements() {
if (allchecks.snapshotLength) {
var logo = document.createElement("div");
logo.innerHTML = '<div style="background-color: black; margin:0;padding:0;color:white; text-align: center;">Checkboxes check: <a href="#" id="_all" style="color: white">All</a> <a href="#" id="_none" style="color: white">None</a> <a href="#" id="_invert" style="color: white">Invert</a></div>';
document.body.insertBefore(logo, document.body.firstChild);
_all = document.getElementById('_all');
_all.addEventListener('click', function(event) {
for (var i = 0; i < allchecks.snapshotLength; i++) {
thisLink = allchecks.snapshotItem(i);
thisLink.checked = true;
event.preventDefault();
}
}, true)
_none = document.getElementById('_none');
_none.addEventListener('click', function(event) {
for (var i = 0; i < allchecks.snapshotLength; i++) {
thisLink = allchecks.snapshotItem(i);
thisLink.checked = false;
event.preventDefault();
}
}, true)
_invert = document.getElementById('_invert');
_invert.addEventListener('click', function(event) {
for (var i = 0; i < allchecks.snapshotLength; i++) {
thisLink = allchecks.snapshotItem(i);
thisLink.checked = !thisLink.checked;
event.preventDefault();
}
}, true)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment