Участник:T kns/hideoldcomments.user.js — различия между версиями
Материал из Энциклопедия leprosorium.ru
T kns (обсуждение | вклад) м (это вообще с помощью цсс сделать можно) |
T kns (обсуждение | вклад) |
||
| Строка 2: | Строка 2: | ||
// @name Hide old comments | // @name Hide old comments | ||
// @namespace leprosorium+hideoldcomments | // @namespace leprosorium+hideoldcomments | ||
| − | // @description Hides old comments in threads | + | // @description Hides old comments in threads # see da [[Участник:T kns/hideoldcomments.user.css]] |
// @include https://*.leprosorium.ru/comments/*/* | // @include https://*.leprosorium.ru/comments/*/* | ||
// @include https://leprosorium.ru/comments/*/* | // @include https://leprosorium.ru/comments/*/* | ||
| Строка 12: | Строка 12: | ||
var debug = function () { | var debug = function () { | ||
var args = Array.prototype.slice.call(arguments); | var args = Array.prototype.slice.call(arguments); | ||
| − | |||
| − | |||
unsafeWindow.console.log('[++Old comments]'); | unsafeWindow.console.log('[++Old comments]'); | ||
for (var i = 0; i < args.length; i++) { | for (var i = 0; i < args.length; i++) { | ||
| Строка 20: | Строка 18: | ||
unsafeWindow.console.log('[--Old comments]'); | unsafeWindow.console.log('[--Old comments]'); | ||
} | } | ||
| − | + | debug('You better look at [[Участник:T kns/hideoldcomments.user.css]]') | |
if (!/^([a-z0-9]+\.)?leprosorium\.ru$/.test(location.host) || (location.search.indexOf('unread=on') === - 1 && location.hash !== '#new')) { | if (!/^([a-z0-9]+\.)?leprosorium\.ru$/.test(location.host) || (location.search.indexOf('unread=on') === - 1 && location.hash !== '#new')) { | ||
Текущая версия на 13:45, 28 августа 2015
// ==UserScript==
// @name Hide old comments
// @namespace leprosorium+hideoldcomments
// @description Hides old comments in threads # see da [[Участник:T kns/hideoldcomments.user.css]]
// @include https://*.leprosorium.ru/comments/*/*
// @include https://leprosorium.ru/comments/*/*
// @version 0.6
// @grant none
// ==/UserScript==
(function () {
'use strict';
var debug = function () {
var args = Array.prototype.slice.call(arguments);
unsafeWindow.console.log('[++Old comments]');
for (var i = 0; i < args.length; i++) {
unsafeWindow.console.log(args[i]);
}
unsafeWindow.console.log('[--Old comments]');
}
debug('You better look at [[Участник:T kns/hideoldcomments.user.css]]')
if (!/^([a-z0-9]+\.)?leprosorium\.ru$/.test(location.host) || (location.search.indexOf('unread=on') === - 1 && location.hash !== '#new')) {
debug('wrong page')
return;
} else {
debug('initialized')
}
window.addEventListener('DOMContentLoaded', function () {
try {
var newcomms = document.querySelectorAll('div.comment.new');
if (!newcomms.length) {
debug('no new comments')
return;
}
var oldcomms = document.querySelectorAll('div.comment:not(.new)');
if (!oldcomms.length) {
debug('no old comments')
return;
}
var addstyle = function () {
var style = document.createElement('style');
style.type = 'text/css';
style.innerHTML = '.oldcomment:not(.show) {display: none;}';
document.head.insertBefore(style, document.head.childNodes[0]);
},
hidecomm = function (el) {
debug('hide', el.id);
el.classList.add('oldcomment')
// hiddencomms[el.id] = el;
};
addstyle();
for (var i = 0; i < oldcomms.length; i++) {
hidecomm(oldcomms[i]);
}
} catch (er) {
unsafeWindow.console.error('~~ERROR: ' + er + ' (line ' + (er.lineNumber || '') + ')')
}
}, false);
}) ()