사용자:타이가/common.js

참고: 설정을 저장한 후에 바뀐 점을 확인하기 위해서는 브라우저의 캐시를 새로 고쳐야 합니다.

  • 파이어폭스 / 사파리: Shift 키를 누르면서 새로 고침을 클릭하거나, Ctrl-F5 또는 Ctrl-R을 입력 (Mac에서는 ⌘-R)
  • 구글 크롬: Ctrl-Shift-R키를 입력 (Mac에서는 ⌘-Shift-R)
  • 인터넷 익스플로러 / 엣지: Ctrl 키를 누르면서 새로 고침을 클릭하거나, Ctrl-F5를 입력.
  • 오페라: Ctrl-F5를 입력.
//<!--[[사용자:다메즈마/mascot notification.js]]에서 이츠레아 부분 삭제-->
//<!--[[사용자:다메즈마/hisyokan.js]]을 변형한 [[사용자:Skim/secretary.js]] 사용-->

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).addClass("mascot_wrap"); //css설정을 위해 class지정
	$(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");
	$(this.now_balloon).css("z-index","1001");
	$(document.body).append(this.now_balloon);
 
	$(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);
	$(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).css("z-index","9999");
	$(wrap_div).addClass("mascot_wrap"); //css설정을 위해 class지정
	$(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("width",256);
	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 = false;
	localStorage.setItem("custom_dmns_is_small",false);
}
 
var mascot = new Mascot();
 
//마스코트를 수정하실 분은 이 부분 부터 변경하시면 됩니다.
 
$(document).ready(function(){
/*
아랫 줄 큰 따옴표(") 사이에 이미지 주소를 넣으면 이미지를 불러올 수 있습니다 (gif도 가능).
리브레 위키 내의 이미지의 경우 "https://librewiki.net"을 생략 가능하며, 외부 이미지는 이미지 주소를 다 쓰셔야합니다.
*/
 
var secretary1 = "/images/f/f6/Umi.png"; //우미1
var secretary2 = "/images/f/f2/Umi2.png"; //우미2
var secretary3 = "/images/5/5f/Umi3.png"; //우미3
var secretary4 = "/images/1/1b/Riko.png"; // 리코1
var secretary5 = "/images/c/cf/Riko2.png"; // 리코2
var secretary6 = "/images/8/82/Riko3.png"; // 리코3
var secretary7 = "/images/8/87/Rin.png"; // 린1
var secretary8 = "/images/0/09/Rin2.png"; // 린2
var secretary9 = "/images/9/95/Rin3.png"; // 린3
// var secretaryX = "/images/b/be/리브렌_100.png"; //리브렌


 
/*
마스코트의 코멘트는 아래 대괄호 안의 문장을 바꾸시면 됩니다.
문장을 추가할 시에는 콤마(,)를 넣어야 합니다.
*/
 
var secretary1_comment = 
[
"오늘도 활기차게 보내봐요!", "이얍! 제 물총 맛이 어떤가요?."
];
 
var secretary2_comment =
[
"호노카가 훈련을 열심히 해야 할 텐데요…", "오늘 기분은 어떠세요?"
];
 
var secretary3_comment =
[
"스쿨 아이돌이 되어서 정말로 잘 되었다고 생각해요!", "당신도 제 공연에 보러 와 주실거죠?"
];

var secretary4_comment =
[
"사쿠라우치 리코에요!", "리브룬과 함께 활기찬 하루를 보내자구"
];

var secretary5_comment =
[
"레브가 바쁠 때는 내가 일한다구", "닦고 기름칠하고 조이자구"
];

var secretary6_comment =
[
"바이트 수가 늘어날 때마다 머리숯이 많아져요...", "문서를 읽기 쉽게 만들면 머릿결이 좋아져요..."
];

var secretary7_comment =
[
"바이트 수가 늘어날 때마다 머리숯이 많아져요...", "문서를 읽기 쉽게 만들면 머릿결이 좋아져요..."
];

var secretary8_comment =
[
"[SYSTEM: 서버담당자인 것 같다.]", "[SYSTEM: 말이 없는 것 같다.]"
];

var secretary9_comment =
[
"[SYSTEM: 서버담당자인 것 같다.]", "[SYSTEM: 말이 없는 것 같다.]"
];

/*
var secretaryX_comment =
[
"나 팩맨아니라고!",
];
*/

var secretaries = [secretary1, secretary2, secretary3, secretary4, secretary5, secretary6, secretary7, secretary8];
var secretaries_comment = [secretary1_comment, secretary2_comment, secretary3_comment, secretary4_comment, secretary5_comment, secretary6_comment, secretary7_comment, secretary8_comment];

var index = randomRange(0,secretaries.length);
 
mascot.AddImage(secretaries[index]);
mascot.ShowMessage(secretaries_comment[index][randomRange(0,secretaries_comment[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)
		{//메세지 알람 멘트를 수정 하려면 '>와 </a>사이를 변경하세요.
		
			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>");
			}
 
			if(index == 3)
			{
			mascot.ShowMessage("<a style='color:#FFF;' href='/wiki/"+ encodeURIComponent(unread_message[unread_message.length - 1].title.full)  + "'>알림이 왔다구.</a>");
			}
			
			if(index == 4)
			{
			mascot.ShowMessage("<a style='color:#FFF;' href='/wiki/"+ encodeURIComponent(unread_message[unread_message.length - 1].title.full)  + "'>알림이 왔다구.</a>");
			}
			
			if(index == 5)
			{
			mascot.ShowMessage("<a style='color:#FFF;' href='/wiki/"+ encodeURIComponent(unread_message[unread_message.length - 1].title.full)  + "'>알림이 왔어요...</a>");
			}
			
			if(index == 6)
			{
			mascot.ShowMessage("<a style='color:#FFF;' href='/wiki/"+ encodeURIComponent(unread_message[unread_message.length - 1].title.full)  + "'>알림이 왔어요...</a>");
			}
			
			if(index == 7)
			{
			mascot.ShowMessage("<a style='color:#FFF;' href='/wiki/"+ encodeURIComponent(unread_message[unread_message.length - 1].title.full)  + "'>[SYSTEM: 알림이 온 것 같다.]</a>");
			}
			
			if(index == 8)
			{
			mascot.ShowMessage("<a style='color:#FFF;' href='/wiki/"+ encodeURIComponent(unread_message[unread_message.length - 1].title.full)  + "'>[SYSTEM: 알림이 온 것 같다.]</a>");
			}
		}
	});
};
temp();
setInterval(temp,1000 * 20);
});