사용자:Sternradio/Sephirot.js: 두 판 사이의 차이

잔글편집 요약 없음
잔글편집 요약 없음
179번째 줄: 179번째 줄:
Mascot.prototype.ToBig = function()
Mascot.prototype.ToBig = function()
{
{
$(this.mascot_img_html).css("height",400);
$(this.mascot_img_html).css("height",400px);
if(this.now_balloon !== null)
if(this.now_balloon !== null)
{
{

2015년 12월 25일 (금) 04:07 판

/*
사용자:다메즈마로 부터 기본 코드를 가져왔습니다.
사용하시는 것은 자유지만 사용자:다메즈마의 코드를 퍼왔다고 한 줄만 써주세요. 
 
바뀐 점
제가 안 쓰는 북마크 버튼을 삭제하고 대신 아래로 가는 버튼 추가.
"위로"와 "아래로"에 애니매이션 추가.
여러 이미지 사용 가능, 이미지 별로 코멘트 작성 가능.
모바일에선 안 나오게 수정.
*/
 
/* 
참고: 이 스크립트는 사용자:Skim님께서 수정하신 버전을 손본 것입니다. 
*/
function randomRange(n1, n2) {
  return Math.round( Math.random()  * 10000) % (n2 - n1) + n1;
}
 
function Mascot()
{
	this.is_loaded = false;
	this.is_show = false;
	this.mascot_img_list = [];
	this.message_queue =  [];
	this.now_balloon = null;
	this.is_small = true;
}
 
Mascot.prototype.AddImage = function(img)
{
	this.mascot_img_list.push(img);
};
 
Mascot.prototype._show_balloon = function()
{
	this.now_balloon = document.createElement("div");
	$(this.now_balloon).css("position","fixed");
	$(this.now_balloon).css("display","none");
	$(this.now_balloon).html(this.message_queue[0]);
	$(this.now_balloon).css("background-color","#000");
	$(this.now_balloon).css("color","#FFF");
	$(this.now_balloon).css("max-width","225px");
	$(this.now_balloon).css("padding","16px");
	$(document.body).append(this.now_balloon);
 
	$(this.now_balloon).css("bottom",$(this.mascot_img_html).height()/2 +80- $(this.now_balloon).height()/2 + 32);
 
	$(this.now_balloon).css("right",$(this.mascot_img_html).width() - 0);
	$(this.now_balloon).css("border-radius",5);
	$(this.now_balloon).fadeIn(1000);
	this.message_queue.shift();
	this.now_balloon.obj = this;
	$(this.now_balloon).click
	(
	function()
	{
		var obj = this.obj;
		$(obj.now_balloon).fadeOut(1000).delay(1000,function(){$(this).remove();});
		obj.now_balloon = null;
		if(obj.message_queue.length !== 0)
		{
			obj._show_balloon();
		}
	}
	);
};
 
Mascot.prototype.Show = function()
{
	if(this.is_show) return;
	this.is_show = true;
	var select = this.mascot_img_list[randomRange(0,this.mascot_img_list.length)];
	var wrap_div = document.createElement("div");
	this.mascot_img_html = document.createElement("img");
	this.mascot_img_html.obj = this;
	if(localStorage.getItem("custom_dmns_is_small") == "true")
	{
		this.ToSmall();
	}
	else
	{
		this.ToBig();
	}
	this.mascot_img_html.onload = function()
	{
		var obj = this.obj;
		if(localStorage.getItem("custom_dmns_is_small") == "true")
		{
			obj.ToSmall();
		}
		else
		{
			obj.ToBig();
		}
		if(obj.message_queue.length !== 0)
		{
			obj._show_balloon();
		}
		$(".top_s_btn").css("display","none");
		$("#to-top-btn").css("width",$(this).width()/2);
		$("#to-bottom-btn").css("width",$(this).width()/2);
		obj.is_loaded = true;
	};
	$(this.mascot_img_html).click(
	function()
	{
		if(this.obj.is_small === false)
		{
			this.obj.ToSmall();
		}
		else
		{
			this.obj.ToBig();
		}
	});
 
	this.mascot_img_html.src = select;
 
	$(this.mascot_img_html).css("display","block");
	$(wrap_div).css("position","fixed");
	$(wrap_div).css("right","16px");
	$(wrap_div).css("bottom","16px");
	$(wrap_div).append(this.mascot_img_html);
	$(wrap_div).append("<ul style='list-style:none;padding: 0px;margin:0px;display:inline;'><li style='float:left;'><a id='to-top-btn' href='#' style='text-align:center;display:inline-block;line-height:32px;width:100%;background-color:#000;color:#FFF;font-weight:bold;'>위로</a></li><li style='float:left;'><a id='to-bottom-btn' href='#' style='text-align:center;display:inline-block;line-height:32px;width:100%;background-color:#000;color:#FFF;font-weight:bold;'>아래로</a></li></ul>");
	$(document.body).append(wrap_div);
	$("#to-top-btn").click(
	function()
	{$('html, body').animate({scrollTop:0}, 'slow');}
	);
 
	$("#to-bottom-btn").click(
	function()
	{$('html, body').animate({scrollTop:document.body.scrollHeight}, 'slow');}
	);
};
 
Mascot.prototype.ShowMessage = function(msg)
{
	this.message_queue.push(msg);
 
	if(this.is_show === false)
	{
		this.Show();
	}
	else{
		this.CloseMessage();
	}
 
	if(this.now_balloon === null && this.is_loaded === true)
	{
		this._show_balloon();
	}
};
 
Mascot.prototype.CloseMessage = function()
{
	$(this.now_balloon).fadeOut(1000).delay(1000,function(){$(this).remove();});
	this.now_balloon = null;
	if(this.message_queue.length !== 0)
	{
		this._show_balloon();
	}
};
 
Mascot.prototype.ToSmall = function()
{
	$(this.mascot_img_html).css("width",96);
	if(this.now_balloon !== null)
	{
		$(this.now_balloon).css("bottom",$(this.mascot_img_html).height()/2 +16 - $(this.now_balloon).height()/2 + 32);
		$(this.now_balloon).css("right",$(this.mascot_img_html).width() + 32);
	}
	$("#to-top-btn").css("width",$(this.mascot_img_html).width()/2);
	$("#to-bottom-btn").css("width",$(this.mascot_img_html).width()/2);
	this.is_small = true;
	localStorage.setItem("custom_dmns_is_small",true);
};
 
Mascot.prototype.ToBig = function()
{
	$(this.mascot_img_html).css("height",400px);
	if(this.now_balloon !== null)
	{
		$(this.now_balloon).css("bottom",$(this.mascot_img_html).height()/2 +16 - $(this.now_balloon).height()/2 + 32);
		$(this.now_balloon).css("right",$(this.mascot_img_html).width() + 40);
	}
	$("#to-top-btn").css("width",$(this.mascot_img_html).width()/2);
	$("#to-bottom-btn").css("width",$(this.mascot_img_html).width()/2);
	this.is_small = false;
	localStorage.setItem("custom_dmns_is_small",false);
};
 
var mascot = new Mascot();
 
$(document).ready(function(){
 
var isMobile = false;
if(/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)){
	isMobile = true;
}
 
if(isMobile === false){
var secretary1 = "/images/7/7c/Sephi1.png"; //세피1 
var secretary2 = "/images/d/d4/Sephi2.png"; //세피2 
var secretary3 = "/images/7/72/Cut_sephi3.png"; //세피3


 
var comment1 = 
[
"안녕하세요・・・.",
"・・・여긴 어디죠?",
"제가 왜 여기에・・・?",
"・・・.",
"모르겠어요・・・.",
"하아・・・."
];
 
var comment2 =
[
"네, 네, 안녕하세요.",
"하아・・・바쁘네요・・・.",
"말 시키지 말아주세요.",
"됐거든요.",
"・・・.",
"여긴 한가해서 좋겠네요.",
"또 반달이에요・・・."
];
 
var comment3 =
[
"안녕하세요.",
"왜요?",
"이 뿔이 그렇게 이상해요?",
"여기 있으면 안 되는데・・・.",
"그냥 나무로 가지 그래요?",
"그게 뭐 하는 거죠?"
];
 
var secretaries = [secretary1, secretary2, secretary3];
var comments = [comment1, comment2, comment3];
var index = randomRange(0,secretaries.length);
 
mascot.AddImage(secretaries[index]);
mascot.ShowMessage(comments[index][randomRange(0,comments[index].length)]);
 
var temp = function(){
	var param = 
	{
		"action":"query",
		"meta":"notifications",
		"notlimit":10,
		"format":"json"
	};
	$.ajax("/api.php",
	{
		data:param,
		dataType:"json"
	})
	.done(function(res)
	{
		var list_o = res.query.notifications.list;
		var list = [];
		for(var key in list_o)
		{
			list.push(list_o[key]);
		}
		var unread_message = [];
		for(var i = 0 ; i < list.length ; i++)
		{
			if(list[i].read === null && list[i].type != "page-linked")
			{
				unread_message.push(list[i]);
			}
		}
		if(unread_message.length !== 0)
		{
			if(index === 0)
			{
			mascot.ShowMessage("<a style='color:#FFF;' href='/wiki/"+ encodeURIComponent(unread_message[unread_message.length - 1].title.full)  + "'>어... 메세지가 왔다나봐요...</a>");
			}
 
			if(index == 1)
			{
			mascot.ShowMessage("<a style='color:#FFF;' href='/wiki/"+ encodeURIComponent(unread_message[unread_message.length - 1].title.full)  + "'>메세지 왔으니까 어서 읽어봐요.</a>");
			}
 
			if(index == 2)
			{
			mascot.ShowMessage("<a style='color:#FFF;' href='/wiki/"+ encodeURIComponent(unread_message[unread_message.length - 1].title.full)  + "'>메세지 왔네요?</a>");
			}
 
		
		}
	});
};
temp();
setInterval(temp,1000 * 20);
}
});