core.js 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. var httpObject = null;
  2. var link = "";
  3. var link2 = "";
  4. var link3 = "";
  5. var pinglink = "";
  6. var ScrollDown = 0;
  7. var msgBox = document.getElementById('msgs');
  8. var timerID = 0;
  9. // Get the HTTP Object
  10. function getHTTPObject() {
  11. if (window.ActiveXObject) return new ActiveXObject("Microsoft.XMLHTTP");
  12. else if (window.XMLHttpRequest) return new XMLHttpRequest();
  13. else {
  14. alert("Your browser does not support AJAX.");
  15. return null;
  16. }
  17. }
  18. // MSGBOX input
  19. function UserPM(tag) {
  20. var msgInput = document.getElementById('msg');
  21. var content = msgInput.value;
  22. msgInput.value = '/msg ' + tag + ' ' + content;
  23. }
  24. // Change the value of the outputText field
  25. function setHtml() {
  26. if(ajaxVar.readyState == 4){
  27. var response = ajaxVar.responseText;
  28. var msgBox = document.getElementById("msgs");
  29. msgBox.innerHTML += response;
  30. ScrollDown = 0;
  31. MsgScrollDown();
  32. }
  33. }
  34. // Change the value of the outputText field
  35. function setAll() {
  36. if(ajaxVar.readyState == 4){
  37. var response = ajaxVar.responseText;
  38. var msgBox = document.getElementById("msgs");
  39. msgBox.innerHTML = response;
  40. ScrollDown = 0;
  41. MsgScrollDown();
  42. }
  43. }
  44. // Getting and generating user list.
  45. function genUserlist() {
  46. if(ajaxUserlist.readyState == 4){
  47. var response = ajaxUserlist.responseText;
  48. var userlist = document.getElementById('userlist');
  49. userlist.innerHTML = response;
  50. }
  51. }
  52. function getUserlist() {
  53. ajaxUserlist = getHTTPObject();
  54. //var randomnumber=Math.floor(Math.random()*10000);
  55. if (ajaxUserlist != null) {
  56. link = "server.php?userlist&nick="+nickName;
  57. ajaxUserlist.open("GET", link , true);
  58. ajaxUserlist.onreadystatechange = genUserlist;
  59. ajaxUserlist.send(null);
  60. }
  61. }
  62. function doNotificationPm() {
  63. if(ajaxVar4.readyState == 4){
  64. var mentionUser = ajaxVar4.responseText;
  65. if(Notification.permission==="granted") {
  66. var notify = new Notification("Private message from " + mentionUser, { body: ""});
  67. }
  68. }
  69. }
  70. function getPmUser() {
  71. ajaxVar4 = getHTTPObject();
  72. //var randomnumber=Math.floor(Math.random()*10000);
  73. if (ajaxVar4 != null) {
  74. link4 = "server.php?get=notificationpmed&nick="+nickName;
  75. ajaxVar4.open("GET", link4 , true);
  76. ajaxVar4.onreadystatechange = doNotificationPm;
  77. ajaxVar4.send(null);
  78. }
  79. }
  80. function checkNotificationPm() {
  81. if(ajaxVar5.readyState == 4){
  82. var returnMsg = ajaxVar5.responseText;
  83. var compareString = "true";
  84. //console.log(returnMsg);
  85. if(returnMsg.trim() === compareString.trim()) {
  86. getPmUser();
  87. }
  88. }
  89. }
  90. function checkPmUrl() {
  91. ajaxVar5 = getHTTPObject();
  92. //var randomnumber=Math.floor(Math.random()*10000);
  93. if (ajaxVar5 != null) {
  94. link5 = "server.php?get=notificationpmedexists&nick="+nickName;
  95. ajaxVar5.open("GET", link5 , true);
  96. ajaxVar5.onreadystatechange = checkNotificationPm;
  97. ajaxVar5.send(null);
  98. }
  99. }
  100. function doNotificationMention() {
  101. if(ajaxVar2.readyState == 4){
  102. var mentionUser = ajaxVar2.responseText;
  103. if(Notification.permission==="granted") {
  104. var notify = new Notification("You were mentioned by " + mentionUser, { body: ""});
  105. }
  106. }
  107. }
  108. function getMentionUser() {
  109. ajaxVar2 = getHTTPObject();
  110. //var randomnumber=Math.floor(Math.random()*10000);
  111. if (ajaxVar2 != null) {
  112. link2 = "server.php?get=notificationmention&nick="+nickName;
  113. ajaxVar2.open("GET", link2 , true);
  114. ajaxVar2.onreadystatechange = doNotificationMention;
  115. ajaxVar2.send(null);
  116. }
  117. }
  118. function checkNotificationMention() {
  119. if(ajaxVar3.readyState == 4){
  120. var returnMsg = ajaxVar3.responseText;
  121. var compareString = "true";
  122. //console.log(returnMsg);
  123. if(returnMsg.trim() === compareString.trim()) {
  124. getMentionUser();
  125. }
  126. }
  127. }
  128. function checkMentionUrl() {
  129. ajaxVar3 = getHTTPObject();
  130. //var randomnumber=Math.floor(Math.random()*10000);
  131. if (ajaxVar3 != null) {
  132. link3 = "server.php?get=notificationmentionexists&nick="+nickName;
  133. ajaxVar3.open("GET", link3 , true);
  134. ajaxVar3.onreadystatechange = checkNotificationMention;
  135. ajaxVar3.send(null);
  136. }
  137. }
  138. // Implement business logic
  139. function serverWrite() {
  140. ajaxVar = getHTTPObject();
  141. if (ajaxVar != null) {
  142. link = "server.php?nick="+nickName+"&msg="+encodeURIComponent(document.getElementById('msg').value);
  143. ajaxVar.open("GET", link , true);
  144. ajaxVar.send(null);
  145. }
  146. }
  147. // Implement business logic
  148. function serverReload() {
  149. ajaxVar = getHTTPObject();
  150. //var randomnumber=Math.floor(Math.random()*10000);
  151. if (ajaxVar != null) {
  152. link = "server.php?get&nick="+nickName;
  153. ajaxVar.open("GET", link , true);
  154. ajaxVar.onreadystatechange = setAll;
  155. ajaxVar.send(null);
  156. }
  157. }
  158. function MsgScrollDown() {
  159. if(ScrollDown != 1) {
  160. var msgBox = document.getElementById("msgs");
  161. msgBox.scrollTop = msgBox.scrollHeight;
  162. ScrollDown = 1;
  163. }
  164. }
  165. function UpdateTimer() {
  166. serverReload();
  167. MsgScrollDown();
  168. getUserlist();
  169. checkPmUrl();
  170. checkMentionUrl();
  171. setTimeout(UpdateTimer, 1000);
  172. }
  173. function doLogin() {
  174. ajaxVar = getHTTPObject();
  175. if(ajaxVar != null) {
  176. link = "server.php?do=login&nick="+nickName;
  177. ajaxVar.open("GET", link, true);
  178. ajaxVar.onreadystatechange = setHtml;
  179. ajaxVar.send(null);
  180. setTimeout(function() { window.location.reload(); },1000);
  181. }
  182. }
  183. function doClearLog() {
  184. ajaxVar = getHTTPObject();
  185. if(ajaxVar != null) {
  186. link = "server.php?do=clearlog&nick="+nickName;
  187. ajaxVar.open("GET", link, true);
  188. ajaxVar.onreadystatechange = setHtml;
  189. ajaxVar.send(null);
  190. setTimeout(function() { window.location.reload(); },1000);
  191. }
  192. }
  193. function doLogout() {
  194. ajaxVar = getHTTPObject();
  195. if(ajaxVar != null) {
  196. link = "server.php?do=logout&nick="+nickName;
  197. ajaxVar.open("GET", link, true);
  198. ajaxVar.onreadystatechange = setHtml;
  199. ajaxVar.send(null);
  200. setTimeout(function() { window.location.reload(); },1000);
  201. }
  202. }
  203. function wrapBBCode(tag) {
  204. var msgInput = document.getElementById('msg');
  205. var content = msgInput.value;
  206. var selectedContent = content.substring(msgInput.selectionStart, msgInput.selectionEnd);
  207. var beforeContent = content.substring(0, msgInput.selectionStart);
  208. var afterContent = content.substring(msgInput.selectionEnd, content.length);
  209. msgInput.value = beforeContent + '[' + tag + ']' + selectedContent + '[/' + tag + ']' + afterContent;
  210. }