Skip to content

Instantly share code, notes, and snippets.

@ronen-e
Last active May 24, 2021 08:55
Show Gist options
  • Save ronen-e/1b3fbeb9173b22f8a2ab1b13c7b54196 to your computer and use it in GitHub Desktop.
Save ronen-e/1b3fbeb9173b22f8a2ab1b13c7b54196 to your computer and use it in GitHub Desktop.
bookmarklet for easier unfriending on facebook

Intro

A quick JavaScript code I wrote to remove a lot of contacts on Facebook. This is a simpler way of unfriending a lot of contacts in facebook. You still need to manually confirm removal.

Instructions

  1. Create a bookmark with the code snippet as the URL.
  2. Add it to your bookmarks bar.
  3. Go to the mobile version of Facebook friends page (https://m.facebook.com/friends/center/friends)
  4. Click on the bookmark

Create a bookmark

For information how to create a bookmark: https://www.scrapersnbots.com/blog/code/how-to-create-javascript-bookmarklet.php

Usage

The script runs from top to bottom. It pops a confirmation message for each contact. Confirm to remove contact, Cancel to proceed to the next contact. After about 50 contacts you will receive a popup asking if you wish to proceed. If you handled a lot of contacts (hundreds or thousands) the page will be slow - I suggest to reload the page.

Suggested usage

  • Use Enter button to confirm
  • Use Esc button to cancel

Caveats

Removing too many contacts in a short time period will cause this specific action to become restricted for a 1-2 days by facebook.

I do not know the policy settings for activating account restriction. I suggest taking a short break after removing 100-200 contacts.

/*
Copyright (c) 2021, Ronen Elster
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
javascript:(function() {async function sleep(ms = 100) { return new Promise( (resolve) => {setTimeout(resolve, ms);} ); }function last(list) { return list[list.length-1];}var fmemory = fmemory || new Set();async function unFriender(options={}) { var items = document.querySelectorAll('i[data-sigil=are-friends-popup]'); items = Array.from(items); console.log(items); if (options.start) { items = items.slice(options.start); } for (let item of items) { try { await handleFriend(item); } catch (e) { console.warn(e); } } console.log('done'); if (window.confirm('proceed')) { let start = options.start || 0; start += items.length; options = Object.assign({}, options, { start: start }); setTimeout(() => unFriender(options), 100); } async function handleFriend(menu) { menu.click(); await sleep(100); var parent = menu.closest('[data-sigil=undoable-action]'); var header = parent.querySelector('h1,h2,h3'); var name = header.innerText; if (fmemory.has(name)) { console.log(name + ' already handled'); return } fmemory.add(name); console.log('unfriend?', name); if (window.confirm('unfriend? ' + name)) { const actions = menu.parentElement.querySelectorAll('[data-sigil*=m-unfriend-request]'); const btn = last(actions); btn && btn.click(); console.log('removed ' + name); } await sleep(100); }}unFriender();}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment