Greasy Fork

Greasy Fork is available in English.

ScriptableNaverCafeChat

네이버 신-웹 카페채팅 스크립트 확장

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

// ==UserScript==
// @name        ScriptableNaverCafeChat
// @namespace   http://teamlongsoft.blogspot.com/
// @description 네이버 신-웹 카페채팅 스크립트 확장
// @include     https://chat.cafe.naver.com/room/*
// @version     2
// @grant       none
// ==/UserScript==

if(typeof unsafewindow === 'undefined') {
	var unsafewindow = window;
}
//var fd='\nSendChatMsg 함수 : 메세지를 보내는 함수\nOnOtherSaid 함수 변수 : 다른사람이 말할때 실행되는 함수, 첫번째 인수는 msgsn(고유 번호), 두번째 인수는 말한 이, 세번째 인수는 메세지 내용\nSendNoti : 알림 띄우는 함수, 첫번째 인수로 내용';
unsafewindow.SendChatMsg=function(msg){document.querySelector('textarea#msgInputArea').value=msg; document.querySelector('span.hit > button').click();};
unsafewindow.OnOthersSaid=function(msgsn,sender,message){};

var MsgsArrived=[];
var FirstLoop=true;

var Messages=document.querySelectorAll('#boardBody.chat_msgs > div.msg');

for(var i=0;i<Messages.length;i++){
MsgsArrived.push(Messages[i].getAttribute('msgsn'));
}
MsgsArrived.push(null);

unsafewindow.Noti = function(title){
if(!("Notification" in window)){
	alert(title);
}else if(Notification.permission==="granted"){
	var notif = new Notification(title);
}else if (Notification.permission !== 'denied'){
	Notification.requestPermission(function(permission){
		if(permission==="granted"){
			var notif= new Notification(title);
		}
	});
}
}
unsafewindow.Loop = function(){
Messages=document.querySelectorAll('#boardBody.chat_msgs > div.msg');

// for loop
for(var i=0;i<Messages.length;i++){
var msgsn=Messages[i].getAttribute('msgsn');
var sender=Messages[i].getAttribute('targetid');
var mescon=document.querySelector('#boardBody.chat_msgs > div.msg[msgsn="'+msgsn+'"] > div.say > div.bl_pcs > div.blm > span').innerHTML;

// HTML Tag Replace
while(mescon.indexOf('&nbsp;')!=-1){mescon=mescon.replace('&nbsp;',' ');}
while(mescon.indexOf('<br>')!=-1){mescon=mescon.replace('<br>','\n');}
if(msgsn===null) continue;
if(sender===null) continue;
// if
if(msgsn!==null && MsgsArrived.indexOf(msgsn)==-1){
console.log('New Message!');
try{
unsafewindow.OnOthersSaid(msgsn,sender,mescon);
}catch(err){
	Noti("오류입니다!\n"+err.message)
}
MsgsArrived.push(msgsn);
} // if end
} // for end
setTimeout("Loop()",1000);
} // function end
unsafewindow.Loop0=function(){
if(document.querySelector('div#commonLayer').style.display!='none'){
	Noti('체팅창을 확인해주세요.');
}else{
setTimeout("Loop0()",1000);
}
}

unsafewindow.InsertMenu = function(menuname, func){
var menuelem=document.querySelector('#roomOptions > .ly_cont > ul.menu');
var m=document.createElement('li');
var aa=document.createElement('a');
aa.innerHTML=menuname;
aa.onclick = func;
m.appendChild(aa);
menuelem.appendChild(m);
} //function end
unsafewindow.InsertGUI = function(){
// n병의 맥주 노래
/* InsertMenu('n병의 맥주',function(){var co=prompt('몇병의 맥주가 있나요? (숫자만)');for(var i=co;i>0;i--){
if(i!=1) { SendChatMsg(i+'병의 맥주가 벽장에 있네, '+i+'병의 맥주라네.\n하나를 내려서 넘겨주었네, '+(i-1)+'병의 맥주가 벽장에 있네.'); } else {
SendChatMsg('1병의 맥주가 벽장에 있네, 1병의 맥주라네.\n하나를 내려서 넘거주었네, 더이상 벽장에 맥주가 없네.\n더이상 벽장에 맥주가 없네, 더이상 맥주는 없다네.\n가게에 가서 더 사려 했더니, 가게는 문을 닫고 있었네.');}
}}); */
// 다른 사람이 말할시 스크립트 설정 메뉴
InsertMenu('스크립트 설정',function(){
var sc=prompt('스크립트를 입력하세요.\nmsgsn은 msgsn 속성\nsender는 말한 이\nmessage는 메세지 내용입니다.\nSendChatMsg 함수는 채팅하는 함수입니다. 재정의하지 마시고 사용만 하세요.\nNoti 함수는 브라우저 내장 알림 API로 알림 띄우는 API입니다. 첫번째 인수로 메세지를 전달합니다.',"SendChatMsg('메세지 고유 번호 : '+msgsn+'\n보낸이 : '+sender+'\n메세지 : '+message);");
eval("unsafewindow.OnOthersSaid=function(msgsn,sender,message){"+sc+"};");
});
InsertMenu('스크립트 실행',function(){eval(prompt('실행할 스크립트를 입력하세요\nSendChatMsg 함수는 채팅보내는 함수, Noti함수는 브라우저 내장 알림 API를 이용한 함수로, 첫번째 인수로 메세지를 받습니다.','alert("Hello!");'));});
}
Loop();
Loop0();
InsertGUI();