mirko live

stream wpisów na żywo

当前为 2015-05-17 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name mirko live
  3. // @namespace http://www.wykop.pl/
  4. // @version 0.4.2
  5. // @description stream wpisów na żywo
  6. // @author You
  7. // @match http://www.wykop.pl/mikroblog/*
  8. // @match http://www.wykop.pl/wpis/*
  9. // @grant none
  10. // ==/UserScript==
  11.  
  12. var interwal_ms = 150; //interwał sprawdzania nowych wpisów, zalecane 100 - 1000ms;
  13.  
  14. handleDefaultAjaxRefresh = function($el, data) {
  15.  
  16. var audio = new Audio('http://www.soundjay.com/switch/switch-7.wav');
  17.  
  18. if (data.html) {
  19. //console.log(data);
  20. $el = $("#itemsStream");
  21. var list = $($(data.html).html());
  22. //console.log(list);
  23. list.find('.dC').addClass('newComment');
  24. $d = list.prependTo($el);
  25. $e = $d.find('div.media-content > a > img');
  26. $d.find('div.media-content > a > img');
  27.  
  28. var t = $(window).scrollTop();
  29. var h = $d.outerHeight();
  30.  
  31. if (t){
  32. $e.hide();
  33. $(window).scrollTop(t + h + 2);
  34.  
  35. $($e).one('load', function () {
  36. //console.log("dumP!");
  37. $e.show();
  38. var imgHeight = $(this).outerHeight();
  39. var dm = $(window).scrollTop();
  40. $(window).scrollTop(dm + $d.outerHeight() - h);
  41. });
  42. } else {
  43. $e.show();
  44. }
  45.  
  46. $el.find('.newComment').animate({
  47. "border-left-color": 'transparent'
  48. }, 2000);
  49. //audio.play();
  50.  
  51. $("#newEntriesCounter").text("");
  52. //$("#rightFooterBoxCounter").find(".active-counter").text("");
  53. //$("#rightFooterBoxCounter").hide();
  54. console.log('nowy wpis - dodałem');
  55. wykop.bindLazy();
  56.  
  57. setTimeout(function(){
  58. wykop.checkNewEntries();
  59. }, interwal_ms);
  60.  
  61. } else {
  62. if (data.count > 0) {
  63. var lastItem = $(wykop.params.ajaxAutoRefresh.selector);
  64. var link = wykop.params.ajaxAutoRefresh.url + 'type/' + lastItem.data().type + '/id/' + lastItem.data().id + '/hash/' + wykop.params.hash + '/html/1';
  65. $("#newEntriesCounter").html("<div class=\"type-light-warning active-annotation\"><a href=\"#\" class=\"dark ajax space\" data-ajaxurl=\"" + link + "\">" + wykop.varietyFromNumber(data.count, ["Pojawił się", "Pojawiły się", "Pojawiło się"]) + " <b class=\"red\">" + data.count + " " + wykop.varietyFromNumber(data.count, ["nowy wpis", "nowe wpisy", "nowych wpisów"]) + "</b>, " + wykop.varietyFromNumber(data.count, ["pokaż go", "pokaż je", "pokaż je"]) + "</a></div>");
  66. console.log('nowe wpisy - klikam!');
  67. $('#newEntriesCounter > div > a').trigger("click");
  68. //$("#newEntriesCounter").fadeIn();
  69. //$("#rightFooterBoxCounter").show();
  70. //$("#rightFooterBoxCounter").find(".active-counter").text(data.count);
  71. } else {
  72. //$("#rightFooterBoxCounter").hide();
  73. $("#newEntriesCounter").hide().text("");
  74. console.log('brak nowych wpisów!');
  75. setTimeout(function(){
  76. wykop.checkNewEntries();
  77. }, interwal_ms);
  78. }
  79. }
  80. };
  81.  
  82. $(document).ready(function(){
  83.  
  84. if (document.location.pathname.match('/mikroblog/')){
  85. $('#site > div > div.grid.m-reset-float > div > div.nav.bspace.rbl-block > ul:last-child').append('<li id="live"><a href="http://www.wykop.pl/mikroblog/live/"><span style="font-weight: bold; font-size: 30px; vertical-align: middle;" id="green_icon">•</span><span> live</span></a></li>');
  86.  
  87. if (document.location.pathname.match('/live')){
  88.  
  89. wykop.handleDefaultAjaxRefresh = handleDefaultAjaxRefresh;
  90. wykop.ajaxAutoRefreshJob = function(){};
  91.  
  92. $('#site > div > div.grid.m-reset-float > div > div.nav.bspace.rbl-block > ul:nth-child(3) > li.active').removeClass('active');
  93. $('#live').html('<li class="active"><a href="http://www.wykop.pl/mikroblog/live/"><span style="color: green; font-weight: bold; font-size: 30px; vertical-align: middle;" id="green_icon">•</span><span> live</span></a></li>');
  94.  
  95. setInterval(function(){
  96. $('#green_icon').css('visibility','hidden');
  97. setTimeout(function(){
  98. $('#green_icon').css('visibility','visible');
  99. },1000)
  100. },2000);
  101.  
  102. setInterval(function(){
  103. $('#itemsStream > li:nth-child(n+50)').remove();
  104. console.log('usunięto stare wpisy');
  105. },60000);
  106.  
  107. }
  108. };
  109.  
  110. if (document.location.pathname.match('/wpis/')){
  111. $('#site > div > div.grid.m-reset-float > div > div.nav.bspace.rbl-block > ul:last-child').append('<li id="live"><a href="http://www.wykop.pl/mikroblog/live/"><span style="font-weight: bold; font-size: 30px; vertical-align: middle;" id="green_icon">•</span><span> live</span></a></li>');
  112. };
  113.  
  114. /*
  115. if (document.location.pathname.match('/tag/')){
  116. var location = document.location.href;
  117. $('#site > div > div.grid.m-reset-float > div > div.rbl-block.media-header > div > ul:nth-child(4) > li:last-child').append('<li id="live"><a href="' + location + '?=live/"><span style="font-weight: bold; font-size: 30px; vertical-align: middle;" id="green_icon">•</span><span> live</span></a></li>');
  118.  
  119. if (document.location.pathname.match('/?=live')){
  120.  
  121. wykop.ajaxAutoRefreshJob = function(){};
  122. wykop.handleDefaultAjaxRefresh = handleDefaultAjaxRefresh;
  123.  
  124. $('#site > div > div.grid.m-reset-float > div > div.rbl-block.media-header > div > ul:nth-child(4) > li').removeClass('active');
  125. $('#live').html('<li class="active"><a href="http://www.wykop.pl/mikroblog/live/"><span style="color: green; font-weight: bold; font-size: 30px; vertical-align: middle;" id="green_icon">•</span><span> live</span></a></li>');
  126.  
  127. setInterval(function(){
  128. $('#green_icon').css('visibility','hidden');
  129. setTimeout(function(){
  130. $('#green_icon').css('visibility','visible');
  131. },1000)
  132. },2000);
  133.  
  134. setInterval(function(){
  135. $('#itemsStream > li:nth-child(n+50)').remove();
  136. console.log('usunięto stare wpisy');
  137. },60000);
  138. }
  139. }
  140. */
  141. })