mirko live

stream wpisów na żywo

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

// ==UserScript==
// @name         mirko live
// @namespace    http://www.wykop.pl/
// @version      0.4.2
// @description  stream wpisów na żywo
// @author       You
// @match        http://www.wykop.pl/mikroblog/*
// @match        http://www.wykop.pl/wpis/*
// @grant        none
// ==/UserScript==

var interwal_ms = 150; //interwał sprawdzania nowych wpisów, zalecane 100 - 1000ms;

handleDefaultAjaxRefresh = function($el, data) {

	var audio = new Audio('http://www.soundjay.com/switch/switch-7.wav');

	if (data.html) {
		//console.log(data);
		$el = $("#itemsStream");
		var list = $($(data.html).html());
		//console.log(list);
		list.find('.dC').addClass('newComment');
		$d = list.prependTo($el);
		$e = $d.find('div.media-content > a > img');
		$d.find('div.media-content > a > img');

		var t = $(window).scrollTop();
		var h = $d.outerHeight();

		if (t){
			$e.hide();
        	$(window).scrollTop(t + h + 2);

        	$($e).one('load', function () {
				//console.log("dumP!");
				$e.show();
	        	var imgHeight = $(this).outerHeight();
	        	var dm = $(window).scrollTop();
	        	$(window).scrollTop(dm + $d.outerHeight() - h);
	    	});
    	} else {
    		$e.show();
    	}

		$el.find('.newComment').animate({
			"border-left-color": 'transparent'
		}, 2000);
		//audio.play();

		$("#newEntriesCounter").text("");
		//$("#rightFooterBoxCounter").find(".active-counter").text("");
		//$("#rightFooterBoxCounter").hide();
		console.log('nowy wpis - dodałem');
		wykop.bindLazy();

		setTimeout(function(){
			wykop.checkNewEntries();
		}, interwal_ms);

	} else {
		if (data.count > 0) {
			var lastItem = $(wykop.params.ajaxAutoRefresh.selector);
			var link = wykop.params.ajaxAutoRefresh.url + 'type/' + lastItem.data().type + '/id/' + lastItem.data().id + '/hash/' + wykop.params.hash + '/html/1';
			$("#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>");
			console.log('nowe wpisy  - klikam!');
			$('#newEntriesCounter > div > a').trigger("click");
			//$("#newEntriesCounter").fadeIn();
			//$("#rightFooterBoxCounter").show();
			//$("#rightFooterBoxCounter").find(".active-counter").text(data.count);
		} else {
			//$("#rightFooterBoxCounter").hide();
			$("#newEntriesCounter").hide().text("");
			console.log('brak nowych wpisów!');
			setTimeout(function(){
				wykop.checkNewEntries();
			}, interwal_ms);
		}
	}
};

$(document).ready(function(){

	if (document.location.pathname.match('/mikroblog/')){
		$('#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>');

		if (document.location.pathname.match('/live')){

			wykop.handleDefaultAjaxRefresh = handleDefaultAjaxRefresh;
			wykop.ajaxAutoRefreshJob = function(){};

			$('#site > div > div.grid.m-reset-float > div > div.nav.bspace.rbl-block > ul:nth-child(3) > li.active').removeClass('active');
			$('#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>');

			setInterval(function(){
				$('#green_icon').css('visibility','hidden');
				setTimeout(function(){
					$('#green_icon').css('visibility','visible');
				},1000)
			},2000);

			setInterval(function(){
				$('#itemsStream > li:nth-child(n+50)').remove();
				console.log('usunięto stare wpisy');
			},60000);

		}
	};

	if (document.location.pathname.match('/wpis/')){
		$('#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>');
	};

	/*
	if (document.location.pathname.match('/tag/')){
		var location = document.location.href;
		$('#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>');

		if (document.location.pathname.match('/?=live')){

			wykop.ajaxAutoRefreshJob = function(){};
			wykop.handleDefaultAjaxRefresh = handleDefaultAjaxRefresh;

			$('#site > div > div.grid.m-reset-float > div > div.rbl-block.media-header > div > ul:nth-child(4) > li').removeClass('active');
			$('#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>');

			setInterval(function(){
				$('#green_icon').css('visibility','hidden');
				setTimeout(function(){
					$('#green_icon').css('visibility','visible');
				},1000)
			},2000);

			setInterval(function(){
				$('#itemsStream > li:nth-child(n+50)').remove();
				console.log('usunięto stare wpisy');
			},60000);
		}
	}
	*/
})