Forked from vsubhash/com.vsubhash.js.facebook-posts-deleter
Created
November 25, 2017 03:46
-
-
Save sudikrt/cd8b9ff910a749ae6bb909b54f16cce8 to your computer and use it in GitHub Desktop.
"Facebook Posts Deleter 2016" script is a Greasemonkey JavaScript that will automatically delete Facebook posts one by one without any user intervention. Install this script in Firefox using the Greasemonkey add-on. Then, go to your "Activity Log" and click on the "Delete Facebook Posts" that pops on the top-left.
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
// ==UserScript== | |
// @name Facebook Posts Deleter 2016 | |
// @namespace com.vsubhash.js.facebook_posts_deleter.2016 | |
// @description Automatically deletes posts from Activity Log of Facebook, one by one. | |
// @include https://www.facebook.com/*=allactivity | |
// @version 1 | |
// @grant none | |
// ==/UserScript== | |
document.addEventListener("DOMContentLoaded", | |
addFacebookPostsDeleteButton, | |
false); | |
var oMvFbTimeout1, oMvFbTimeout2, oMvFbTimeout3; | |
function deleteTimelinePosts() { | |
var i, j, k; | |
if (document.getElementsByClassName("fbTimelineLogStream").length > 0) { | |
console.error("Found a stream DIV"); | |
for (n = 0; n < document.getElementsByClassName("fbTimelineLogStream").length; n++) { | |
var oStreamDiv = document.getElementsByClassName("fbTimelineLogStream")[n]; | |
for (i = 0; i < oStreamDiv.getElementsByTagName("div").length; i++) { | |
// console.error("Class name of DIV" + oStreamDiv.getElementsByTagName("div")[i].className); | |
if ((oStreamDiv.getElementsByTagName("div")[i].className.indexOf("pam") != -1) && | |
(oStreamDiv.getElementsByTagName("div")[i].className.indexOf("uiBoxWhite") != -1) && | |
(oStreamDiv.getElementsByTagName("div")[i].className.indexOf("bottomborder") != -1)) { | |
// console.error("Found a post DIV in the stream DIV"); | |
var oPostDiv = oStreamDiv.getElementsByTagName("div")[i]; | |
if (oPostDiv.getElementsByTagName("table").length > 0) { | |
if (oPostDiv.getElementsByTagName("table")[0].getElementsByTagName("td").length == 3) { | |
// console.error("Found a table in the post DIV"); | |
var oCell = oPostDiv.getElementsByTagName("table")[0].getElementsByTagName("td")[2]; | |
var oCellMenuLink = oCell.getElementsByTagName("div")[0].getElementsByTagName("div")[0].getElementsByTagName("a")[0]; | |
oCellMenuLink.click(); | |
clickDelete(); | |
return; | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
function clickDelete() { | |
var oMenuItems = document.getElementsByClassName("__MenuItem"); | |
for (var i = 0; i < oMenuItems.length; i++) { | |
if (oMenuItems[i].getElementsByTagName("a").length > 0) { | |
var oMenuItemLink = oMenuItems[i].getElementsByTagName("a")[0]; | |
if (oMenuItemLink.getAttribute("ajaxify").indexOf("/ajax/timeline/delete/confirm") != -1) { | |
// console.error("Ajaxify " + oMenuItemLink.getAttribute("ajaxify")); | |
oMenuItemLink.style.backgroundColor = "orange"; | |
if (oMvFbTimeout2 != null) { window.clearTimeout(oMvFbTimeout2); } | |
oMvFbTimeout2 = window.setTimeout( | |
function() { | |
var oForms = document.getElementsByTagName("form"); | |
for (var j = 0; j < oForms.length; j++) { | |
if (oForms[j].getAttribute("action").indexOf("/ajax/timeline/delete") != -1) { | |
var oButtons = oForms[j].getElementsByTagName("button"); | |
for (var k = 0; k < oButtons.length; k++) { | |
if (oButtons[k].textContent.indexOf("Delete Post") != -1) { | |
if (oMvFbTimeout3 != null) { window.clearTimeout(oMvFbTimeout3); } | |
oMvFbTimeout3 = window.setTimeout( | |
function() { | |
// console.error("final call"); | |
for (var l = 0; l < document.getElementsByTagName("a").length; l++) { | |
if (document.getElementsByTagName("a")[l].className.indexOf("layerCancel") != -1) { | |
// console.error("final call as"); | |
document.getElementsByTagName("a")[l].style.backgroundColor = "orange"; | |
document.getElementsByTagName("a")[l].click(); | |
} | |
} | |
}, | |
2000); | |
oButtons[k].click(); | |
} | |
} | |
} | |
} | |
}, | |
7000); | |
if (oMvFbTimeout1 != null) { window.clearTimeout(oMvFbTimeout1); } | |
oMvFbTimeout1 = window.setTimeout(function () { deleteTimelinePosts() }, 12000); | |
oMenuItemLink.click(); | |
} | |
} | |
} | |
} | |
function addFacebookPostsDeleteButton() { | |
var oBody = document.getElementsByTagName("body")[0]; | |
var oInjectDiv = document.createElement("div"); | |
oInjectDiv.setAttribute("style", "position: absolute; top: 0; left: 0; background-color: rgba(50,150,30, 0.5); width: 190px; height: 50px; z-index: 333!important; "); | |
oInjectDiv.innerHTML = "<input id='MvDelButton' type='button' value='Delete Facebook Posts' />"; | |
oBody.insertBefore(oInjectDiv, oBody.childNodes[0]); | |
document.getElementById("MvDelButton").addEventListener("click", deleteTimelinePosts, false); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment