Advertisement
Guest User

Absterge (mirror)

a guest
Jun 7th, 2014
11,858
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name           Absterge
  3. // @namespace      http://userscripts.org/users/astojanov
  4. // @include        http://*.facebook.com/*
  5. // @include        https://*.facebook.com/*
  6. // @require        http://code.jquery.com/jquery-1.7.1.min.js
  7. // ==/UserScript==
  8.  
  9. function parseUri (str) {
  10.     var o = parseUri.options,
  11.     m   = o.parser[o.strictMode ? "strict" : "loose"].exec(str),
  12.     uri = {},
  13.     i   = 14;
  14.     while (i--) uri[o.key[i]] = m[i] || "";
  15.     uri[o.q.name] = {};
  16.     uri[o.key[12]].replace(o.q.parser, function ($0, $1, $2) {
  17.         if ($1) uri[o.q.name][$1] = $2;
  18.     });
  19.     return uri;
  20. };
  21.  
  22. parseUri.options = {
  23.         strictMode: false,
  24.         key: ["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"],
  25.         q:   {
  26.             name:   "queryKey",
  27.             parser: /(?:^|&)([^&=]*)=?([^&]*)/g
  28.         },
  29.         parser: {
  30.             strict: /^(?:([^:\/?#]+):)?(?:\/\/((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?))?((((?:[^?#\/]*\/)*)([^?#]*))(?:\?([^#]*))?(?:#(.*))?)/,
  31.             loose:  /^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/
  32.         }
  33. };
  34.  
  35. window.addEventListener('load', function()  {
  36.  
  37.     var fb_dtsg = null;
  38.     var abstergeProcessingTimeout = 2000;
  39.  
  40.     // Unfriend as an action as well ?
  41.     var deleteActions = ["Unfriend", "Delete", "Report/Remove Tag", "Delete Photo", "Unlike"];
  42.  
  43.     // Verify the delete action
  44.     var isDeleteAction = function (actionType) {
  45.         return (deleteActions.indexOf(actionType) >= 0);
  46.     }
  47.    
  48.     // Get the value of fb_dtsg
  49.     var getConstantParameters = function () {
  50.         if ( fb_dtsg !== null ) {
  51.             return true;
  52.         } else {
  53.  
  54.             if ( fb_dtsg === null ) {
  55.                 $('input[name="fb_dtsg"]').each(function(){
  56.                     fb_dtsg = $(this).attr("value");
  57.                 });
  58.             }
  59.             return (fb_dtsg !== null);
  60.         }
  61.     }
  62.  
  63.     // Mimic physical mouse click event (testing only)
  64.     var physicalClick = function (obj) {
  65.         var x = obj.offset().left + ( obj.width () / 2 );  
  66.         var y = obj.offset().top  + ( obj.height() / 2 );  
  67.         $(document.elementFromPoint(x, y)).click();
  68.     }
  69.  
  70.     // Delete any ministory passed to this function
  71.     var processMinistory = function (ministory, actionObj) {
  72.         var ajaxify = parseUri("http://facebook.com" + actionObj.attr("ajaxify"));
  73.         if ( ajaxify.file === "take_action_on_story.php" ) {
  74.             var data = {
  75.                     'fb_dtsg'  : fb_dtsg,
  76.                     'confirmed': "true",
  77.                     'ban_user' : "0"
  78.             };
  79.             for ( var key in ajaxify.queryKey ) {
  80.                 data[key] = ajaxify.queryKey[key];
  81.             }
  82.             $.ajax({
  83.                 type    : "POST",
  84.                 url     : "https://www.facebook.com/ajax/timeline/take_action_on_story.php",
  85.                 data    : data,
  86.                 complete: function(jqXHR, textStatus) {
  87.                     if ( jqXHR.status === 200 ) {
  88.                         if ( $('#cmdAbsterge').attr('deletecount') === undefined || $('#cmdAbsterge').attr('deletecount') === null ) {
  89.                             $('#cmdAbsterge').attr('deletecount', '0');
  90.                         }
  91.                         var deleteCount = parseInt($('#cmdAbsterge').attr('deletecount')) + 1;
  92.                         $('#cmdAbsterge').html("Absterge (" + deleteCount + ")");
  93.                         $('#cmdAbsterge').attr('deletecount', '' + deleteCount);
  94.                         ministory.remove();
  95.                     }
  96.                     console.log("Deleting:", jqXHR);
  97.                 }
  98.             });
  99.         }
  100.     }
  101.  
  102.  
  103.     var onAbstergeClick = function () {
  104.         getConstantParameters ();
  105.         console.log("Absterge is starting ...");
  106.         $("div > div > div > div.fbTimelineSection > div > div > div > div > ul > li").each(function() {
  107.             var ministory = $(this);
  108.             ministory.find('a').each(function(){
  109.                 if ( $(this).attr("aria-label") === "Allowed on Timeline" ) {
  110.                     var editButton = $(this);
  111.                     editButton.mousemove();
  112.                     editButton.find('i').click();
  113.                     setTimeout ( function() { editButton.parent().find('a[ajaxify]').each (function() {
  114.                         if ( isDeleteAction($(this).text()) ) {
  115.                             // console.log(ministory, $(this).text());
  116.                             processMinistory (ministory, $(this));
  117.                         }
  118.                     })}, abstergeProcessingTimeout);
  119.                 }
  120.             });
  121.         });
  122.         $("html, body").animate({ scrollTop: $(document).height() }, "slow");
  123.         console.log("Absterge done ...: ", fb_dtsg);
  124.         setTimeout(onAbstergeClick, 3000);
  125.     };
  126.  
  127.  
  128.     // Include the
  129.     $('<li id="navAbsterge" class="navItem middleItem"><a id="cmdAbsterge" class="navLink bigPadding" href="#">Absterge</a></li>').insertAfter('#navHome');
  130.     var pathname = window.location.pathname;    
  131.     if ( pathname.indexOf('/allactivity') === -1 ) {
  132.         $('#cmdAbsterge').click(function () {
  133.             alert('You must navigate to "Activity Log" using the "Timeline" feature in order to use Absterge');          
  134.         });
  135.     } else {
  136.         $('#cmdAbsterge').css("color", "#FAFAD2");
  137.         $('#cmdAbsterge').click(function () {
  138.             onAbstergeClick();
  139.         });
  140.     }
  141. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement