Facebook Posts Deleter 2016 – User JavaScript for Opera 12.x and Firefox

Clean out your Facebook activity log with Facebook Posts Deleter 2016!

There is a Greasemonkey script called Facebook Timeline Cleaner, which has not been updated and does not work anymore. So, I created my own User JS for Opera and later adapted it for Firefox. I am not wholly satisfied with this script as it uses recursion. But, it does work. See this video. It is extremely gratifying to see Facebook posts get deleted mercilessly.

// ==UserScript==
// @name        Facebook Posts Deleter
// @namespace   com.vsubhash.js.facebook.posts.deleter
// @description Deletes all facebook posts
// @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].getAttribute("action") == "cancel") &&
                                (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);  
}) != -1) {
                var oButtons = oForms[j].getElementsByTagName(

This source is also available at: https://gist.github.com/vsubhash/

[This post was updated in 2016]

Advertisements
This entry was posted in news and tagged , , , , . Bookmark the permalink.