Tabun CommentHider L

I Want my autohide back!

当前为 2015-10-19 提交的版本,查看 最新版本

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

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

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

您需要先安装一个扩展,例如 篡改猴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://табун.всепони.рф/*


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

// @version     0.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 comms = document.getElementsByClassName('comment');
for (var i = 0; i < comms.length; i++) {
  comms[i].getElementsByClassName('comment-info') [0].appendChild(createHideButton(comms[i].dataset.id));
  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('footer').innerHTML += ' :3'; //Просто признак того, что всё сработало