Greasy Fork

Greasy Fork is available in English.

내카체Plus

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

当前为 2015-04-06 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name        내카체Plus
// @namespace   http://teamlongsoft.blogspot.com/
// @description 네이버 신-웹 카페채팅 스크립트 확장
// @include     https://chat.cafe.naver.com/room/*
// @version     6
// @grant       none
// @run-at 	document-end
// ==/UserScript==

// APIs
var nccSendChat=function(msg){ // 체팅 보내기
	document.querySelector('textarea#msgInputArea').value=msg;
	document.querySelector('span.hit > button').click();
};
var nccNotification=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);
			}
		});
	}
}
var nccCreateMenu = function(menuname, func){ // 메뉴 생성
	var menuelem=document.querySelector('#roomOptions > .ly_cont > ul.menu'); // 기존 ... 메뉴
	var m=document.createElement('li'); // li 태그 생성
	var aa=document.createElement('a'); // a 태그 생성
	aa.innerHTML=menuname; // a 태그 텍스트 설정
	aa.onclick = func; // a 태그 클릭시 함수 설정
	m.appendChild(aa); // li태그에 a태그 추가
	menuelem.appendChild(m); // ...메뉴에 li 태그 추가
}
// Event
function CEvent(){
	var funcs =[];
	this.addEventHandler = function(func){funcs.push(func);}
	this.removeEventHandler = function(func){funcs.splice(funcs.indexOf(func),1);};
	this.getEventHandlers=function(){return funcs;}
	this.raiseEvent=function(arg){for(var i=0;i<funcs.length;i++){funcs[i](arg);}};
}
// forEach 함수
var forEach=function(arr,func){
	for(var i=0;i<arr.length;i++){
		try{func(arr[i]);}catch(err){}
	}
}
// 메세지 불러오기
var getMessages = function(){
	return document.querySelectorAll('#boardBody.chat_msgs > div.msg');
}
var __MessagesRead;
var __EventOnMessagedCreated;
function LoopMsg(){
	var msgs = getMessages();
	forEach(msgs, function(element){
		var _msgsn=element.getAttribute('msgsn');
		if(_msgsn==null) return false;
		var nic=document.querySelector('#boardBody.chat_msgs > div.msg[msgsn="'+_msgsn+'"] > div.say > p.name');
		if(nic!=null){nic=nic.innerHTML}
		if(__MessagesRead.indexOf(_msgsn)==-1){
			var Arg={
				msgsn:_msgsn,
				message:document.querySelector('#boardBody.chat_msgs > div.msg[msgsn="'+_msgsn+'"] > div.say > div.bl_pcs > div.blm > span').innerHTML,
				senderID:element.getAttribute('targetid'), // 자기가 쓴 글이면 null임.
				senderNick:nic, // 이거도
				IsMyMessage:element.getAttribute('targetid')==null
			};
			while(Arg.message.indexOf('&nbsp;')!=-1){Arg.message=Arg.message.replace('&nbsp;',' ');}
			while(Arg.message.indexOf('<br>')!=-1){Arg.message=Arg.message.replace('<br>',' ');}
			__EventOnMessagedCreated.raiseEvent(Arg);
			__MessagesRead.push(_msgsn);
		} // if end
	}); // for each end
	
	setTimeout("LoopMsg()",500);
}
function LoadScript(){
	eval(localStorage.getItem('RecentScript')==null?'console.log("No Script");':localStorage.getItem('RecentScript'));
}
function Main(){
	__EventOnMessagedCreated  = new CEvent();
	__MessagesRead = [];
	LoadScript();
	
	// 기존에 있던 메세지들 추가
	forEach(getMessages(), function(element){
		__MessagesRead.push(element.getAttribute('msgsn'));
	});

	// 메뉴 추가
	nccCreateMenu('스크립트 실행',function(){localStorage.setItem('RecentScript',prompt('실행할 스크립트를 입력해주세요.\n입력한 스크립트는 자동으로 기억되며, 후에 채팅창 접속시 자동으로 실행됩니다.'));LoadScript();});
	
	// 루프 시작
	LoopMsg();
}
if(typeof unsafewindow === "undefined"){
	var unsafewindow = window; // Greasemonkey 감지
}
if(typeof(Storage) === "undefined"){
	// localStorage 사용 불가시 스크립트 중지
	alert('스크립트를 사용할 수 없습니다.\n최신 버전의 브라우저에서 사용 해 주세요.(Firefox/Chrome 권장)');
} else {
	// 스크립트 실행
	Main();
}