Skip to content

Instantly share code, notes, and snippets.

@Aryoam
Last active January 19, 2016 16:49
Show Gist options
  • Save Aryoam/307bece413b850243817 to your computer and use it in GitHub Desktop.
Save Aryoam/307bece413b850243817 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name BlockUsersShouts
// @version 0.3
// @description Oculta Shouts de Destacados
// @author AryoamGames and N3HL and Overjt
// @match http*://www.taringa.net/*
// @match http://www.taringa.net/*
// @grant none
// ==/UserScript==
//'use strict';
//test
(function() {
function getBlacklistedUsers() {
if (localStorage.BlacklistedUsers == undefined) {
localStorage.setItem('BlacklistedUsers', '[]');
return [];
}
var de = JSON.parse(localStorage.BlacklistedUsers);
return de;
}
function addUser(user) {
var de = JSON.parse(localStorage.BlacklistedUsers);
de.push(user);
localStorage.BlacklistedUsers = JSON.stringify(de);
}
function removeUser(user) {
var de = JSON.parse(localStorage.BlacklistedUsers);
var indx = de.indexOf(user);
if (indx > -1) {
de.splice(indx, 1);
localStorage.BlacklistedUsers = JSON.stringify(de);
}
}
var box = `<div class="box" id="blockedShouts">
<div class="title clearfix">
<h2>Bloquear cancer de Destacados</h2>
</div>
<div style="margin-top: 8px; width: 95%">
<input type="text" class="input" style="width: 100%;" id="userToBlock" autocomplete="off" placeholder="Escribe el nombre del cancerigeno">
<button class="btn r" style="width: 100%; margin-top: 5px;">Bloquear</button>
</div>
<div class="list">
</div>
</div>`;
var list_element = '<div class="list-element"><b>%username%</b><span style="cursor:pointer" class="value delUser" data-user="%username%">Desbloquear</span></div>';
$(".section-perfil #sidebar").prepend(box);
$("body").on("click", "#blockedShouts button", function(e) {
var userToBlock = $("#userToBlock").val();
if ($.inArray(userToBlock, getBlacklistedUsers()) == -1) {
addUser(userToBlock);
$("#blockedShouts > div.list").append(list_element.replace(/%username%/g, userToBlock));
}
});
$("body").on("click", ".delUser", function(e) {
removeUser($(this).data("user"));
$(this).closest("div.list-element").remove();
});
function main() {
var userlist = getBlacklistedUsers();
var $list = $("#blockedShouts div.list");
userlist.forEach(function(item) {
$list.append(list_element.replace(/%username%/g, item));
var selector = 'a.hovercard.shout-user_name[href="http://www.taringa.net/' + item + '"]';
var usuario = document.querySelectorAll(selector);
for (i = 0; i < usuario.length; i++) {
usuario[i].parentNode.parentNode.parentNode.parentNode.style.display = 'none';
}
for (j = 0; j < item.length; j++) {
(item[j]);
}
});
}
$(document).ready(function(e) {
main(); // se ejecuta la acción principal.
});
//Gracias Overjt
$(document).ajaxSuccess(function(event, jqXHR, settings) {
if (settings.url.indexOf('ajax/feed/fetch') > -1 || settings.url.indexOf('serv/more/trend') > -1) {
main();
}
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment