imojito / Hide Queets for Quitter

// ==UserScript==
// @name         Hide Queets for Quitter
// @namespace    http://imojito.com/quitter-tools-hide-queets-from-blocked-users.html
// @version      0.1
// @include     https://quitter.tld/*
// @include     https://gnusocial.tld/*
// @grant       GM_getValue
// @grant       GM_setValue
// ==/UserScript==

// Blocked users as full profile URL
// example ["https://quitter.es/aaaa", "http://quitter.no/bbbb"];
var blockedUsers = GM_getValue("blockedUsers", []);

//   $('.block-user').on("click", function (e) {
  $('body').on('click','.mute-user',function(e){
    e.preventDefault();
    var j = $(this).parents('.queet').find('a.account-group').attr('href');
    if ($(this).text() == "Disable mute") {
      removeBlock(j);
      console.log("Borrado de la lista de bloqueo");
      $(this).text('Mute this user');
    }
    else {
      $(this).text('Disable mute');
      console.log(j);

      if (j !== undefined) { // If element exists
      if (blockedUsers.indexOf(j) < 0) { // And was not added
      blockedUsers.push(j); // ADD Value TO AN ARRAY
      GM_setValue("blockedUsers", blockedUsers); // Save Array
      setTimeout(function(){
        hideQueet(1);
      }, 3500);
      }
    }
  }
});

//Eliminar de la lista de bloqueados
function removeBlock(userprofile) {
blockedUsers = jQuery.grep(blockedUsers, function(value) {
  return value != userprofile;
});
GM_setValue("blockedUsers", blockedUsers);
}

//Silenciar en menĂº y Mostrar desbloquear para usuarios ya bloqueados
$('body').on('click','.sm-ellipsis',function(){
  var j = $(this).parents('.queet').find('a.account-group').attr('href');
  blockHtml = '<li><a class="mute-user">Mute this user</a></li>';
  var theta = $(this).parents('.queet-actions').find('.action-ellipsis-container').find('ul.dropdown-menu').append(blockHtml);
    if (blockedUsers.indexOf(j) > 0) { //if user on index
          theta.find('a.mute-user').text("Disable mute");
    }
});

//Elemento de menĂº para borrar todos los silenciamientos
$('body').on('click','.nav-session',function(){
  if ($(this).parents('.topbar').find('a#purge-silenced-users').length < 1) {
  blockHtml = '</li><li class="fullwidth language dropdown-divider"></li><li class="fullwidth"><a id="purge-silenced-users">Clear mute list</a>';
  $(this).parents('.topbar').find('a#classic-link').after(blockHtml);
  }
});

//Restablecer lista de usuarios silenciados
$('body').on('click','a#purge-silenced-users',function(){
  console.log("Borrando lista de usuarios silenciados");
  blockedUsers = [];
  GM_setValue("blockedUsers", blockedUsers);
  //saveSilencedUsers();
});


function hideQueet(full) {
  blockedUsers.forEach(function(profileurl) {
  //limits and animation, if ( NOT on top )
  if (full) {
    $('div#feed-body a.account-group[href="' + profileurl + '"]').parentsUntil( "#feed-body" ).hide(600);
    console.log("borrado queets COMPLETO ejecutado");
  } else {
    if ($(window).scrollTop()){
      $('div#feed-body a.account-group:gt(-20)[href="' + profileurl + '"]').parentsUntil( "#feed-body" ).hide();  
    } else {
      $('div#feed-body a.account-group:lt(20)[href="' + profileurl + '"]').parentsUntil( "#feed-body" ).hide(600);
    }
  }
});
  console.log("borrado queets ejecutado");
}

//** Fire hideQueet **//
// Fire on load
setTimeout(function(){
  hideQueet();
}, 2500);


// Fire when loading new queets
//* it seems to fail sooner than later whith
//* $( "#new-queets-bar" ).click(function() {
$('body').on('click','#new-queets-bar',function(){
hideQueet();
  console.log( "Handler for .click() called." );
});

// Fire when switching stream
$( ".stream-selection" ).click(function() {
  setTimeout(function(){
    hideQueet();
  }, 1500);
});

$( "#logo" ).click(function() {
  setTimeout(function(){
    hideQueet();
  }, 1500);
});

$( ".reload-stream" ).click(function() {
  setTimeout(function(){
    hideQueet();
  }, 1500);
});

// Fire when requesting more queets at bottom
$(window).scroll(function() {
  if($(window).scrollTop() + $(window).height() > $(document).height() - 1000) {
    setTimeout(function(){
      hideQueet();
  }, 1500); }
});