Last active
July 5, 2023 13:44
-
-
Save michaelprovenzano/b64355c5dd0b932b1facdb5c96d9c4a7 to your computer and use it in GitHub Desktop.
This simple code will select multiple facebook friends for you to invite to your Facebook Business Page.
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
/* | |
========================================================================== | |
Select Multiple Facebook Friends | |
========================================================================== | |
This simple code will select multiple facebook friends for you to invite | |
to your Facebook Business Page. | |
To use this code you need to paste it into your Devloper Console and hit | |
the "Enter" key. Here is a blog article with instructions on how to open | |
your Developer Console: | |
https://balsamiq.com/support/faqs/browserconsole/#:~:text=Google%20Chrome,-To%20open%20the&text=You%20can%20also%20use%20Option,to%20select%20the%20Console%20tab. | |
DISCLAIMER: ONLY EVER PASTE CODE YOU UNDERSTAND! I HAVE TAKEN | |
THE TIME TO CLEARLY EXPLAIN WHAT THIS CODE IS DOING SO YOU DO UNDERSTAND | |
IT, BUT IF YOU STILL DON'T FOLLOW ALONG OR DON'T TRUST IT THEN DON'T USE | |
IT. THIS CODE, IF USED AS IS, WILL NOT HARM YOUR FACEBOOK PROFILE. IT | |
ONLY CHECKS BOXES. | |
*/ | |
// Define the number of friends you'd like to select. | |
// Facebook currently limits invites to 49 at a time | |
let numberOfFriendsToSelect = 49; | |
// We are going to create a simple button so we don't have | |
// to paste this code over and over to select friends. If | |
// you refresh your browser it will disappear. Don't worry, | |
// this button will only exist until you reload and it | |
// does not do anything to your facebook profile. | |
let selectFriendsButton = document.createElement('button'); | |
selectFriendsButton.innerText = "Select Multiple Friends"; // Name the button | |
selectFriendsButton.style.position = "fixed"; // Put the button in fixed position on the page | |
selectFriendsButton.style.right = "10px"; // Put the button on the right side of the screen | |
selectFriendsButton.style.bottom = "10px"; // Put the button on the bottom of the screen | |
selectFriendsButton.style.zIndex = 999999; // zIndex makes sure nothing will pop up over the button | |
// Here we tell the browser that if we click on this new button to run | |
// the function "selectMultipleFriends" | |
selectFriendsButton.addEventListener('click', selectMultipleFriends); | |
// This line inserts the button on the page so we can click on it. | |
document.querySelector('body').insertAdjacentElement('beforeend', selectFriendsButton); | |
// This is the function that actually will check all of our checkboxes for us | |
function selectMultipleFriends() { | |
// Select all of the checkboxes on the page | |
let checkboxes = [...document.querySelectorAll('input[type="checkbox"]')]; | |
// This sets up something called a loop, that basically | |
// allows us to run a command on each checkbox | |
checkboxes.forEach((currentCheckbox, i) => { | |
// DEEPER CONTEXT | |
// The variable "i" stands for the current iteration | |
// It is increased by 1 for each checkbox. So think of | |
// it like each checkbox is numbered [ 0, 1, 2, 3, 4... ] | |
// Fun fact: computers start counting at 0 not 1 | |
// In this context we are using the "return" keyword to | |
// ignore everything that comes after it. | |
// This line says if it's the first checkbox, then ignore it | |
if (i === 0) return; | |
// If the current iteration (or checkbox #) is greater than | |
// the amount of friends you want to select, ignore it. | |
if (i > numberOfFriendsToSelect) return; | |
// Console.log statements basically write things to the console | |
// This will just tell you what # box it's currently checking | |
console.log('Checking box #: ' + i); | |
// Each checkbox is inside something called a "label" | |
// We are going to select the current label for the checkbox | |
let currentLabel = currentCheckbox.parentNode.parentNode; | |
// We are going to click each label to select the checkbox | |
currentLabel.click(); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment