CubecraftHideLockedThreads

Adds an option to hide locked threads on the cubecraft forums.

当前为 2016-08-15 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name CubecraftHideLockedThreads
  3. // @namespace de.rasmusantons
  4. // @description Adds an option to hide locked threads on the cubecraft forums.
  5. // @include https://www.cubecraft.net/forums/*
  6. // @version 1
  7. // @grant none
  8. // ==/UserScript==
  9.  
  10. function updateThreadList(hideLocked) {
  11. var count = 0;
  12. var threads = $('.discussionListItem');
  13. threads.each(function(i, e) {
  14. var thread = $(e);
  15. if (!thread.hasClass('locked'))
  16. return;
  17. ++count;
  18. thread.css('display', hideLocked ? 'none' : '');
  19. });
  20. $('.discussionListItems > br').css('display', (hideLocked && $('li.sticky:not(.locked)').length == 0) ? 'none' : '');
  21. cnt.text(hideLocked ? '(' + count + ' locked threads hidden)' : '');
  22. }
  23.  
  24. function onCbChange() {
  25. localStorage.setItem('hideLocked', this.checked);
  26. updateThreadList(this.checked);
  27. }
  28.  
  29. var cb = $('<input type="checkbox" />');
  30. var cnt = $('<span></span>');
  31. cnt.css('margin-left', '5px');
  32. cb.get(0).checked = (localStorage.getItem('hideLocked') == "true");
  33. updateThreadList(cb.get(0).checked);
  34. cb.change(onCbChange);
  35. $($('.secondaryContent > .col2')[0]).append($('<li></li>').append($('<a></a>').append($('<label>hide locked threads</label>').prepend(cb))));
  36. $($('.sectionFooter')[0]).append(cnt);