Here's a user blocking script I wrote for voat chat.

2    12 Apr 2017 04:10 by u/EngelbertHumperdinck

Just copy and paste this script into your browser console. And please feel free to show me how I can improve my code.

var blockedUserList = [];
var blockedUserLinks = [];
/////////////////////////////////////////////////
function updateBlockList(){
  if (blockedUserList.length > 0) $('.blockListDisplay').css('display', 'inline');
  blockedUserLinks = [];
  $(blockedUserList).each(function(i){
    blockedUserLinks.push('<a href="javascript:void(0)" class="unblockUser" data-user="'+this+'">'+this+'</a>');
  })
  // show all users
  $('div.chat-message').show();
  // hide all blocked users
  $(blockedUserList).each(function(i){
    var blockee = '/user/'+ this;
    $('a[href="'+blockee+'"]').parents('div.chat-message').hide();
  });
  $('.blockListDisplay').html('Click to unblock: '+ blockedUserLinks.join(', ') );
}
/////////////////////////////////////////////////
// click block buttons
$('body').on('click', 'button.blockUser', function(){
  var theUser = $(this).parent('p').find('a').attr('href');
  var userName = theUser.split('/').pop();
  blockedUserList.push( userName );
  updateBlockList();
});
// click unblock buttons
$('body').on('click', '.unblockUser', function(e){
  e.preventDefault();
  // remove from list array
  blockedUserList.splice(blockedUserList.indexOf($(this).attr('data-user')), 1);
  // remove from links array
  blockedUserLinks.splice(blockedUserLinks.indexOf(this), 1);
  updateBlockList();
  if (blockedUserList.length <= 0) $('.blockListDisplay').css('display', 'none');
});
/////////////////////////////////////////////////
$('document').ready(function(){
  $('head').append('<style type="text/css"> button.blockUser { background-color: #303030; height: 16px; padding: 0 2px; } button.blockUser:hover { background-color: red; } .blockListDisplay { display: none; float: right; width: 90%; padding-top: 6px; } </style> ');
  var blockButton = '&nbsp; <button type="button" class="blockUser">block</button>';
  var numComments = $('.chat-message').length;
  var blockListDisplay = '<div class="blockListDisplay" >Click to unblock: </div>';
  // add initial block buttons
  $('.chat-message-head p').append(blockButton);
  // add area to display blocked users
  $('.sidecontentbox').append(blockListDisplay);
  // update display each time a new comment is added
  $('.chatContent').bind("DOMSubtreeModified",function(){
     // add block button to newly added comment
     if ($('.chat-message').length > numComments) {
       numComments = $('.chat-message').length;
       $('.chat-message:last').find('.chat-message-head p').append(blockButton);
       updateBlockList();
     } 
  });
});

2 comments

3

@PuttItOut, this means you can get rid of the chat restrictions!

edit: Also, thanks engel, you're a straight G.

0

You may as well hardcode Hecho and Sanegoatiswear.