TwitchBlock Plus

Remove people/games from directories

  1. // ==UserScript==
  2. // @name TwitchBlock Plus
  3. // @description Remove people/games from directories
  4. // @namespace mothproof
  5. // @include http://www.twitch.tv/*
  6. // @version 1.1
  7. // @grant none
  8. // ==/UserScript==
  9.  
  10. if(typeof $ == 'undefined') var $ = unsafeWindow.jQuery;
  11.  
  12. $(function()
  13. {
  14. var
  15. people = [
  16. 'lirik',
  17. 'sodapoppin'
  18. ],
  19. games = [
  20. 'fifa',
  21. 'counter-strike',
  22. 'dota',
  23. 'hearth',
  24. 'gaming talk shows'
  25. ];
  26. var
  27. debug = false,
  28. $b = $('body'),
  29. wrapper,
  30. lastChannelCount,
  31. pplReg,
  32. gamesReg;
  33. if (games) {
  34. gamesReg = new RegExp(games.join('|').replace(/[-[\]{}()*+?.,\\^$#\s]/g, '\\$&'), 'i');
  35. }
  36. if (people) {
  37. pplReg = new RegExp(people.join('|').replace(/[-[\]{}()*+?.,\\^$#\s]/g, '\\$&'), 'i');
  38. }
  39. function log(msg) {
  40. if (!debug) {
  41. return;
  42. }
  43. console.log(msg);
  44. }
  45. var treeModifiedEvent = function (e)
  46. {
  47. $b.off('DOMSubtreeModified', treeModifiedEvent);
  48. switch (window.location.pathname) {
  49. case '/directory':
  50. wrapper = '.js-games';
  51. titleObject = 'a.game-item';
  52. break;
  53. default:
  54. case '/directory/all':
  55. titleObject = '.boxart';
  56. wrapper = '.js-streams';
  57. break;
  58. }
  59. var
  60. $w = $(wrapper),
  61. $channels = $w.find('> div > div');
  62. if ($channels.length != lastChannelCount)
  63. {
  64. $channels.each(function()
  65. {
  66. var
  67. $gameContainer = $(this),
  68. $title = $gameContainer.find(titleObject),
  69. $cap = $gameContainer.find('a.cap');
  70. if (gamesReg && gamesReg.test($title.attr('title'))) {
  71. log('removing game ' + $title.attr('title'));
  72. $gameContainer.css('display', 'none');
  73. }
  74. if (pplReg && pplReg.test($cap.attr('href'))) {
  75. log('removing person ' + $cap.attr('href'));
  76. $gameContainer.remove();
  77. }
  78. // in cases when there are few results, there might not be enough filler to scroll
  79. $('.tse-scroll-content').scroll();
  80. });
  81. lastChannelCount = $channels.length;
  82. }
  83.  
  84. setTimeout(function () {
  85. $b.on('DOMSubtreeModified', treeModifiedEvent);
  86. }, 1000);
  87. };
  88. $b.on('DOMSubtreeModified', treeModifiedEvent);
  89. });