Advertisement
Phillydan25

Chat.js for ESB

Mar 14th, 2017
28
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.12 KB | None | 0 0
  1. var blinkInterval = 1000; // Custom blink delay, 1000ms is default
  2. importScriptPage('MediaWiki:PrivateMessageAlert/code.js', 'dev');
  3.  
  4. importScriptPage('User:Monchoman45/ChatHacks.js', 'community');
  5.  
  6. importScriptPage('User:Madnessfan34537/multikick.js', 'callofduty');
  7.  
  8. importArticles( {
  9. type: 'script',
  10. articles: [
  11. "u:dev:ChatOptions/code.js",
  12. ]
  13. } );
  14. /* ChatPlugins */
  15.  
  16. var ChatPlugins = {
  17. release: {
  18. version: 1.1,
  19. branch: "Stable"
  20. },
  21. models: {
  22. feature: function(id, name, access, script) {
  23. this.enabled = false;
  24. this.id = id;
  25. this.name = name;
  26. this.access = access;
  27. this.script = script;
  28. },
  29. alert: function(text) {
  30. newInlineAlert = new models.InlineAlert();
  31. newInlineAlert.attributes.text = text;
  32. mainRoom.model.chats.add(newInlineAlert);
  33. },
  34. command: function(command, script) {
  35. this.command = command;
  36. this.script = script;
  37. }
  38. },
  39. features: {},
  40. settings: {
  41. release: {
  42. version: 1.0,
  43. branch: "Stable"
  44. },
  45. icons: {
  46. staffIcon: "http://img1.wikia.nocookie.net/__cb20140626173406/gamedezyner/images/6/60/StaffIcon.png",
  47. modIcon: "http://img1.wikia.nocookie.net/__cb20140626173343/gamedezyner/images/8/89/ModIcon.png"
  48. },
  49. sounds: {
  50. pingSound: "https://notificationsounds.com/soundfiles/9461cce28ebe3e76fb4b931c35a169b0/file-sounds-1044-inquisitiveness.mp3"
  51. },
  52. features: {
  53. pings: true
  54. }
  55. },
  56. save: function() {
  57. ChatPlugins.settings.features.pings = ChatPlugins.features.pings.enabled;
  58. api.functions.editPage("User:" + wgUserName + "/ChatPlugins.js", JSON.stringify(ChatPlugins.settings));
  59. },
  60. load: function() {
  61. new ChatPlugins.models.alert("Welcome to Chat Plugins 1.0!");
  62. pagecontents = api.functions.getPageContents("User:" + wgUserName + "/ChatPlugins.js");
  63. if (pagecontents == "error") {
  64. new ChatPlugins.models.alert("There seems to be something wrong with your settings file, or it doesn't exist yet. Default settings have been saved.");
  65. ChatPlugins.save();
  66. } else {
  67. ChatPlugins.settings = JSON.parse(pagecontents);
  68. ChatPlugins.features.pings.enabled = ChatPlugins.settings.features.pings;
  69. ChatPlugins.features.pings.words = ChatPlugins.settings.pings;
  70. }
  71. pagecontents = api.functions.getPageContents("MediaWiki:ChatPluginsSettings.js");
  72. if (pagecontents != "error") {
  73. wikicustom = JSON.parse(pagecontents);
  74. if (typeof(wikicustom.settings) != "object") {
  75. new ChatPlugins.models.alert("This wiki has a custom settings page, but it is broken.");
  76. } else {
  77. ChatPlugins.settings.icons = wikicustom.settings.icons; //Load Wiki-specific icons
  78. ChatPlugins.settings.sounds = wikicustom.settings.sounds; //Load Wiki-specific sounds
  79. new ChatPlugins.models.alert("This wiki has custom settings and they have been applied.");
  80. }
  81.  
  82. }
  83. }
  84. };
  85. // Call API
  86. function callAPI(data, method, callback) {
  87. data.format = 'json';
  88. $.ajax({
  89. data: data,
  90. dataType: 'json',
  91. url: wgScriptPath + '/api.php',
  92. type: method,
  93. success: function(response) {
  94. if (response.error)
  95. showError('API error: ' + response.error.info);
  96. else
  97. callback(response);
  98. },
  99. error: function(xhr, error) {
  100. showError('AJAX error: ' + error);
  101. }
  102. });
  103. }
  104. //Inline-mod tools
  105. function scrollToBottom() {
  106. var chat = document.getElementById('Chat_' + mainRoom.roomId);
  107. chat.scrollTop = chat.scrollHeight;
  108. }
  109. ChatPlugins.features.modIcons = new ChatPlugins.models.feature(null, "Mod Icons", 0, function(chat) {
  110. var time = new Date();
  111. var hours = time.getHours();
  112. var minutes = time.getMinutes();
  113. var seconds = time.getSeconds();
  114. if ( hours < 10) hours = '0' + hours;
  115. if (minutes < 10) minutes = "0" + minutes;
  116. if (seconds < 10) seconds = "0" + seconds;
  117. mainRoom.viewDiscussion.chatUL.children().last().children(".message").attr('msg-source', chat.attributes.text);
  118. mainRoom.viewDiscussion.chatUL.children().last().children(".message").attr('msg-time', hours + ':' + minutes + ':' + seconds);
  119. var icon = '';''
  120. mainRoom.viewDiscussion.chatUL.children().last().children('.message').hover(
  121. function() {
  122. thistarget = this;
  123. username = $(thistarget).parent().attr("data-user");
  124. timestamp = $(thistarget).attr('msg-time');
  125. message = $(thistarget).attr('msg-source');
  126. $(thistarget).append('<span class="inline-quote" style="color: #3cd7fa !important;cursor:pointer;">&amp;nbsp;&amp;nbsp;Quote</span>');
  127. $(thistarget).children('.inline-quote').click(function(e) {
  128. if ( e.shiftKey ) {
  129. $('.message textarea').val($('.message textarea').val() + '[' + timestamp + '] ' + username + ": " + message.replace(/^\/me/, "* " + username) + '\n');
  130. } else {
  131. $('.message textarea').val('[' + timestamp + '] ' + username + ": " + message.replace(/^\/me/, "* " + username) + '\n');
  132. scrollToBottom();
  133. }
  134. $(".message textarea").focus();
  135. });
  136.  
  137. },
  138. function() {
  139. $(this).children('.inline-quote').remove();
  140. }
  141. );
  142. }
  143. );
  144. //Bind function to chat updates
  145. setTimeout(function() {
  146. mainRoom.model.chats.bind('afteradd', ChatPlugins.features.modIcons.script, mainRoom.viewDiscussion);
  147. }, 15000);
  148.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement