Review Queue Hider

Hide and show individual queues from the Review page

  1. // ==UserScript==
  2. // @name Review Queue Hider
  3. // @description Hide and show individual queues from the Review page
  4. // @namespace http://stackoverflow.com/users/1563422/danny-beckett
  5. // @version 1.1
  6. // @grant
  7. // @include http://*.stackexchange.com/review*
  8. // @include http://answers.onstartups.com/review*
  9. // @include http://askubuntu.com/review*
  10. // @include http://meta.askubuntu.com/review*
  11. // @include http://meta.serverfault.com/review*
  12. // @include http://meta.stackoverflow.com/review*
  13. // @include http://serverfault.com/review*
  14. // @include http://stackapps.com/review*
  15. // @include http://stackoverflow.com/review*
  16. // @include http://superuser.com/review*
  17. // ==/UserScript==
  18.  
  19. // Images courtesy of fatcow.com/free-icons
  20. var toMove = [];
  21. var queues = document.getElementsByClassName('dashboard-item');
  22. var hide = 'iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAllJREFUeNqMU0toU1EQPfd9k4qF+mkg0lREUWqEWtQuWqOl2rpQ3HXjTl0IdlHowrVLF4ILCy7EjTs3KgrSoLaJdVGVCDVEix9sJNXGxmhsk5f3u9556bPRCHZguMzMOefN3HmX4S9L9HSMccc9zTkP+DnGmMFk6cahp5nz9ViBAfODZG90wLGs8bbD/Wjt2getpQVelQNmsYh86gU+TT6CrKqDsal0/A+B5MHoAJPk8ejZcwgEdZSnk7CzH2Dn56G0hqFEtqGpOwajUkX6+jVw1xmMPUnHfwtMdO/ke0dGIS/kUH54D65jgcky/Ba440CSVTQdOQEntAUvr1xG3/QsIwEp0bN7LHL0GNRCHuX4bRoYshaApGjCVe+kmPJUJxzhiUcfl1zXPRPq7ILx+D5kVyhWDbDKMlh5adVFTHmqE47wxCMBRUjrSj4Hs1rBhgcz+J8Vj3eC8MTzOoDEwLPvIUkK1mKEIzzxagJiNvbjO+TgujUJEI7wxPNG4IyZtmVpyvpmLJ/qB2ybFtzIJIKigHACD+J5AoumfS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kUBccEfkYNZOKYW3iIqxSb3zvK/Rce4LXSidE+t4DDbjTq5I7nClXm7aQZPEXHv1veAq2BwXGcPDSM2xY7jtelYrdaQGAjiNnV9/jEwfs+ptriMfGQOf8SMEsWIcvvfY27AgwA3EwHS5LUr7EAAAAASUVORK5CYII=';
  24.  
  25. // Checks whether a toggle state is saved for a queue
  26. function exists(queue)
  27. {
  28. return document.cookie.indexOf('rqh_' + location.host + '_' + queue + '=') >= 0;
  29. }
  30.  
  31. // Gets a queue's toggle state
  32. function get(queue)
  33. {
  34. for(var i = 0; pair = document.cookie.split('; ')[i].split('='); i++)
  35. if(pair[0] == 'rqh_' + location.host + '_' + queue)
  36. return unescape(pair[1]) === '1';
  37. return false;
  38. }
  39.  
  40. // Sets a queue's toggle state
  41. function set(queue, shown)
  42. {
  43. document.cookie = 'rqh_' + location.host + '_' + queue + '=' + shown;
  44. }
  45.  
  46. // Toggles a queue's toggle state & button
  47. function toggle(box)
  48. {
  49. var state = get(box.queue);
  50.  
  51. box.firstChild.src = 'data:image/png;base64,' + (state ? show : hide);
  52. box.parentNode.style.opacity = state ? '0.3' : '1.0';
  53.  
  54. if(state)
  55. document.getElementById('mainbar').appendChild(box.parentNode);
  56. else
  57. document.getElementById('mainbar').insertBefore(box.parentNode, document.getElementById('mainbar').children[1]);
  58.  
  59. set(box.queue, state ? '0' : '1');
  60. fixTops();
  61. }
  62.  
  63. function fixTops()
  64. {
  65. for(var i = 0; i < queues.length; i++)
  66. {
  67. // Ignore queues with insufficient rep
  68. if(typeof queues[i].getElementsByClassName('dashboard-title')[0].getElementsByTagName('a')[0] == 'undefined')
  69. continue;
  70.  
  71. queues[i].lastChild.style.top = '-' + (queues[i].clientHeight - 10 + (i == 0 ? 15 : 0)) + 'px';
  72. }
  73. }
  74.  
  75. // Add a toolbox to each queue
  76. for(var i = 0; i < queues.length; i++)
  77. {
  78. // Ignore queues with insufficient rep
  79. if(typeof queues[i].getElementsByClassName('dashboard-title')[0].getElementsByTagName('a')[0] == 'undefined')
  80. continue;
  81.  
  82. var queue = queues[i].getElementsByClassName('dashboard-title')[0].getElementsByTagName('a')[0].getAttribute('href').split('/').slice(-1)[0];
  83. if(!exists(queue))
  84. set(queue, 1);
  85.  
  86. var box = document.createElement('div');
  87. box.innerHTML = '<img src="data:image/png;base64,' + (get(queue) ? hide : show) + '" height="16" width="16">';
  88. box.onclick = function(){ toggle(this); };
  89. box.queue = queue;
  90. box.style.border = '1px dotted #999';
  91. box.style.borderTopStyle = 'none';
  92. box.style.cursor = 'pointer';
  93. box.style.float = 'right';
  94. box.style.padding = '5px';
  95. box.style.position = 'relative';
  96. queues[i].appendChild(box);
  97.  
  98. if(!get(queue))
  99. {
  100. queues[i].style.opacity = '0.3';
  101. toMove.push(i);
  102. }
  103. }
  104.  
  105. // Move the hidden queues to the bottom - this is done separately from the for() above so
  106. // that [i] is preserved (i.e. so queues aren't being moved around, and [i]'s position changes)
  107. for(var i = toMove.length - 1; i >= 0; --i)
  108. document.getElementById('mainbar').appendChild(queues[toMove[i]]);
  109.  
  110. fixTops();