Участник:T kns/hideoldcomments.user.js — различия между версиями
Материал из Энциклопедия leprosorium.ru
T kns (обсуждение | вклад) (почему бы и нет?) |
T kns (обсуждение | вклад) м (ь) |
||
| Строка 4: | Строка 4: | ||
// @description Hides old comments in threads | // @description Hides old comments in threads | ||
// @include https://*.leprosorium.ru/comments/*/* | // @include https://*.leprosorium.ru/comments/*/* | ||
| − | // @version 0. | + | // @include https://leprosorium.ru/comments/*/* |
| + | // @version 0.4 | ||
// @grant none | // @grant none | ||
// ==/UserScript== | // ==/UserScript== | ||
| Строка 13: | Строка 14: | ||
unsafeWindow.console.log('[++Old comments]\n', args.join('\n'), '\n[--Old comments]') | unsafeWindow.console.log('[++Old comments]\n', args.join('\n'), '\n[--Old comments]') | ||
} | } | ||
| − | + | 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')) { | + | |
debug('wrong page') | debug('wrong page') | ||
return; | return; | ||
| Строка 21: | Строка 21: | ||
} | } | ||
window.addEventListener('DOMContentLoaded', function () { | window.addEventListener('DOMContentLoaded', function () { | ||
| − | var | + | var newcomms = document.querySelectorAll('div.comment.new'); |
| − | + | ||
if (!newcomms.length) { | if (!newcomms.length) { | ||
debug('no new comments') | debug('no new comments') | ||
Версия 08:17, 26 августа 2015
// ==UserScript==
// @name Hide old comments
// @namespace leprosorium+hideoldcomments
// @description Hides old comments in threads
// @include https://*.leprosorium.ru/comments/*/*
// @include https://leprosorium.ru/comments/*/*
// @version 0.4
// @grant none
// ==/UserScript==
(function () {
'use strict';
var debug = function () {
var args = Array.prototype.slice.call(arguments);
unsafeWindow.console.log('[++Old comments]\n', args.join('\n'), '\n[--Old comments]')
}
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 () {
var newcomms = document.querySelectorAll('div.comment.new');
if (!newcomms.length) {
debug('no new comments')
return;
}
var parentlinks = document.querySelectorAll('a.c_parent');
if (!parentlinks.length) {
debug('no parent links')
return;
}
var oldcomms = document.querySelectorAll('div.comment:not(.new)'),
hiddencomms = {
},
parentlinks = document.querySelectorAll('a.c_parent'),
hidecomm = function (el) {
debug('hide', el.id);
el.style.display = 'none';
hiddencomms[el.id] = el;
},
listenup = function (uplink) {
var gotoid = /#(\d+)$/.exec(uplink.href);
//debug('wut', uplink.href);
if (gotoid && gotoid.length) {
var parentid = gotoid[1];
//debug('↑', parentid);
uplink.addEventListener('click', function (ev) {
//debug('click', parentid);
if (parentid in hiddencomms && hiddencomms[parentid].style.display === 'none') {
debug('show', parentid);
hiddencomms[parentid].style.display = ''
}
}, false);
}
};
//debug('test')
for (var i = 0; i < oldcomms.length; i++) {
hidecomm(oldcomms[i]);
}
for (var j = 0; j < parentlinks.length; j++) {
listenup(parentlinks[j]);
}
}, false);
}) ()