Участник:T kns/hideoldcomments.user.js — различия между версиями
Материал из Энциклопедия leprosorium.ru
T kns (обсуждение | вклад) м (ь) |
T kns (обсуждение | вклад) м |
||
Строка 5: | Строка 5: | ||
// @include https://*.leprosorium.ru/comments/*/* | // @include https://*.leprosorium.ru/comments/*/* | ||
// @include https://leprosorium.ru/comments/*/* | // @include https://leprosorium.ru/comments/*/* | ||
− | // @version 0. | + | // @version 0.5 |
// @grant none | // @grant none | ||
// ==/UserScript== | // ==/UserScript== | ||
Строка 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]', args.join('\n'), '\n[--Old comments]') |
+ | //unsafeWindow.console.log('[++Old comments]', arguments, '\n[--Old comments]') | ||
+ | unsafeWindow.console.log('[++Old comments]'); | ||
+ | for (var i = 0; i < args.length; i++) { | ||
+ | unsafeWindow.console.log(args[i]); | ||
+ | } | ||
+ | unsafeWindow.console.log('[--Old comments]'); | ||
} | } | ||
+ | //debug(commentsHandler.showParent) | ||
+ | |||
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') | ||
Строка 50: | Строка 58: | ||
if (parentid in hiddencomms && hiddencomms[parentid].style.display === 'none') { | if (parentid in hiddencomms && hiddencomms[parentid].style.display === 'none') { | ||
debug('show', parentid); | debug('show', parentid); | ||
− | hiddencomms[parentid].style.display = '' | + | hiddencomms[parentid].style.display = ''; |
+ | var commid = uplink.parentNode.parentNode.parentNode.parentNode.getAttribute('data-parent_comment_id'), | ||
+ | scrolltimeout = setTimeout(function () { | ||
+ | clearTimeout(scrolltimeout) | ||
+ | //debug('click', commid); | ||
+ | //commentsHandler.showParent(parentid, commid); | ||
+ | document.getElementById(parentid).scrollIntoView(true); | ||
+ | }, 480) | ||
+ | //commentsHandler.showParent(parentid, ev.id) | ||
} | } | ||
− | }, | + | //document.getElementById(parentid).scrollIntoView(); |
+ | //return false; | ||
+ | |||
+ | }, true); | ||
} | } | ||
}; | }; |
Версия 13:15, 27 августа 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.5 // @grant none // ==/UserScript== (function () { 'use strict'; var debug = function () { var args = Array.prototype.slice.call(arguments); //unsafeWindow.console.log('[++Old comments]', args.join('\n'), '\n[--Old comments]') //unsafeWindow.console.log('[++Old comments]', arguments, '\n[--Old comments]') unsafeWindow.console.log('[++Old comments]'); for (var i = 0; i < args.length; i++) { unsafeWindow.console.log(args[i]); } unsafeWindow.console.log('[--Old comments]'); } //debug(commentsHandler.showParent) 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 = ''; var commid = uplink.parentNode.parentNode.parentNode.parentNode.getAttribute('data-parent_comment_id'), scrolltimeout = setTimeout(function () { clearTimeout(scrolltimeout) //debug('click', commid); //commentsHandler.showParent(parentid, commid); document.getElementById(parentid).scrollIntoView(true); }, 480) //commentsHandler.showParent(parentid, ev.id) } //document.getElementById(parentid).scrollIntoView(); //return false; }, true); } }; //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); }) ()