CubecraftHideLockedThreads

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

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

// ==UserScript==
// @name        CubecraftHideLockedThreads
// @namespace   de.rasmusantons
// @description Adds an option to hide locked threads on the cubecraft forums.
// @include     https://www.cubecraft.net/forums/*
// @version     1
// @grant       none
// ==/UserScript==

function updateThreadList(hideLocked) {
  var count = 0;
  var threads = $('.discussionListItem');
  threads.each(function(i, e) {
    var thread = $(e);
    if (!thread.hasClass('locked'))
      return;
    ++count;
    thread.css('display', hideLocked ? 'none' : '');
  });
  $('.discussionListItems > br').css('display', (hideLocked && $('li.sticky:not(.locked)').length == 0) ? 'none' : '');
  cnt.text(hideLocked ? '(' + count + ' locked threads hidden)' : '');
}

function onCbChange() {
  localStorage.setItem('hideLocked', this.checked);
  updateThreadList(this.checked);
}

var cb = $('<input type="checkbox" />');
var cnt = $('<span></span>');
cnt.css('margin-left', '5px');
cb.get(0).checked = (localStorage.getItem('hideLocked') == "true");
updateThreadList(cb.get(0).checked);
cb.change(onCbChange);
$($('.secondaryContent > .col2')[0]).append($('<li></li>').append($('<a></a>').append($('<label>hide locked threads</label>').prepend(cb))));
$($('.sectionFooter')[0]).append(cnt);