- 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
- 81
- 82
- 83
- 84
- 85
- 86
- 87
- 88
- 89
- 90
- 91
- 92
- 93
- 94
// ==UserScript==
// @name govnokod.ru.user.js
// @description highlight for new comments
// @author [email protected]
// @include http://govnokod.ru/*
// ==/UserScript==
if(!jQuery.cookie)
jQuery.cookie = function(name, value, options) {
if (typeof value != 'undefined') { // name and value given, set cookie
options = options || {};
if (value === null) {
value = '';
options.expires = -1;
}
var expires = '';
if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
var date;
if (typeof options.expires == 'number') {
date = new Date();
date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
} else {
date = options.expires;
}
expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
}
var path = options.path ? '; path=' + (options.path) : '';
var domain = options.domain ? '; domain=' + (options.domain) : '';
var secure = options.secure ? '; secure' : '';
document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
} else { // only name given, get cookie
var cookieValue = null;
if (document.cookie && document.cookie != '') {
var cookies = document.cookie.split(';');
for (var i = 0; i < cookies.length; i++) {
var cookie = jQuery.trim(cookies[i]);
// Does this cookie string begin with the name we want?
if (cookie.substring(0, name.length + 1) == (name + '=')) {
cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
break;
}
}
}
return cookieValue;
}
};
var there_href = document.location.href.match(/govnokod\.ru\/(\d+)/);
if ( there_href ) // in topic
$(document).ready(function() {
var govnokod_n = there_href[1];
var cookiename = 'gk'+govnokod_n
var lastvisit = new Date(parseInt($.cookie(cookiename)));
var now = new Date();
var comments = $(".hcomment abbr").filter(function(index,elem) {
var date=new Date(elem.title.replace("T"," ").replace(/\+(\d\d):(\d\d)$/," GMT+$1$2"));
return date>lastvisit;
});
for (var i=0;i<comments.length;i++)
{
var elem = comments[i];
var header = elem.parentElement;
var block = elem.parentElement.parentElement;
block.style.background = '#FACE8D';
var anchor = document.createElement("a");
anchor.setAttribute('name','new_'+i);
block.insertBefore(anchor,block.firstChild);
var prevlink = document.createElement("a");
if (i!=0)
prevlink.setAttribute('href','#new_'+(i-1));
prevlink.appendChild(document.createTextNode('⟵'));
header.insertBefore(prevlink,elem.nextSibiling);
header.insertBefore(document.createTextNode(' '),elem.nextSibiling);
var nextlink = document.createElement("a");
if (i!=comments.length-1)
nextlink.setAttribute('href','#new_'+(i+1));
nextlink.appendChild(document.createTextNode('⟶'));
header.insertBefore(nextlink,elem.nextSibiling);
}
var new_comments_count = document.createElement("a");
if (comments.length)
new_comments_count.setAttribute('href','#new_0');
new_comments_count.appendChild(document.createTextNode(''+comments.length+' новых'));
var comments_count = $(".enrty-comments-count");
comments_count.text(comments_count.text().replace(/\)$/,', '));
comments_count.append(new_comments_count);
comments_count.append(')');
$.cookie(cookiename, now.valueOf(), { 'expires': 3 }); //помним, что имеется ограничение на размер куков.
});
Наговнокодил подсвечивалку новых комментариев для говногод.ру. Смесь из обычного DOM и тутошнего jQuery. Сохранить как govnokod.ru.user.js. Тестировал только в опере.