- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
// ==UserScript==
// @name GK parent comment
// @namespace GK
// @description Adds links to parent commentary to GK comments, and sets parent commentary text as link tooltip.
// @include http://govnokod.ru/*
// @include http://www.govnokod.ru/*
// @version 1.0.0
// @updateURL http://userscripts.org/scripts/source/172756.meta.js
// @downloadURL http://userscripts.org/scripts/source/172756.user.js
// ==/UserScript==
(function(){
//hack for Chrome, as it doesn't support unsafeWindow.
if (typeof unsafeWindow == 'undefined')
{
unsafeWindow = (function()
{
var el = document.createElement('p');
el.setAttribute('onclick', 'return window;');
return el.onclick();
}())
};
$ = unsafeWindow.jQuery;
//dirty, DIRTY hack to wait for certain element to appear. -_-
//But I have no idea how to do it right.
function waitForSelector(selector, context, mustexist, callback) {
var l = $(selector, context).length;
if ((l>0) != mustexist)
{
setTimeout(function(){waitForSelector(selector, context, mustexist, callback)}, 50);
return false;
};
callback();
}
//short function for adding custom CSS rules. Why use Greasemonkey specific GM_setStyle() just for that?
function addCSS(rule) {
var styleElement = document.createElement("style");
styleElement.type = "text/css";
if (typeof styleElement.styleSheet !== 'undefined')
styleElement.styleSheet.cssText = rule;
else
styleElement.appendChild(document.createTextNode(rule));
document.getElementsByTagName("head")[0].appendChild(styleElement);
}
addCSS([
'.comment-parent-link {margin-left:10px;font-size:10pt}',
].join('/n'));
var PARENT = '<a class="comment-link comment-parent-link" href="">↑</a>';
var oldLoadComments = unsafeWindow.comments['load'];
function newLoadComments(aElemTrigger) {
var $parent = $(aElemTrigger).closest('.entry-comments');
oldLoadComments.call(this,aElemTrigger);
waitForSelector('.hcomment', $parent, true, function(){
setParentLinks($parent);
});
}
unsafeWindow.comments['load'] = newLoadComments;
function setParentLinks($context) {
$context.find('.hcomment').each(function(i,e){
var $this = $(this);
var $parent = $this.parents('.hcomment:eq(0)');
if ($parent.length) {
var $parentlink = $(PARENT);
$parentlink.attr('href', $parent.find('a.comment-link:eq(0)').attr('href'));
$parentlink.attr('title', $parent.find('.comment-text:eq(0)').text());
$this.find('a.comment-link:eq(0)').after($parentlink);
}
});
}
setParentLinks($('body'));
})();