Advertisement
Guest User

Untitled

a guest
Aug 20th, 2012
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @include http://www.linux.org.ru/*
  3. // ==/UserScript==
  4.  
  5. function addJQuery(callback) {
  6.   var script = document.createElement("script");
  7.   script.setAttribute("src", "http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js");
  8.   script.addEventListener('load', function() {
  9.     var script = document.createElement("script");
  10.     script.textContent = "(" + callback.toString() + ")();";
  11.     document.body.appendChild(script);
  12.   }, false);
  13.   document.body.appendChild(script);
  14. }
  15.  
  16. function main() {
  17.     var t1 = '<br /><object style="height: 210px; width: 320px"><param name="movie" value="';
  18.     var t2 = '?version=3&feature=player_detailpage"><param name="allowFullScreen" value="true"><param name="allowScriptAccess" value="always"><embed src="';
  19.     var t3 = '?version=3&feature=player_detailpage" type="application/x-shockwave-flash" allowfullscreen="true" allowScriptAccess="always" width="320" height="180"></object><br />';
  20.  
  21.     $.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); });
  22.  
  23.     function add_answers(parent_post, post){
  24.         if($("div.title:contains('Ответ на') a[href$='" + $(parent_post).attr("id").replace("preview_", "") + "']", $(post)).length){
  25.             var a = "<a href='" + $(post).find(".title a:contains('#')").attr("href") + "'>" + ($(post).find(".sign a").html() ? $(post).find(".sign a").html() : "anonymous") + "</a>";
  26.             if($(".answers", parent_post).length){
  27.                 $($(".answers", parent_post)[0]).html($($(".answers", parent_post)[0]).html() + ", " + a);
  28.             }
  29.             else{
  30.                 $("<div />", {
  31.                     "class" : "answers"
  32.                     , "html": "Ответы: " + a
  33.                 }).insertAfter($("p:last", $(parent_post)));
  34.             }
  35.         }
  36.     }
  37.  
  38.     function add_parent_post(link, zi, pt, pl){
  39.         var timer;
  40.         link.mouseover(function(e){
  41.             var id = (e.target.hash ? e.target.hash.replace("#", "") : "comment-" + link.attr("href").match(RegExp("[?|&]cid=(.+?)(&|$)"))[0].split("=")[1]);
  42.             if($("#preview_" + id).length){
  43.                 clearTimeout(timer);
  44.                 return;
  45.             }
  46.             $.get(link.attr("href"), function(data){
  47.                 $("<article />", {
  48.                     'id': 'preview_' + id,
  49.                     'html': $("#" + id, $(data)).html(),
  50.                     'class': "target msg highLighted",
  51.                     '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;",
  52.                     'mouseover': function(){ clearTimeout(timer); },
  53.                     'mouseout': function(){  
  54.                         timer = setTimeout(
  55.                             function(){
  56.                                 $("#preview_" + id).remove();
  57.                             }
  58.                             , 800
  59.                         );
  60.                     }
  61.                 }).appendTo(".messages");
  62.                 $.each(posts, function(p){
  63.                     add_answers($("#preview_" + id), $(posts[p]));
  64.                 });
  65.                 $.each($("a:not([href^='/people/']):not([href^='add_comment.jsp']):not([href^='http']):not(:eq(0))", $("#preview_" + id)), function(){
  66.                     add_parent_post($(this), zi + 1, (pt + e.target["offsetTop"] + e.target.offsetHeight), (l = pl + e.target["offsetLeft"] + e.target.offsetWidth/2));
  67.                 });
  68.             });
  69.         });
  70.         link.mouseout( function(e){
  71.             var id = (e.target.hash ? e.target.hash.replace("#", "") : "comment-" + link.attr("href").match(RegExp("[?|&]cid=(.+?)(&|$)"))[0].split("=")[1]);
  72.             timer = setTimeout(
  73.                 function(){
  74.                     $("#preview_" + id).remove();
  75.                 }
  76.                 , 800
  77.             );
  78.         });
  79.    
  80.     }
  81.  
  82.     //var cur_page = window.location.href.match(/page\d+/) ? window.location.href.match(/page\d+/)[0].replace("page", "") : 0;
  83.     var pages = $("a.page-number:not(:contains('←')):not(:contains('→'))").slice(/*cur_page*/ 0, $("a.page-number:not(:contains('←')):not(:contains('→'))").length/2);
  84.     var posts_sel = ".msg:not([id*='topic'])";
  85.     var posts = $(posts_sel);
  86.     var l = pages.length;
  87.     var c = 0;
  88.     $.each(pages, function(pagei, pagev){
  89.         $.get($(pagev).attr("href"), function(data){
  90.             posts = $.merge(posts, $(posts_sel, $(data)));
  91.             c++;
  92.         });
  93.     });
  94.     (function t1(){
  95.         setTimeout(function(){
  96.             if(c == l){
  97.                 var ll = $(posts_sel).length;
  98.                 var cc = 0;
  99.                 $.each($(posts_sel), function(ppi, ppv){
  100.                     $.each(posts, function(pi, pv){
  101.                         add_answers(ppv, pv);
  102.                     });
  103.                     cc++;
  104.                 });
  105.                 (function t2(){
  106.                     setTimeout(function(){
  107.                         if(cc == ll){
  108.                             $.each($(posts_sel), function(pi, pv){
  109.                                 $.each($("a:not([href^='/people/']):not([href^='add_comment.jsp']):not([href^='http']):not(:eq(0))", $(pv)), function(li, lv){
  110.                                     add_parent_post($(lv), 300, 0, 0);
  111.                                 });
  112.                             });
  113.                         }
  114.                         else{
  115.                             t2();
  116.                         }
  117.                     }, 100);
  118.                 })();
  119.             }
  120.             else{
  121.                 t1();
  122.             }
  123.         }, 100);
  124.     })();
  125. }
  126.  
  127. addJQuery(main);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement