// ==UserScript==
// @include http://www.linux.org.ru/*
// ==/UserScript==
function addJQuery(callback) {
var script = document.createElement("script");
script.setAttribute("src", "http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js");
script.addEventListener('load', function() {
var script = document.createElement("script");
script.textContent = "(" + callback.toString() + ")();";
document.body.appendChild(script);
}, false);
document.body.appendChild(script);
}
function main() {
var t1 = '<br /><object style="height: 210px; width: 320px"><param name="movie" value="';
var t2 = '?version=3&feature=player_detailpage"><param name="allowFullScreen" value="true"><param name="allowScriptAccess" value="always"><embed src="';
var t3 = '?version=3&feature=player_detailpage" type="application/x-shockwave-flash" allowfullscreen="true" allowScriptAccess="always" width="320" height="180"></object><br />';
$.each($("a[href^='http://youtu.be']"), function(i, v){ $(v).replaceWith(t1 + v.href.replace("http://youtu.be/", "http://www.youtube.com/v/") + t2 + v.href.replace("http://youtu.be/", "http://www.youtube.com/v/") + t3); });
function add_answers(parent_post, post){
if($("div.title:contains('Ответ на') a[href$='" + $(parent_post).attr("id").replace("preview_", "") + "']", $(post)).length){
var a = "<a href='" + $(post).find(".title a:contains('#')").attr("href") + "'>" + ($(post).find(".sign a").html() ? $(post).find(".sign a").html() : "anonymous") + "</a>";
if($(".answers", parent_post).length){
$($(".answers", parent_post)[0]).html($($(".answers", parent_post)[0]).html() + ", " + a);
}
else{
$("<div />", {
"class" : "answers"
, "html": "Ответы: " + a
}).insertAfter($("p:last", $(parent_post)));
}
}
}
function add_parent_post(link, zi, pt, pl){
var timer;
link.mouseover(function(e){
var id = (e.target.hash ? e.target.hash.replace("#", "") : "comment-" + link.attr("href").match(RegExp("[?|&]cid=(.+?)(&|$)"))[0].split("=")[1]);
if($("#preview_" + id).length){
clearTimeout(timer);
return;
}
$.get(link.attr("href"), function(data){
$("<article />", {
'id': 'preview_' + id,
'html': $("#" + id, $(data)).html(),
'class': "target msg highLighted",
'style': "position: absolute; z-index: " + zi + "; top: " + (pt + e.target["offsetTop"] + e.target.offsetHeight) + "px; left: " + (l = pl + e.target["offsetLeft"] + e.target.offsetWidth/2) + "px;",
'mouseover': function(){ clearTimeout(timer); },
'mouseout': function(){
timer = setTimeout(
function(){
$("#preview_" + id).remove();
}
, 800
);
}
}).appendTo(".messages");
$.each(posts, function(p){
add_answers($("#preview_" + id), $(posts[p]));
});
$.each($("a:not([href^='/people/']):not([href^='add_comment.jsp']):not([href^='http']):not(:eq(0))", $("#preview_" + id)), function(){
add_parent_post($(this), zi + 1, (pt + e.target["offsetTop"] + e.target.offsetHeight), (l = pl + e.target["offsetLeft"] + e.target.offsetWidth/2));
});
});
});
link.mouseout( function(e){
var id = (e.target.hash ? e.target.hash.replace("#", "") : "comment-" + link.attr("href").match(RegExp("[?|&]cid=(.+?)(&|$)"))[0].split("=")[1]);
timer = setTimeout(
function(){
$("#preview_" + id).remove();
}
, 800
);
});
}
//var cur_page = window.location.href.match(/page\d+/) ? window.location.href.match(/page\d+/)[0].replace("page", "") : 0;
var pages = $("a.page-number:not(:contains('←')):not(:contains('→'))").slice(/*cur_page*/ 0, $("a.page-number:not(:contains('←')):not(:contains('→'))").length/2);
var posts_sel = ".msg:not([id*='topic'])";
var posts = $(posts_sel);
var l = pages.length;
var c = 0;
$.each(pages, function(pagei, pagev){
$.get($(pagev).attr("href"), function(data){
posts = $.merge(posts, $(posts_sel, $(data)));
c++;
});
});
(function t1(){
setTimeout(function(){
if(c == l){
var ll = $(posts_sel).length;
var cc = 0;
$.each($(posts_sel), function(ppi, ppv){
$.each(posts, function(pi, pv){
add_answers(ppv, pv);
});
cc++;
});
(function t2(){
setTimeout(function(){
if(cc == ll){
$.each($(posts_sel), function(pi, pv){
$.each($("a:not([href^='/people/']):not([href^='add_comment.jsp']):not([href^='http']):not(:eq(0))", $(pv)), function(li, lv){
add_parent_post($(lv), 300, 0, 0);
});
});
}
else{
t2();
}
}, 100);
})();
}
else{
t1();
}
}, 100);
})();
}
addJQuery(main);