123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238 |
- var httpObject = null;
- var link = "";
- var link2 = "";
- var link3 = "";
- var pinglink = "";
- var ScrollDown = 0;
- var msgBox = document.getElementById('msgs');
- var timerID = 0;
- // Get the HTTP Object
- function getHTTPObject() {
- if (window.ActiveXObject) return new ActiveXObject("Microsoft.XMLHTTP");
- else if (window.XMLHttpRequest) return new XMLHttpRequest();
- else {
- alert("Your browser does not support AJAX.");
- return null;
- }
- }
- // MSGBOX input
- function UserPM(tag) {
- var msgInput = document.getElementById('msg');
- var content = msgInput.value;
- msgInput.value = '/msg ' + tag + ' ' + content;
- }
- // Change the value of the outputText field
- function setHtml() {
- if(ajaxVar.readyState == 4){
- var response = ajaxVar.responseText;
- var msgBox = document.getElementById("msgs");
- msgBox.innerHTML += response;
- ScrollDown = 0;
- MsgScrollDown();
- }
- }
- // Change the value of the outputText field
- function setAll() {
- if(ajaxVar.readyState == 4){
- var response = ajaxVar.responseText;
- var msgBox = document.getElementById("msgs");
- msgBox.innerHTML = response;
- ScrollDown = 0;
- MsgScrollDown();
- }
- }
- // Getting and generating user list.
- function genUserlist() {
- if(ajaxUserlist.readyState == 4){
- var response = ajaxUserlist.responseText;
- var userlist = document.getElementById('userlist');
- userlist.innerHTML = response;
- }
- }
- function getUserlist() {
- ajaxUserlist = getHTTPObject();
- //var randomnumber=Math.floor(Math.random()*10000);
- if (ajaxUserlist != null) {
- link = "server.php?userlist&nick="+nickName;
- ajaxUserlist.open("GET", link , true);
- ajaxUserlist.onreadystatechange = genUserlist;
- ajaxUserlist.send(null);
- }
- }
-
- function doNotificationPm() {
- if(ajaxVar4.readyState == 4){
- var mentionUser = ajaxVar4.responseText;
- if(Notification.permission==="granted") {
- var notify = new Notification("Private message from " + mentionUser, { body: ""});
- }
- }
- }
- function getPmUser() {
- ajaxVar4 = getHTTPObject();
- //var randomnumber=Math.floor(Math.random()*10000);
- if (ajaxVar4 != null) {
- link4 = "server.php?get=notificationpmed&nick="+nickName;
- ajaxVar4.open("GET", link4 , true);
- ajaxVar4.onreadystatechange = doNotificationPm;
- ajaxVar4.send(null);
- }
- }
- function checkNotificationPm() {
- if(ajaxVar5.readyState == 4){
- var returnMsg = ajaxVar5.responseText;
- var compareString = "true";
- //console.log(returnMsg);
- if(returnMsg.trim() === compareString.trim()) {
- getPmUser();
- }
- }
- }
- function checkPmUrl() {
- ajaxVar5 = getHTTPObject();
- //var randomnumber=Math.floor(Math.random()*10000);
- if (ajaxVar5 != null) {
- link5 = "server.php?get=notificationpmedexists&nick="+nickName;
- ajaxVar5.open("GET", link5 , true);
- ajaxVar5.onreadystatechange = checkNotificationPm;
- ajaxVar5.send(null);
- }
- }
- function doNotificationMention() {
- if(ajaxVar2.readyState == 4){
- var mentionUser = ajaxVar2.responseText;
- if(Notification.permission==="granted") {
- var notify = new Notification("You were mentioned by " + mentionUser, { body: ""});
- }
- }
- }
- function getMentionUser() {
- ajaxVar2 = getHTTPObject();
- //var randomnumber=Math.floor(Math.random()*10000);
- if (ajaxVar2 != null) {
- link2 = "server.php?get=notificationmention&nick="+nickName;
- ajaxVar2.open("GET", link2 , true);
- ajaxVar2.onreadystatechange = doNotificationMention;
- ajaxVar2.send(null);
- }
- }
- function checkNotificationMention() {
- if(ajaxVar3.readyState == 4){
- var returnMsg = ajaxVar3.responseText;
- var compareString = "true";
- //console.log(returnMsg);
- if(returnMsg.trim() === compareString.trim()) {
- getMentionUser();
- }
- }
- }
- function checkMentionUrl() {
- ajaxVar3 = getHTTPObject();
- //var randomnumber=Math.floor(Math.random()*10000);
- if (ajaxVar3 != null) {
- link3 = "server.php?get=notificationmentionexists&nick="+nickName;
- ajaxVar3.open("GET", link3 , true);
- ajaxVar3.onreadystatechange = checkNotificationMention;
- ajaxVar3.send(null);
- }
- }
- // Implement business logic
- function serverWrite() {
- ajaxVar = getHTTPObject();
- if (ajaxVar != null) {
- link = "server.php?nick="+nickName+"&msg="+encodeURIComponent(document.getElementById('msg').value);
- ajaxVar.open("GET", link , true);
- ajaxVar.send(null);
- }
- }
- // Implement business logic
- function serverReload() {
- ajaxVar = getHTTPObject();
- //var randomnumber=Math.floor(Math.random()*10000);
- if (ajaxVar != null) {
- link = "server.php?get&nick="+nickName;
- ajaxVar.open("GET", link , true);
- ajaxVar.onreadystatechange = setAll;
- ajaxVar.send(null);
- }
- }
- function MsgScrollDown() {
- if(ScrollDown != 1) {
- var msgBox = document.getElementById("msgs");
- msgBox.scrollTop = msgBox.scrollHeight;
- ScrollDown = 1;
- }
- }
- function UpdateTimer() {
- serverReload();
- MsgScrollDown();
- getUserlist();
- checkPmUrl();
- checkMentionUrl();
- setTimeout(UpdateTimer, 1000);
- }
- function doLogin() {
- ajaxVar = getHTTPObject();
- if(ajaxVar != null) {
- link = "server.php?do=login&nick="+nickName;
- ajaxVar.open("GET", link, true);
- ajaxVar.onreadystatechange = setHtml;
- ajaxVar.send(null);
- setTimeout(function() { window.location.reload(); },1000);
- }
- }
- function doClearLog() {
- ajaxVar = getHTTPObject();
- if(ajaxVar != null) {
- link = "server.php?do=clearlog&nick="+nickName;
- ajaxVar.open("GET", link, true);
- ajaxVar.onreadystatechange = setHtml;
- ajaxVar.send(null);
- setTimeout(function() { window.location.reload(); },1000);
- }
- }
- function doLogout() {
- ajaxVar = getHTTPObject();
- if(ajaxVar != null) {
- link = "server.php?do=logout&nick="+nickName;
- ajaxVar.open("GET", link, true);
- ajaxVar.onreadystatechange = setHtml;
- ajaxVar.send(null);
- setTimeout(function() { window.location.reload(); },1000);
- }
- }
- function wrapBBCode(tag) {
- var msgInput = document.getElementById('msg');
- var content = msgInput.value;
- var selectedContent = content.substring(msgInput.selectionStart, msgInput.selectionEnd);
- var beforeContent = content.substring(0, msgInput.selectionStart);
- var afterContent = content.substring(msgInput.selectionEnd, content.length);
- msgInput.value = beforeContent + '[' + tag + ']' + selectedContent + '[/' + tag + ']' + afterContent;
- }
|