Tabun CommentHider L

I Want my autohide back!

当前为 2015-11-18 提交的版本,查看 最新版本

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name        Tabun CommentHider L
// @author      Йетанозер
// @namespace   localhaust
// @description I Want my autohide back!

// @include  http://tabun.everypony.ru/*
// @include  http://tabun.everypony.info/*
// @include  http://табун.всепони.рф/*

// @include  https://tabun.everypony.ru/*
// @include  https://tabun.everypony.info/*
// @include  https://табун.всепони.рф/*

//@downloadURL	https://greasyfork.org/scripts/13203-tabun-commenthider-l/code/Tabun%20CommentHider%20L.user.js
//@updateURL	https://greasyfork.org/scripts/13203-tabun-commenthider-l/code/Tabun%20CommentHider%20L.user.js

// @grant    GM_setValue
// @grant    GM_deleteValue
// @grant    GM_getValue

// @version     0.3.1

// ==/UserScript==
function unhideComment(commentid) {
  var comm = document.getElementById('comment_content_id_' + commentid);
  comm.getElementsByClassName('text') [0].style.display = 'block';
  comm.removeChild(comm.lastChild);
  document.getElementById('hide_' + commentid).style.display = 'block';
  GM_deleteValue(commentid);
}

function createUnhideButton(commentid) {
  var newLink = document.createElement('a');
  newLink.href = '#';
  newLink.title = 'UNHIDE THIS FOR CELESTIA\'S SAKE';
  newLink.innerHTML = 'Комментарий скрыт. Показать?';
  newLink.id = 'unhide_' + commentid;
  newLink.onclick = function (event) {
    event.preventDefault();
    unhideComment(commentid);
  };
  return newLink;
}

function hideComment(commentid) {
  var comm = document.getElementById('comment_content_id_' + commentid);
  comm.getElementsByClassName('text') [0].style.display = 'none';
  comm.appendChild(createUnhideButton(commentid));
  document.getElementById('hide_' + commentid).style.display = 'none';
  GM_setValue(commentid, true);
}

function createHideButton(commentid) {
  var newButt = document.createElement('li');
  var newLink = document.createElement('a');
  newLink.href = '#';
  newLink.title = 'HIDE THIS FOR CELESTIA\'S SAKE';
  newLink.innerHTML = 'Скрыть';
  newLink.id = 'hide_' + commentid;
  newLink.onclick = function (event) {
    event.preventDefault();
    hideComment(commentid);
  };
  newButt.appendChild(newLink);
  return newButt;
}

var GlobTimePassed = 0;

function updateNewComms() {
  if (GlobTimePassed > 8000){
    GlobTimePassed = 0;
    return;
  }
  if (document.getElementById('new_comments_counter').innerHTML === '0') {
    GlobTimePassed+=50;
    setTimeout(updateNewComms, 50);
    return;
  }
  GlobTimePassed = 0;
  var comms = document.querySelectorAll('.comment:not(.comment-deleted):not(.hdr-processed)');
  for (var i = 0; i < comms.length; i++) {
    comms[i].getElementsByClassName('comment-info') [0].appendChild(createHideButton(comms[i].dataset.id));
    comms[i].classList.add('hdr-processed');
    if (parseInt((/-?\d+/).exec(comms[i].getElementsByClassName('vote-count') [0].innerHTML) [0], 10) < - 5) {
      hideComment(comms[i].dataset.id);
    }
  }
}

var comms = document.querySelectorAll('.comment:not(.comment-deleted)');
for (var i = 0; i < comms.length; i++) {
  comms[i].getElementsByClassName('comment-info') [0].appendChild(createHideButton(comms[i].dataset.id));
  comms[i].classList.add('hdr-processed');
  if (GM_getValue(comms[i].dataset.id) === true) {
    hideComment(comms[i].dataset.id);
    continue;
  }
  if (parseInt((/-?\d+/).exec(comms[i].getElementsByClassName('vote-count') [0].innerHTML) [0], 10) < - 5) {
    hideComment(comms[i].dataset.id);
  }
}

document.getElementById('update-comments').addEventListener('click', function (event) {
  updateNewComms();
}, false)
document.getElementById('footer').innerHTML += ' :3'; //Просто признак того, что всё сработало