Advertisement
Guest User

Untitled

a guest
Apr 28th, 2016
31
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 77.61 KB | None | 0 0
  1. // ==UserScript==
  2. // @name RPH Tools
  3. // @namespace https://openuserjs.org/scripts/shuffyiosys/RPH_Tools
  4. // @version 2.3.2a
  5. // @description Adds extended settings to RPH
  6. // @match http://chat.rphaven.com/
  7. // @copyright (c)2014 shuffyiosys@github
  8. // @grant none
  9. // @license MIT license (https://en.wikipedia.org/wiki/MIT_License)
  10. // ==/UserScript==
  11. /*jshint multistr: true */
  12. /*jshint bitwise: false*/
  13. /*global $:false */
  14.  
  15. var RPHT_AUTO_JOIN = 1;
  16. var RPHT_PING_BOLD = 2;
  17. var RPHT_PING_ITALICS = 4;
  18. var RPHT_PING_EXACT_MATCH = 8;
  19. var RPHT_PING_CASE_SENSE = 16;
  20. var RPHT_NO_PM_ICONS = 32;
  21. var RPHT_SHOW_NAMES = 64;
  22. var RPHT_NO_ROOM_ICONS = 128;
  23. var RPHT_CLEANUP_RECONNECT = 256;
  24. var RPHT_DIE_MIN = 1;
  25. var RPHT_DIE_MAX = 10;
  26. var RPHT_DIE_SIDE_MIN = 2;
  27. var RPHT_DIE_SIDE_MAX = 100;
  28. var RPHT_RNG_NUM_MIN = -4294967296;
  29. var RPHT_RNG_NUM_MAX = 4294967296;
  30.  
  31. /*****************************************************************************
  32. * Variables for persistent storage
  33. /***************************************************************************/
  34. /****************************************************************************
  35. Array that holds all of the user name settings. The settings itself are
  36. stored in a JSON object.
  37. "pings": Names/Words/etc. to use for pinging
  38. "ping_url": URL to the audio source for pinging
  39. "color": Text color to use when a match is found
  40. "highlight": background color to use when a match is found
  41. "flags": Bitmask of option flags.
  42. 0 - Settings have been modified
  43. 1 - Bold text
  44. 2 - Italicize text
  45. 3 - Use exact matching
  46. 4 - Case sensitive matching
  47. 5 - Remove room links in chat.
  48. 6 - Show names in chat tabs and textbox
  49. 7 - Remove icons in chat
  50. *****************************************************************************/
  51. var scriptSettings = {
  52. "pings" : "",
  53. "ping_url" : "http://chat.rphaven.com/sounds/boop.mp3",
  54. "color" : "#000",
  55. "highlight" : "#FFA",
  56. "flags" : 0,
  57. "pmPingUrl" : "http://chat.rphaven.com/sounds/imsound.mp3",
  58. "favRooms" : [],
  59. };
  60.  
  61. var blockedUsers = [];
  62.  
  63. /* Object for dialog box */
  64. var settingsDialog = {};
  65.  
  66. var validSettings = true;
  67.  
  68. var settingsChanged = false;
  69.  
  70. var pingSound = null;
  71.  
  72. var awayMessages = {};
  73.  
  74. var roomNamePairs = {};
  75.  
  76. var autoJoinTimer = null;
  77.  
  78. var versString = 'RPH Tools 2.3.2a';
  79.  
  80. var html =
  81. '<style>' +
  82. '.rpht_headers{cursor: pointer; padding-left: 5px; background: #43698D; width: 99%; border-radius: 3px; color:#FFF;}' +
  83. '.rpht_textarea{background: rgb(255, 255, 255); height: 80px; width: 403px;}' +
  84. '.rpht-block {text-align: right; margin-top: 10px;}' +
  85. '.rpht-block label { display: inline-block; font-size: 1em; margin-right: 10px; }' +
  86. '.rpht-block input[type=checkbox] { width: 14px; margin-right: 286px;}' +
  87. '</style>' +
  88. '<div id="settingsBox" style="display: none; position: absolute; top: 35px; z-index: 9999999; height: 500px; width: 450px; border-radius: 10px; box-shadow: 0px 2px 5px rgba(0, 0, 0, 0.7); right: 85px; background: url(&quot;http://www.rphaven.com/css/img/aero-bg.png&quot;) repeat scroll 0px 0px transparent; padding: 5px;" left="">' +
  89. '<h3 style="text-align: center; color:#000;">RPH Tools</h3>' +
  90. '<div id="settingsContainer" style="height: 470px; width: 100%; overflow: auto; background: rgb(51, 51, 51); padding: 10px; border-radius: 5px; font-size: 0.8em;">' +
  91. '<h3 class="rpht_headers" id="chatSettingsHeader">Chat room</h3>' +
  92. /* Chat Settings */
  93. '<div id="chatSettingsForm" style="display:none;">' +
  94. '<p style="border-bottom: 2px solid #EEE;">' +
  95. '<span style="background: #333; position: relative; top: 0.7em;"><strong>User text color</strong>&nbsp;</span>' +
  96. '</p>' +
  97. '<div class="rpht-block"><label>Username:</label><select style="width: 300px;" id="userColorDroplist"></select></div>'+
  98. '<div class="rpht-block"><label>Text color:</label><input style="width: 300px;" type="text" id="userNameTextColor" name="userNameTextColor" value="#111"></div>' +
  99. '<div class="rpht-block"><button type="button" id="userNameTextColorButton">Set color</button></div>' +
  100. '<p style="border-bottom: 2px solid #EEE;">' +
  101. '<span style="background: #333; position: relative; top: 0.7em;"><strong>Pings</strong>&nbsp;</span>' +
  102. '</p><br />' +
  103. '<p>Names to be pinged (comma separated)</p>' +
  104. '<textarea id="pingNames" class="rpht_textarea" name="pingNames"> </textarea>' +
  105. '<br /><br />' +
  106. '<div class="rpht-block"><label>Ping URL: </label><input style="width: 370px;" type="text" id="pingURL" name="pingURL"></div>' +
  107. '<div class="rpht-block"><label>Text Color: </label><input style="width: 370px;" type="text" id="pingTextColor" name="pingTextColor" value="#000"></div>' +
  108. '<div class="rpht-block"><label>Highlight: </label><input style="width: 370px;" type="text" id="pingHighlightColor" name="pingHighlightColor" value="#FFA"></div>' +
  109. '<br>' +
  110. '<p>Matching options</p> <br/>' +
  111. '<input style="width: 40px;" type="checkbox" id="pingBoldEnable" name="pingBoldEnable"><strong>Bold</strong>' +
  112. '<input style="width: 40px;" type="checkbox" id="pingItalicsEnable" name="pingItalicsEnable"><em>Italics</em>' +
  113. '<input style="width: 40px;" type="checkbox" id="pingExactMatch" name="pingExactMatch">Exact match' +
  114. '<input style="width: 40px;" type="checkbox" id="pingCaseSense" name="pingCaseSense">Case sensitive' +
  115. '<br /><br />' +
  116. '<p style="border-bottom: 2px solid #EEE;">' +
  117. '<span style="background: #333; position: relative; top: 0.7em;"><strong>Auto Join Favorite Rooms</strong>&nbsp; </span>' +
  118. '</p>' +
  119. '<div class="rpht-block"><label>Enable Auto Join: </label><input type="checkbox" id="favEnable" name="favEnable"></div>' +
  120. '<div class="rpht-block"><label>Username: </label><select style="width: 300px;" id="favUserList"></select></div>'+
  121. '<div class="rpht-block"><label>Room: </label><input style="width: 370px;" type="text" id="favRoom" name="favRoom"></div>' +
  122. '<div class="rpht-block"><label>Password: </label><input style="width: 370px;" type="text" id="favRoomPw" name="favRoomPw"></div>' +
  123. '<div class="rpht-block"><button type="button" id="favAdd">Add</button></div>'+
  124. '<p>Favorite rooms</p>' +
  125. '<select style="width: 403px;" id="favRoomsList" size="5"></select><br><br>' +
  126. '<div class="rpht-block"><button type="button" id="favRemove">Remove</button></div>'+
  127. '<br>' +
  128. '<p style="border-bottom: 2px solid #EEE;">' +
  129. '<span style="background: #333; position: relative; top: 0.7em;"><strong>Other Settings</strong>&nbsp; </span>' +
  130. '</p><br />' +
  131. '<div class="rpht-block"><label>Chat history: </label><input style="width: 300px;" type="number" id="chatHistory" name="chatHistory" max="65535" min="10" value="300"><br /><br /></div>' +
  132. '<div class="rpht-block"><label>No image icons in chat</label><input style="margin-right: 10px;" type="checkbox" id="imgIconDisable" name="imgIconDisable"></div>' +
  133. '<div class="rpht-block"><label>Show username in tabs & textbox (requires rejoin)</label><input style="margin-right: 10px;" type="checkbox" id="showUsername" name="showUsername"></div>' +
  134. /*'<div class="rpht-block"><label>Cleanup on reconnect</label><input style="margin-right: 10px;" type="checkbox" id="cleanupOnReconnect" name="cleanupOnReconnect"></div>' +*/
  135. '</div>' +
  136. '<br />' +
  137. /* PM Settings */
  138. '<h3 class="rpht_headers" id="pmSettingsHeader">PM</h3>' +
  139. '<div id="pmSettingsForm" style="display:none;">'+
  140. '<p style="border-bottom: 2px solid #EEE;">' +
  141. '<span style="background: #333; position: relative; top: 0.7em;"><strong>PM Away System</strong>&nbsp; </span>' +
  142. '</p><br />' +
  143. '<p>Username</p>' +
  144. '<select style="width: 403px;" id="pmNamesDroplist" size="5"></select><br><br>' +
  145. '<div class="rpht-block"><label>Away Message: </label><input style="width: 300px;" type="text" id="awayMessageTextbox" name="awayMessageTextbox" maxlength="300" placeholder="Away message..."></div>' +
  146. '<div class="rpht-block"><button type="button" id="setAwayButton">Enable</button> <button type="button" id="removeAwayButton">Disable</button></div>' +
  147. '<br /><br />' +
  148. '<p style="border-bottom: 2px solid #EEE;">' +
  149. '<span style="background: #333; position: relative; top: 0.7em;"><strong>Other Settings</strong>&nbsp; </span>' +
  150. '</p><br />' +
  151. '<div class="rpht-block"><label>PM Sound: </label><input style="width: 300px;" type="text" id="pmPingURL" name="pmPingURL"></div><br />' +
  152. '<div class="rpht-block"><label>Mute PMs: </label><input type="checkbox" id="pmMute" name="pmMute"></div><br />' +
  153. '<div class="rpht-block"><label>No Image Icons: </label><input type="checkbox" id="pmIconsDisable" name="pmIconsDisable"></div>' +
  154. '</div>' +
  155. '<br />' +
  156. /* RNG */
  157. '<h3 class="rpht_headers" id="rngHeader">Random Number Generators</h3>' +
  158. '<div id="rngForm" style="display:none;">' +
  159. '<p style="border-bottom: 2px solid #EEE;">' +
  160. '<span style="background: #333; position: relative; top: 0.7em;"><strong>Type</strong>&nbsp;</span>' +
  161. '</p> <br />' +
  162. '<form>' +
  163. '<input style="width: 50px;" type="radio" name="rng" value="coin" id="coinRadio"> Coin tosser' +
  164. '<input style="width: 50px;" type="radio" name="rng" value="dice" id="diceRadio" checked> Dice roller' +
  165. '<input style="width: 50px;" type="radio" name="rng" value="rng" id="rngRadio"> General RNG' +
  166. '</form>' +
  167. '<p style="border-bottom: 2px solid #EEE;">' +
  168. '<span style="background: #333; position: relative; top: 0.7em;"><strong>Options</strong>&nbsp;</span>' +
  169. '</p> <br />' +
  170. '<div id="diceOptions">' +
  171. '<div class="rpht-block"><label>Number of die </label><input style="width: 300px;" type="number" id="diceNum" name="diceNum" max="10" min="1" value="2"></div>'+
  172. '<div class="rpht-block"><label>Sides </label><input style="width: 300px;" type="number" id="diceSides" name="diceSides" max="100" min="2" value="6"></div>'+
  173. '<div class="rpht-block"><label>Show Totals:</label><input type="checkbox" id="showRollTotals" name="showRollTotals"></div>' +
  174. '</div>' +
  175. '<div id="rngOptions" style="display: none;">' +
  176. '<div class="rpht-block"><label>Minimum: </label><input style="width: 300px;" type="number" id="rngMinNumber" name="rngMinNumber" max="4294967295" min="-4294967296" value="0"></div>' +
  177. '<div class="rpht-block"><label>Maximum: </label><input style="width: 300px;" type="number" id="rngMaxNumber" name="rngMaxNumber" max="4294967295" min="-4294967296" value="10"></div>' +
  178. '</div>' +
  179. '<div class="rpht-block"><button type="button" id="rngButton">Let\'s roll!</button></div>' +
  180. '</div>' +
  181. '<br />' +
  182. '<h3 class="rpht_headers" id="blockHeader">Blocking</h3>' +
  183. '<div id="blockForm" style="display:none;">' +
  184. '<p style="border-bottom: 2px solid #EEE;">' +
  185. '<span style="background: #333; position: relative; top: 0.7em;"><strong>Block</strong>&nbsp;</span>' +
  186. '</p>' +
  187. '<div class="rpht-block"><label>User:</label><input style="width: 400px;" type="text" id="nameCheckTextbox" name="nameCheckTextbox" placeholder="User to block"></div>' +
  188. '<div class="rpht-block"><button style="margin-left: 357px;" type="button" id="blockButton">Block</button></div></ br>' +
  189. '<br />' +
  190. '<p>Blocked users</p>' +
  191. '<select style="width: 100%;" size="5" id="blockedDropList"></select>' +
  192. '<div class="rpht-block"><button style="margin-left: 341px;" type="button" id="unblockButton">Unblock</button></div>' +
  193. '</div>' +
  194. '<br />' +
  195. /* Modding */
  196. '<h3 class="rpht_headers" id="moddingHeader">Modding</h3>' +
  197. '<div id="moddingForm" style="display:none;">' +
  198. '<p style="border-bottom: 2px solid #EEE;">' +
  199. '<span style="background: #333; position: relative; top: 0.7em;"><strong>Mod Commands</strong>&nbsp;</span>' +
  200. '</p><br />' +
  201. '<p>This will only work if you\'re actually a mod and you own the user name.</p>' +
  202. '<br />' +
  203. '<div class="rpht-block"><label>Room-Name pair</label> <select style="width: 300px;" id="roomModSelect">' +
  204. '<option value=""></option>' +
  205. '</select></div>' +
  206. '<div class="rpht-block"><label>Room:</label><input style="width: 300px;" type="text" id="modRoomTextInput" placeholder="Room"></div>' +
  207. '<div class="rpht-block"><label>Mod name:</label><input style="width: 300px;" type="text" id="modFromTextInput" placeholder="Your mod name"></div>' +
  208. '<div class="rpht-block"><label>Message:</label><input style="width: 300px;" type="text" id="modMessageTextInput" placeholder="Message"></div>' +
  209. '<br/><br/>' +
  210. '<p>Perform action on these users (semicolon separated with no space between): </p>' +
  211. '<textarea name="modTargetTextInput" id="modTargetTextInput" class="rpht_textarea"></textarea>' +
  212. '<br />' +
  213. '<div class="rpht-block">' +
  214. '<button type="button" id="resetPassword">Reset PW</button>' +
  215. '<button style="margin-left: 30px;" type="button" id="kickButton">Kick</button>' +
  216. '<button style="margin-left: 30px;" type="button" id="banButton">Ban</button>' +
  217. '<button style="margin-left: 6px;" type="button" id="unbanButton">Unban</button>' +
  218. '<button style="margin-left: 30px;" type="button" id="modButton">Mod</button>' +
  219. '<button style="margin-left: 6px;" type="button" id="unmodButton">Unmod</button></div>' +
  220. '</div>' +
  221. '<br />' +
  222. /* Script settings */
  223. '<h3 class="rpht_headers" id="importExportHeader">Script Settings</h3>' +
  224. '<div id="importExportForm" style="display:none;">' +
  225. '<br />' +
  226. '<p>Press "Export" to export savable settings.</p>' +
  227. '<p>To import settings, paste them into the text box and press "Import".</p><br />' +
  228. '<textarea name="importExportText" id="importExportTextarea" class="rpht_textarea" ></textarea>' +
  229. '<div class="rpht-block">' +
  230. '<button style="float: left;" type="button" id="exportButton">Export</button>' +
  231. '<button style="float: right;"type="button" id="importButton">Import</button>' +
  232. '</div>' +
  233. '<br />' +
  234. '<p style="border-bottom: 2px solid #EEE;">' +
  235. '<span style="background: #333; position: relative; top: 0.7em;"></span>' +
  236. '</p><br />' +
  237. /*'<button type="button" id="printSettingsButton">Print settings</button> (open console to see settings) <br /><br />' +*/
  238. '<button type="button" id="deleteSettingsButton">Delete settings</button>' +
  239. '<br /><br/>' +
  240. '</div>' +
  241. '<br />' +
  242. /* About */
  243. '<h3 class="rpht_headers" id="aboutHeader">About</h3>' +
  244. '<div id="aboutHelpForm" style="display:none;">' +
  245. '<br><p>Click on the "Settings" button again to save your settings!</p>' +
  246. '<p>You may need to refresh the chat for the settings to take effect.</p>' +
  247. '<br><p><a href="http://www.rphaven.com/topics.php?id=1#topic=1883&page=1" target="_blank">Report a problem</a> |' +
  248. '<a href="https://openuserjs.org/scripts/shuffyiosys/RPH_Tools#troubleshooting" target=_blank">Troubleshooting Tips</a> | '+ versString +'</p><br>' +
  249. '<br>' +
  250. '</div>' +
  251. '<br />' +
  252. '</div>' +
  253. '</div>';
  254.  
  255. /* If this doesn't print, something happened with the global vars */
  256. console.log('RPH Tools start');
  257.  
  258. /****************************************************************************
  259. * MAIN FUNCTIONS
  260. ****************************************************************************/
  261. /***************************************************************************
  262. * @brief: Called when connection to chat is established. If it is, it will
  263. * inject the ping settings form to the chat and restore any saved
  264. * settings
  265. ***************************************************************************/
  266. $(function() {
  267. scriptSettings.flags = RPHT_SHOW_NAMES;
  268.  
  269. _on('accounts', function() {
  270. ProcessAccountEvt(account);
  271. });
  272.  
  273. _on('ignores', function(data) {
  274. ProcessIngoresEvt(data);
  275. });
  276.  
  277. chatSocket.on('confirm-room-join', function(data) {
  278. RoomJoinSetup(data);
  279. });
  280.  
  281. _on('pm', function(data) {
  282. HandleIncomingPm(data);
  283. });
  284.  
  285. _on('outgoing-pm', function(data) {
  286. HandleOutgoingPm(data);
  287. });
  288.  
  289. chatSocket.on('user-kicked', function(data){
  290. for(var i=0; i < account.users.length; i++){
  291. if (data.targetid == account.users[i]){
  292. $('<div class="inner"><p>You were kicked from '+data.room+'.<br />'+ ' Reason: '+ data.msg + '.</p></div>').dialog().dialog('open');
  293. }
  294. }
  295. });
  296.  
  297. chatSocket.on('user-banned', function(data){
  298. for(var i=0; i < account.users.length; i++){
  299. if (data.targetid == account.users[i]){
  300. $('<div class="inner"><p>You were banned from '+data.room+'.<br />'+ ' Reason: '+ data.msg + '.</p></div>').dialog().dialog('open');
  301. }
  302. }
  303. });
  304.  
  305. InitRphTools();
  306. });
  307.  
  308. /*****************************************************************************
  309. * @brief: Further initialize the script after receiving an account data blob.
  310. ***************************************************************************/
  311. function InitRphTools(){
  312. /* Set up HTML injection. */
  313. $('#random-quote').hide();
  314. $('a.settings').hide();
  315. $('#top p.right').prepend('<a class="pings settings">Settings</a>');
  316. $('body').append(html);
  317.  
  318. InitSettingsDialog();
  319. LoadSettings();
  320.  
  321. console.log('RPH Tools[InitRphTools]: Init complete, setting up dialog box');
  322. SetUpToolsDialog();
  323. }
  324.  
  325. /****************************************************************************
  326. * 2. GUI SETUP FUNCTION
  327. ****************************************************************************/
  328. /****************************************************************************
  329. * @brief: Sets up all the ping dialog box GUI handling.
  330. ****************************************************************************/
  331. function SetUpToolsDialog() {
  332. ChatSettingsSetup();
  333. PmSettingsSetup();
  334. DiceRollSetup();
  335. BlockingSetup();
  336. ModdingSetup();
  337. ImportExportSetup();
  338. AboutFormSetup();
  339.  
  340. PopulateSettingsDialog();
  341. setTimeout(ReblockList, 60*1000);
  342.  
  343. if (GetFlagState(RPHT_AUTO_JOIN) === true){
  344. autoJoinTimer = setInterval(JoinFavoriteRooms, 5*1000);
  345. }
  346. console.log('RPH Tools[SetUpToolsDialog]: Dialog box setup complete. RPH Tools is now ready.');
  347. }
  348.  
  349. /****************************************************************************
  350. * @brief Sets up the chat settings group.
  351. *
  352. * @note Anything that deals with flags is listed by bit order for sanity's
  353. * sake
  354. ****************************************************************************/
  355. function ChatSettingsSetup() {
  356. settingsDialog.chat.button.click(function() {
  357. if (settingsDialog.chat.state === true) {
  358. settingsDialog.chat.form.hide();
  359. settingsDialog.chat.state = false;
  360. }
  361. else{
  362. settingsDialog.chat.form.show();
  363. settingsDialog.chat.state = true;
  364. }
  365. });
  366.  
  367. $('#pingNames').blur(function() {
  368. scriptSettings.pings = $('#pingNames').val().replace('\n','').replace('\r','');
  369. settingsChanged = true;
  370. });
  371.  
  372. $('#pingURL').blur(function() {
  373. UpdateChatPmSetting('pingURL', 'ping_url');
  374. });
  375.  
  376. $('#pingTextColor').blur(function() {
  377. UpdateChatPmSetting('pingTextColor', 'color');
  378. });
  379.  
  380. $('#pingHighlightColor').blur(function() {
  381. UpdateChatPmSetting('pingHighlightColor', 'highlight');
  382. });
  383.  
  384. $('#pingBoldEnable').change(function() {
  385. ToggleFlag(RPHT_PING_BOLD);
  386. });
  387.  
  388. $('#pingItalicsEnable').change(function() {
  389. ToggleFlag(RPHT_PING_ITALICS);
  390. });
  391.  
  392. $('#pingExactMatch').change(function() {
  393. ToggleFlag(RPHT_PING_EXACT_MATCH);
  394. });
  395.  
  396. $('#pingCaseSense').change(function() {
  397. ToggleFlag(RPHT_PING_CASE_SENSE);
  398. });
  399.  
  400. $('#showUsername').change(function() {
  401. ToggleFlag(RPHT_SHOW_NAMES);
  402. });
  403.  
  404. $('#imgIconDisable').change(function() {
  405. ToggleFlag(RPHT_NO_ROOM_ICONS);
  406. });
  407.  
  408. $('#favEnable').click(function(){
  409. ToggleFlag(RPHT_AUTO_JOIN);
  410. SaveChatSettings();
  411. });
  412.  
  413. $('#favAdd').click(function(){
  414. AddFavoriteRoom();
  415. });
  416.  
  417. $('#favRemove').click(function(){
  418. RemoveFavoriteRoom();
  419. });
  420.  
  421. $('#userNameTextColorButton').click(function() {
  422. ChangeTextColor();
  423. });
  424.  
  425. $('#chatHistory').change(function() {
  426. rph.setSetting('maxHistory', parseInt($(this).val()) );
  427. });
  428. }
  429.  
  430. /****************************************************************************
  431. * @brief Sets up PM settings dialog
  432. *
  433. * @note Anything that deals with flags is listed by bit order for sanity's
  434. * sake
  435. ****************************************************************************/
  436. function PmSettingsSetup() {
  437. settingsDialog.pm.button.click(function() {
  438. if (settingsDialog.pm.state === true) {
  439. settingsDialog.pm.form.hide();
  440. settingsDialog.pm.state = false;
  441. }
  442. else{
  443. settingsDialog.pm.form.show();
  444. settingsDialog.pm.state = true;
  445. }
  446. });
  447.  
  448. $('#pmPingURL').change(function(){
  449. UpdateChatPmSetting('pmPingURL', 'pmPingUrl');
  450. });
  451.  
  452. $('#pmMute').change(function(){
  453. if ($('#pmMute').is(":checked")){
  454. $('#im-sound').children("audio").attr('src', '');
  455. }
  456. else {
  457. $('#im-sound').children("audio").attr('src', scriptSettings.pmPingUrl);
  458. }
  459. });
  460.  
  461. $('#pmIconsDisable').change(function() {
  462. ToggleFlag(RPHT_NO_PM_ICONS);
  463. });
  464.  
  465. $('#pmNamesDroplist').change(function() {
  466. var userId = $('#pmNamesDroplist option:selected').val();
  467. var message = '';
  468.  
  469. if (awayMessages[userId] !== undefined) {
  470. message = awayMessages[userId].message;
  471. }
  472. $('input#awayMessageTextbox').val(message);
  473. });
  474.  
  475. $('#setAwayButton').click(function() {
  476. SetPmAway();
  477. });
  478.  
  479. $('#removeAwayButton').click(function() {
  480. RemovePmAway();
  481. });
  482. }
  483.  
  484. /****************************************************************************
  485. * @brief: Sets up the GUI callbacks and behavior for the RNGs.
  486. ****************************************************************************/
  487. function DiceRollSetup() {
  488. settingsDialog.rng.button.click(function() {
  489. if (settingsDialog.rng.state === true) {
  490. settingsDialog.rng.form.hide();
  491. settingsDialog.rng.state = false;
  492. }
  493. else{
  494. settingsDialog.rng.form.show();
  495. settingsDialog.rng.state = true;
  496. }
  497. });
  498.  
  499. $('#diceNum').blur(function() {
  500. var dieNum = parseInt($('#diceNum').val());
  501. if (dieNum < RPHT_DIE_MIN) {
  502. $('#diceNum').val(RPHT_DIE_MIN);
  503. }
  504. else if (RPHT_DIE_MAX < dieNum) {
  505. $('#diceNum').val(RPHT_DIE_MAX);
  506. }
  507. });
  508.  
  509. $('#diceSides').blur(function() {
  510. var dieSides = parseInt($('#diceSides').val());
  511. if (dieSides < RPHT_DIE_SIDE_MIN) {
  512. $('#diceSides').val(RPHT_DIE_SIDE_MIN);
  513. }
  514. else if (RPHT_DIE_SIDE_MAX < dieSides) {
  515. $('#diceSides').val(RPHT_DIE_SIDE_MAX);
  516. }
  517. });
  518.  
  519. $('#rngMinNumber').blur(function() {
  520. var minNum = parseInt($('#rngMinNumber').val());
  521. if (minNum < RPHT_RNG_NUM_MIN) {
  522. $('#rngMinNumber').val(RPHT_RNG_NUM_MIN);
  523. }
  524. else if (RPHT_RNG_NUM_MAX < minNum) {
  525. $('#rngMinNumber').val(RPHT_RNG_NUM_MAX);
  526. }
  527. });
  528.  
  529. $('#rngMaxNumber').blur(function() {
  530. var maxNum = parseInt($('#rngMaxNumber').val());
  531. if (maxNum < RPHT_RNG_NUM_MIN) {
  532. $('#rngMaxNumber').val(RPHT_RNG_NUM_MIN);
  533. }
  534. else if (RPHT_RNG_NUM_MAX < maxNum) {
  535. $('#rngMaxNumber').val(RPHT_RNG_NUM_MAX);
  536. }
  537. });
  538.  
  539. $('#rngButton').click(function() {
  540. if ($('#coinRadio')[0].checked) {
  541. RunRNG('coin');
  542. }
  543. else if ($('#diceRadio')[0].checked) {
  544. RunRNG('dice');
  545. }
  546. else if ($('#rngRadio')[0].checked) {
  547. RunRNG('rng');
  548. }
  549. });
  550.  
  551. $('#coinRadio').change(function() {
  552. ChangeRngDisplay('coin');
  553. });
  554. $('#diceRadio').change(function() {
  555. ChangeRngDisplay('dice');
  556. });
  557. $('#rngRadio').change(function() {
  558. ChangeRngDisplay('rng');
  559. });
  560.  
  561. }
  562.  
  563. /****************************************************************************
  564. * @brief: Sets up the GUI callbacks and behavior for blocking
  565. ****************************************************************************/
  566. function BlockingSetup() {
  567. settingsDialog.blocking.button.click(function() {
  568. if (settingsDialog.blocking.state === true) {
  569. settingsDialog.blocking.form.hide();
  570. settingsDialog.blocking.state = false;
  571. }
  572. else{
  573. settingsDialog.blocking.form.show();
  574. settingsDialog.blocking.state = true;
  575. }
  576. });
  577.  
  578. $('#blockButton').click(function() {
  579. var userName = $('#nameCheckTextbox').val();
  580. BlockUserByName(userName);
  581. });
  582.  
  583. $('#unblockButton').click(function() {
  584. RemoveFromBlockList();
  585. });
  586. }
  587.  
  588. /****************************************************************************
  589. * @brief: Sets up the GUI callbacks and behavior for modding functions
  590. ****************************************************************************/
  591. function ModdingSetup() {
  592. settingsDialog.modding.button.click(function() {
  593. if (settingsDialog.modding.state === true) {
  594. settingsDialog.modding.form.hide();
  595. settingsDialog.modding.state = false;
  596. }
  597. else{
  598. settingsDialog.modding.form.show();
  599. settingsDialog.modding.state = true;
  600. }
  601. });
  602.  
  603. $('#roomModSelect').change(function() {
  604. var roomModPair_sel = document.getElementById("roomModSelect");
  605. var roomModVal = roomModPair_sel.options[roomModPair_sel.selectedIndex].value;
  606. if (roomNamePairs[roomModVal] !== undefined) {
  607. $('input#modRoomTextInput').val(roomNamePairs[roomModVal].room);
  608. $('input#modFromTextInput').val(roomNamePairs[roomModVal].modName);
  609. }
  610. else{
  611. $('input#modRoomTextInput').val("");
  612. $('input#modFromTextInput').val("");
  613. }
  614. });
  615.  
  616. $('#resetPassword').click(function(){
  617. var room = $('input#modRoomTextInput').val();
  618. var user = $('input#modFromTextInput').val();
  619. getUserByName($('input#modFromTextInput').val(), function(User) {
  620. var userId = User.props.id;
  621. chatSocket.emit('modify', {room:room, userid:userId, props:{pw:false}});
  622. });
  623. });
  624.  
  625. $('#kickButton').click(function() {
  626. ModAction('kick');
  627. });
  628.  
  629. $('#banButton').click(function() {
  630. ModAction('ban');
  631. });
  632.  
  633. $('#unbanButton').click(function() {
  634. ModAction('unban');
  635. });
  636.  
  637. $('#modButton').click(function() {
  638. ModAction('add-mod');
  639. });
  640.  
  641. $('#unmodButton').click(function() {
  642. ModAction('remove-mod');
  643. });
  644. }
  645.  
  646. /****************************************************************************
  647. * @brief: Sets up callback functions for importing/exporting settings
  648. ****************************************************************************/
  649. function ImportExportSetup() {
  650. settingsDialog.importExport.button.click(function() {
  651. if (settingsDialog.importExport.state === true) {
  652. settingsDialog.importExport.form.hide();
  653. settingsDialog.importExport.state = false;
  654. }
  655. else{
  656. settingsDialog.importExport.form.show();
  657. settingsDialog.importExport.state = true;
  658. }
  659. });
  660.  
  661. $('#importButton').click(function() {
  662. ImportSettings();
  663. });
  664.  
  665. $('#exportButton').click(function() {
  666. ExportSettings();
  667. });
  668.  
  669. $('#printSettingsButton').click(function() {
  670. PrintSettings();
  671. });
  672.  
  673. $('#deleteSettingsButton').click(function(){
  674. DeleteSettings();
  675. });
  676. }
  677.  
  678. /****************************************************************************
  679. * @brief: Sets up callback functions for the about area
  680. ****************************************************************************/
  681. function AboutFormSetup(){
  682. settingsDialog.about.button.click(function() {
  683. if (settingsDialog.about.state === true) {
  684. settingsDialog.about.form.hide();
  685. settingsDialog.about.state = false;
  686. }
  687. else{
  688. settingsDialog.about.form.show();
  689. settingsDialog.about.state = true;
  690. }
  691. });
  692. }
  693.  
  694. /****************************************************************************
  695. * @brief Populates the dialog with settings from the gathered settings.
  696. *
  697. * @param user_id - ID of username
  698. ****************************************************************************/
  699. function PopulateSettingsDialog() {
  700. $('#pingNames').val(scriptSettings.pings);
  701. $('#pingURL').val(scriptSettings.ping_url);
  702. $('#pingTextColor').val(scriptSettings.color);
  703. $('#pingHighlightColor').val(scriptSettings.highlight);
  704. $('#pmPingURL').val(scriptSettings.pmPingUrl);
  705.  
  706. $('input#favEnable').prop("checked", GetFlagState(RPHT_AUTO_JOIN));
  707. $('input#pingBoldEnable').prop("checked", GetFlagState(RPHT_PING_BOLD));
  708. $('input#pingItalicsEnable').prop("checked", GetFlagState(RPHT_PING_ITALICS));
  709. $('input#pingExactMatch').prop("checked", GetFlagState(RPHT_PING_EXACT_MATCH));
  710. $('input#pingCaseSense').prop("checked", GetFlagState(RPHT_PING_CASE_SENSE));
  711. $('input#pmIconsDisable').prop("checked", GetFlagState(RPHT_NO_PM_ICONS));
  712. $('input#showUsername').prop("checked", GetFlagState(RPHT_SHOW_NAMES));
  713. $('inputimgIconDisable').prop("checked", GetFlagState(RPHT_NO_ROOM_ICONS));
  714.  
  715. for(var i = 0; i < scriptSettings.favRooms.length; i++){
  716. var favRoomObj = scriptSettings.favRooms[i];
  717. $('#favRoomsList').append(
  718. '<option value="' + favRoomObj._id + '">' +
  719. favRoomObj.user + ": " + favRoomObj.room + '</option>'
  720. );
  721. }
  722.  
  723. if (scriptSettings.favRooms.length >= 10){
  724. $('#favAdd').text("Favorites Full");
  725. $('#favAdd')[0].disabled = true;
  726. }
  727.  
  728. // Prevents populating the dialogue from counting as a change.
  729. settingsChanged = false;
  730. }
  731.  
  732. /****************************************************************************
  733. * @brief Changes the character's text color.
  734. *
  735. ****************************************************************************/
  736. function ChangeTextColor(){
  737. var text_color = $('input#userNameTextColor').val();
  738. if (ValidateColor(text_color) === false ||
  739. ValidateColorRange(text_color) === false) {
  740. MarkProblem('userNameTextColor', true);
  741. }
  742. else{
  743. var userId = $('#userColorDroplist option:selected').val();
  744.  
  745. text_color = text_color.substring(1,text_color.length);
  746. getUserById(userId, function(User) {
  747. MarkProblem('userNameTextColor', false);
  748. sendToSocket('modify', {userid:User.props.id, color:text_color});
  749. });
  750. }
  751. }
  752.  
  753. /****************************************************************************
  754. * @brief Adds a room and user to the favorite's list
  755. *
  756. ****************************************************************************/
  757. function AddFavoriteRoom(){
  758. var room = getRoom($('#favRoom').val());
  759.  
  760. if (room === undefined){
  761. MarkProblem('favRoom', true);
  762. return;
  763. }
  764.  
  765. if (scriptSettings.favRooms.length < 10){
  766. var favExists = false;
  767. var hashStr = $('#favRoom').val() + $('#favUserList option:selected').html();
  768. var favRoomObj = {
  769. _id: hashStr.hashCode(),
  770. user : $('#favUserList option:selected').html(),
  771. userId: parseInt($('#favUserList option:selected').val()),
  772. room : $('#favRoom').val(),
  773. roomPw : $('#favRoomPw').val()
  774. };
  775.  
  776. MarkProblem('favRoom', false);
  777. if (ArrayObjectIndexOf(scriptSettings.favRooms, "_id", favRoomObj._id) === -1){
  778. $('#favRoomsList').append(
  779. '<option value="' + favRoomObj._id + '">' +
  780. favRoomObj.user + ": " + favRoomObj.room + '</option>'
  781. );
  782. scriptSettings.favRooms.push(favRoomObj);
  783. console.log('RPH Tools[AddFavoriteRoom]: Added favorite room', favRoomObj);
  784. }
  785.  
  786. if (scriptSettings.favRooms.length >= 10){
  787. $('#favAdd').text("Favorites Full");
  788. $('#favAdd')[0].disabled = true;
  789. }
  790. }
  791. SaveChatSettings();
  792. }
  793.  
  794. /****************************************************************************
  795. * @brief Removes a room and user to the favorite's list
  796. *
  797. ****************************************************************************/
  798. function RemoveFavoriteRoom(){
  799. var favItem = document.getElementById("favRoomsList");
  800. var favItemId = $('#favRoomsList option:selected').val();
  801. favItem.remove(favItem.selectedIndex);
  802.  
  803. for(var favs_i = 0; favs_i < scriptSettings.favRooms.length; favs_i++){
  804. if (scriptSettings.favRooms[favs_i]._id == favItemId){
  805. scriptSettings.favRooms.splice(favs_i, 1);
  806. break;
  807. }
  808. }
  809.  
  810. if (scriptSettings.favRooms.length < 10){
  811. $('#favAdd').text("Add");
  812. $('#favAdd')[0].disabled = false;
  813. }
  814.  
  815. SaveChatSettings();
  816. }
  817.  
  818. /****************************************************************************
  819. * @brief Automatically joins rooms in the saved list.
  820. *
  821. ****************************************************************************/
  822. function JoinFavoriteRooms(){
  823. if (roomnames.length > 10){
  824. for(var i = 0; i < scriptSettings.favRooms.length; i++){
  825. var favRoom = scriptSettings.favRooms[i];
  826. chatSocket.emit('join', {name:favRoom.room, userid:favRoom.userId, pw:favRoom.roomPw});
  827. }
  828.  
  829. if (autoJoinTimer !== null){
  830. clearTimeout(autoJoinTimer);
  831. }
  832. }
  833. }
  834.  
  835. /****************************************************************************
  836. PM functions
  837. ****************************************************************************/
  838. /****************************************************************************
  839. * @brief: Sets up PM Away Messages
  840. ****************************************************************************/
  841. function SetPmAway(){
  842. var userId = $('#pmNamesDroplist option:selected').val();
  843. var name = $("#pmNamesDroplist option:selected").html();
  844. if (awayMessages[userId] !== undefined) {
  845. if (awayMessages[userId].enabled === false){
  846. $("#pmNamesDroplist option:selected").html("[Away]" + name);
  847. }
  848. awayMessages[userId].enabled = true;
  849. awayMessages[userId].message = $('input#awayMessageTextbox').val();
  850. $("#pmNamesDroplist option:selected").css("background-color", "#FFD800");
  851. $("#pmNamesDroplist option:selected").prop("selected", false);
  852.  
  853. console.log('RPH Tools[ChatSettingsSetup]: Setting away message for', name, 'with message', awayMessages[userId].message);
  854. }
  855. else{
  856. var awayMsgObj = {
  857. "usedPmAwayMsg" : false,
  858. "message" : "",
  859. "enabled" : true
  860. };
  861. awayMsgObj.message = $('input#awayMessageTextbox').val();
  862. awayMessages[userId] = awayMsgObj;
  863.  
  864. $("#pmNamesDroplist option:selected").html("[Away]" + name);
  865. $("#pmNamesDroplist option:selected").css("background-color", "#FFD800");
  866. $("#pmNamesDroplist option:selected").prop("selected", false);
  867. }
  868. }
  869.  
  870. /****************************************************************************
  871. * @brief: Removes PM away message
  872. ****************************************************************************/
  873. function RemovePmAway(){
  874. var userId = $('#pmNamesDroplist option:selected').val();
  875.  
  876. if (awayMessages[userId] !== undefined) {
  877. if (awayMessages[userId].enabled === true) {
  878. var name = $("#pmNamesDroplist option:selected").html();
  879.  
  880. awayMessages[userId].enabled = false;
  881. $("#pmNamesDroplist option:selected").html(name.substring(6,name.length));
  882. $("#pmNamesDroplist option:selected").css("background-color", "");
  883. $('input#awayMessageTextbox').val("");
  884. console.log('RPH Tools[ChatSettingsSetup]: Remove away message for', name);
  885. }
  886. }
  887. }
  888.  
  889. /****************************************************************************
  890. RNG functions
  891. ****************************************************************************/
  892. /****************************************************************************
  893. * @brief: Changes the RNG options being displayed
  894. * @param: "option", option to be displayed ("coin", "dice", "rng")
  895. ****************************************************************************/
  896. function ChangeRngDisplay(option) {
  897. if (option === 'coin')
  898. {
  899. $('#diceOptions').hide();
  900. $('#rngOptions').hide();
  901. $('#rngButton').text('Flip it!');
  902. }
  903. else if (option === 'dice') {
  904. $('#diceOptions').show();
  905. $('#rngOptions').hide();
  906. $('#rngButton').text('Let\'s roll!');
  907. }
  908. else if (option === 'rng') {
  909. $('#diceOptions').hide();
  910. $('#rngOptions').show();
  911. $('#rngButton').text('Randomize!');
  912. }
  913. }
  914.  
  915. /****************************************************************************
  916. * @brief: Performs an RNG action
  917. * @param: "action", Which RNG action to perform ('coin', 'dice', 'rng')
  918. ****************************************************************************/
  919. function RunRNG(action) {
  920. var class_name = $('li.active')[0].className.split(" ");
  921. var room_name = "";
  922. var this_room = null;
  923. var userID = parseInt(class_name[2].substring(0,6));
  924. var outcomeMsg = '';
  925.  
  926. /* Populate room name based on if showing usernames is checked. */
  927. if (GetFlagState(RPHT_SHOW_NAMES)) {
  928. room_name = $('li.active').find("span:first").text();
  929. }
  930. else {
  931. room_name = $('li.active')[0].textContent.slice(0,-1);
  932. }
  933.  
  934. this_room = getRoom(room_name);
  935.  
  936. if (action == "coin") {
  937. outcomeMsg = Rng_flipCoin();
  938. }
  939. else if (action == "dice") {
  940. outcomeMsg = Rng_rollDice();
  941. }
  942. else if (action == "rng") {
  943. outcomeMsg = Rng_randomNumber();
  944. }
  945.  
  946. outcomeMsg += '\u200b';
  947. this_room.sendMessage(outcomeMsg, userID);
  948. DisableRngButtons(action);
  949. }
  950.  
  951. /****************************************************************************
  952. * @brief: Generates a coin toss
  953. ****************************************************************************/
  954. function Rng_flipCoin(){
  955. var coinMsg = '(( Coin toss: ';
  956. if (Math.ceil(Math.random() * 2) == 2) {
  957. coinMsg += '**heads!**))';
  958. }
  959. else{
  960. coinMsg += '**tails!**))';
  961. }
  962.  
  963. return coinMsg;
  964. }
  965.  
  966. /****************************************************************************
  967. * @brief: Generates a dice roll.
  968. ****************************************************************************/
  969. function Rng_rollDice(){
  970. var totals = 0;
  971. var dieNum = parseInt($('#diceNum').val());
  972. var dieSides = parseInt($('#diceSides').val());
  973. var dieMsg = '/me rolled ' + dieNum + 'd' + dieSides + ':';
  974.  
  975. for(i = 0; i < dieNum; i++) {
  976. var result = Math.ceil(Math.random() * dieSides);
  977. if ($('#showRollTotals')[0].checked) {
  978. totals += result;
  979. }
  980. dieMsg += ' ';
  981. dieMsg += result;
  982. }
  983.  
  984. if ($('#showRollTotals')[0].checked) {
  985. dieMsg += " (Total amount: " + totals + ")";
  986. }
  987.  
  988. return dieMsg;
  989. }
  990.  
  991. /****************************************************************************
  992. * @brief: Generates a random number
  993. ****************************************************************************/
  994. function Rng_randomNumber(){
  995. var minNum = parseInt($('#rngMinNumber').val());
  996. var maxNum = parseInt($('#rngMaxNumber').val());
  997. var ranNumMsg = '(( Random number generated (' + minNum + ' to ' + maxNum + '): **';
  998.  
  999. ranNumMsg += Math.floor((Math.random() * (maxNum - minNum) + minNum)) + '** ))';
  1000.  
  1001. return ranNumMsg;
  1002. }
  1003.  
  1004. /****************************************************************************
  1005. * @brief: Disables the RNG buttons for three seconds.
  1006. ****************************************************************************/
  1007. function DisableRngButtons(action) {
  1008. $('#rngButton').text('Wait...');
  1009. $('#rngRadio')[0].disabled = true;
  1010. $('#diceRadio')[0].disabled = true;
  1011. $('#coinRadio')[0].disabled = true;
  1012. $('#rngButton')[0].disabled = true;
  1013.  
  1014. setTimeout(function() {
  1015. $('#rngRadio')[0].disabled = false;
  1016. $('#diceRadio')[0].disabled = false;
  1017. $('#coinRadio')[0].disabled = false;
  1018. $('#rngButton')[0].disabled = false;
  1019. ChangeRngDisplay(action);
  1020. }, 3000);
  1021. }
  1022.  
  1023. /****************************************************************************
  1024. Blocking Functions
  1025. ****************************************************************************/
  1026. /****************************************************************************
  1027. * @brief: Adds a user to the internal and dialog block list.
  1028. * @param: User - User object for the username being blocked
  1029. ****************************************************************************/
  1030. function AddToBlockList(User) {
  1031. /* Check if this user is already in the list. */
  1032. var inList = false;
  1033.  
  1034. for (var i=0; i < blockedUsers.length; i++) {
  1035. if (User.props.id == blockedUsers[i].id) {
  1036. inList = true;
  1037. }
  1038. }
  1039.  
  1040. if (inList === false) {
  1041. blockedUsers.push({id:User.props.id, name:User.props.name});
  1042. $('#blockedDropList').append('<option value="' + User.props.id + '">' +
  1043. User.props.name + '</option>');
  1044. }
  1045.  
  1046. console.log('RPH Tools[BlockUser]: Blocking user', User.props.name);
  1047. User.blocked = true;
  1048. }
  1049.  
  1050. /****************************************************************************
  1051. * @brief: Removes a user from the internal and dialog block list.
  1052. ****************************************************************************/
  1053. function RemoveFromBlockList(){
  1054. var names = document.getElementById("blockedDropList");
  1055. var userId = $('#blockedDropList option:selected').val();
  1056. UnblockUser(userId);
  1057. names.remove(names.selectedIndex);
  1058. blockedUsers.splice(blockedUsers.indexOf(userId),1);
  1059. SaveBlockSettings();
  1060. }
  1061.  
  1062. /****************************************************************************
  1063. * @brief: Blocks everyone on the list. Used to refresh blocking.
  1064. ****************************************************************************/
  1065. function ReblockList(){
  1066. console.log('RPH Tools[ReblockList]: reblocking everyone');
  1067. for(var i = 0; i < blockedUsers.length; i++){
  1068. BlockUser(blockedUsers[i].id);
  1069. }
  1070. }
  1071.  
  1072. /****************************************************************************
  1073. * @brief: Sets the blocked flag to true for a user.
  1074. * @param: UserId - ID of the user whose ignore settings are being changed
  1075. ****************************************************************************/
  1076. function BlockUser(UserId) {
  1077. getUserById(UserId, function(User) {
  1078. User.blocked = true;
  1079. });
  1080. }
  1081.  
  1082. /****************************************************************************
  1083. * @brief: Sets the blocked flag to false for a user.
  1084. * @param: UserId - ID of the user whose ignore settings are being changed
  1085. ****************************************************************************/
  1086. function UnblockUser(UserId){
  1087. getUserById(UserId, function(User) {
  1088. User.blocked = false;
  1089. });
  1090. }
  1091.  
  1092. /****************************************************************************
  1093. * @brief: Blocks a user by their ID
  1094. * @param: userID - ID of the using being blocked
  1095. ****************************************************************************/
  1096. function BlockUserById(userID) {
  1097. if (userID !== undefined){
  1098. getUserById(userID, function(User) {
  1099. AddToBlockList(User);
  1100. SaveBlockSettings();
  1101. });
  1102. }
  1103. }
  1104.  
  1105. /****************************************************************************
  1106. * @brief: Blocks a user by their name
  1107. * @param: username - username of the using being blocked
  1108. ****************************************************************************/
  1109. function BlockUserByName(username){
  1110. if (username !== undefined){
  1111. getUserByName(username, function(user){
  1112. AddToBlockList(user);
  1113. SaveBlockSettings();
  1114. });
  1115. }
  1116. }
  1117.  
  1118. /****************************************************************************
  1119. Modding Functions
  1120. ****************************************************************************/
  1121. /****************************************************************************
  1122. * @brief: Performs a modding action
  1123. * @param: action - string command that has the action.
  1124. ****************************************************************************/
  1125. function ModAction(action) {
  1126. var targets = $('#modTargetTextInput').val().replace('\n','').replace('\r','');
  1127. targets = targets.split(';');
  1128. console.log('RPH Tools[ModAction]: Performing', action, 'on', targets);
  1129.  
  1130. for(var i = 0; i < targets.length; i++) {
  1131. EmitModAction(action, targets[i]);
  1132. }
  1133. }
  1134.  
  1135. /****************************************************************************
  1136. * @brief: Sends off the mod action
  1137. * @param: action - string command that has the action.
  1138. * @param: targetName - user name that the action is meant for.
  1139. ****************************************************************************/
  1140. function EmitModAction(action, targetName) {
  1141. var room = $('input#modRoomTextInput').val();
  1142. var user = $('input#modFromTextInput').val();
  1143. var userId = 0;
  1144. var targetId = 0;
  1145. var target = '';
  1146. var modMessage = ' ';
  1147.  
  1148. getUserByName(targetName, function(Target) {
  1149. targetId = Target.props.id;
  1150. target = Target.props.name;
  1151. });
  1152.  
  1153. getUserByName($('input#modFromTextInput').val(), function(User) {
  1154. userId = User.props.id;
  1155. modMessage += $("input#modMessageTextInput").val();
  1156.  
  1157. if (action === 'add-mod' || action === 'remove-mod') {
  1158. modMessage = '';
  1159. }
  1160. chatSocket.emit(action, {room:room, userid:userId, targetid:targetId, msg:modMessage});
  1161.  
  1162. if (action === 'ban') {
  1163. modMessage = "Banning: " + target + " by: " + user + " In room: " + room;
  1164. }
  1165. else if (action === 'unban') {
  1166. modMessage = "Unbanning: " + target + " by: " + user + " In room: " + room;
  1167. }
  1168. else if (action === 'add-mod') {
  1169. modMessage = "Modding: " + target + " by: " + user + " In room: " + room;
  1170. }
  1171. else if (action === 'remove-mod') {
  1172. modMessage = "Unmodding: " + target + " by: " + user + " In room: " + room;
  1173. }
  1174. else if (action === 'kick') {
  1175. modMessage = "Kicking: " + target + " by: " + user + " In room: " + room;
  1176. }
  1177. console.log('RPH Tools[EmitModAction]:', modMessage);
  1178. });
  1179. }
  1180.  
  1181. /****************************************************************************
  1182. Script settings functions
  1183. ****************************************************************************/
  1184. /****************************************************************************
  1185. * @brief: Imports settings from the textarea.
  1186. ****************************************************************************/
  1187. function ImportSettings() {
  1188. var settings_str = $('textarea#importExportTextarea').val();
  1189. var chatSettings_str = '';
  1190. var blockedUsers_str = '';
  1191. var temp_scriptSettings;
  1192. var temp_blockedUsers;
  1193. var delimiter = settings_str.indexOf("|");
  1194.  
  1195. try{
  1196. chatSettings_str = settings_str.substring(0, delimiter);
  1197. blockedUsers_str = settings_str.substring(delimiter+1, settings_str.length);
  1198. temp_scriptSettings = JSON.parse(chatSettings_str);
  1199. temp_blockedUsers = JSON.parse(blockedUsers_str);
  1200.  
  1201. /* Time to do a lot of checking here. */
  1202. if ( chatSettings_str === '' || blockedUsers_str === '' ||
  1203. temp_scriptSettings === undefined || temp_blockedUsers === undefined )
  1204. {
  1205. MarkProblem("importExportTextarea", true);
  1206. }
  1207. else{
  1208. ExtractChatPmSettings(temp_scriptSettings);
  1209. ExtractBlockSettings(temp_blockedUsers);
  1210. SaveChatSettings(scriptSettings);
  1211.  
  1212. console.log("RPH Tools[ImportSettings]: Importing blocked list", blockedUsers);
  1213. MarkProblem("importExportTextarea", false);
  1214. PopulateSettingsDialog();
  1215. }
  1216. }
  1217. catch (err) {
  1218. console.log('RPH Tools[ImportSettings]: Error importing settings');
  1219. MarkProblem("importExportTextarea", true);
  1220. }
  1221. }
  1222.  
  1223. /****************************************************************************
  1224. * @brief: Prints out the settings into the main textbox for exporting.
  1225. ****************************************************************************/
  1226. function ExportSettings(){
  1227. var chatSettings_str = JSON.stringify(scriptSettings);
  1228. var blockedUsers_str = JSON.stringify(blockedUsers);
  1229. $('textarea#importExportTextarea').val(chatSettings_str + "|" + blockedUsers_str);
  1230. MarkProblem("importExportTextarea", false);
  1231. }
  1232.  
  1233. /****************************************************************************
  1234. * @brief: Prints out settings in the console.
  1235. ****************************************************************************/
  1236. function PrintSettings(){
  1237. console.log('RPH Tools[SetUpToolsDialog]: Chat settings', scriptSettings);
  1238. console.log('RPH Tools[SetUpToolsDialog]: Blocked users', blockedUsers);
  1239. }
  1240.  
  1241. /****************************************************************************
  1242. * @brief: Deletes settings.
  1243. * @note: The user has to press the button twice to delete.
  1244. ****************************************************************************/
  1245. function DeleteSettings(){
  1246. if (settingsDialog.importExport.deleteConfirm === false){
  1247. $('#deleteSettingsButton').text('Press again to delete');
  1248. settingsDialog.importExport.deleteConfirm = true;
  1249. }
  1250. else if (settingsDialog.importExport.deleteConfirm === true){
  1251. $('#deleteSettingsButton').text('Delete Settings');
  1252. settingsDialog.importExport.deleteConfirm = false;
  1253. localStorage.removeItem("chatSettings");
  1254. localStorage.removeItem("blockedUsers");
  1255.  
  1256. scriptSettings = {
  1257. "pings" : "",
  1258. "ping_url" : "http://chat.rphaven.com/sounds/boop.mp3",
  1259. "color" : "#000",
  1260. "highlight" : "#FFA",
  1261. "flags" : 0,
  1262. "pmPingUrl" : "http://chat.rphaven.com/sounds/imsound.mp3",
  1263. "favRooms" : []
  1264. };
  1265. PopulateSettingsDialog();
  1266. }
  1267. }
  1268.  
  1269. /****************************************************************************
  1270. PM processing functions
  1271. ****************************************************************************/
  1272. /****************************************************************************
  1273. * @brief Handles incoming PMs.
  1274. *
  1275. * @param data - Data containing the PM.
  1276. ****************************************************************************/
  1277. function HandleIncomingPm(data){
  1278. getUserById(data.to, function(fromUser) {
  1279. /* Send away message. */
  1280. if (awayMessages[data.from] !== undefined) {
  1281. if (awayMessages[data.from].enabled === true) {
  1282. var awayMsg = awayMessages[data.from].message;
  1283. awayMessages[data.from].usedPmAwayMsg = true;
  1284. sendToSocket('pm', {'from':data.from, 'to':data.to, 'msg':awayMsg, 'target':'all'});
  1285. }
  1286. }
  1287. });
  1288. }
  1289.  
  1290. /****************************************************************************
  1291. * @brief Handles outgoing PMs.
  1292. *
  1293. * @param data - Data containing the PM.
  1294. ****************************************************************************/
  1295. function HandleOutgoingPm(data){
  1296. getUserById(data.from, function(fromUser) {
  1297. if (awayMessages[data.from] !== undefined) {
  1298. if (awayMessages[data.from].usedPmAwayMsg === false) {
  1299. awayMessages[data.from].enabled = false;
  1300. $('#pmNamesDroplist option').filter(function() {
  1301. return this.value == data.from;
  1302. }).css("background-color", "");
  1303. }
  1304. awayMessages[data.from].usedPmAwayMsg = false;
  1305. }
  1306. });
  1307. }
  1308.  
  1309. /****************************************************************************
  1310. Chat message processing functions
  1311. ****************************************************************************/
  1312. /****************************************************************************
  1313. * @brief: When user joins a room, do the following:
  1314. * - Set up the .onMessage function for pinging
  1315. * - Add the user's name to the chat tab and textarea
  1316. * - Create a room-pair name for the Modding section
  1317. * @param: room - Room that the user has joined
  1318. ****************************************************************************/
  1319. function RoomJoinSetup(room) {
  1320. var thisRoom = getRoom(room.room);
  1321. var userId = GetIdFromChatTab(thisRoom);
  1322.  
  1323. thisRoom.onMessage = function (data) {
  1324. var thisRoom = this;
  1325. if ( account.ignores.indexOf(data.userid) !== -1 ) {
  1326. return;
  1327. }
  1328. PostMessage(thisRoom, data);
  1329. };
  1330.  
  1331. if (GetFlagState(RPHT_SHOW_NAMES)) {
  1332. AddNameToUI(thisRoom, userId);
  1333. }
  1334. AddModFeatures(thisRoom, userId);
  1335. }
  1336.  
  1337. /****************************************************************************
  1338. * @brief: Takes a message received in the chat and modifies it if it has
  1339. * a match for pinging
  1340. * @param: thisRoom - The room that the message is for.
  1341. * @param: data - The message for the room
  1342. ****************************************************************************/
  1343. function PostMessage(thisRoom, data) {
  1344. getUserById(data.userid, function(User) {
  1345. var timestamp = makeTimestamp(data.time);
  1346. var msg = parseMsg(data.msg);
  1347. var classes = '';
  1348. var $el = '';
  1349. var msgHtml = '';
  1350.  
  1351. if ( User.blocked ) {
  1352. return;
  1353. }
  1354.  
  1355. classes = GetClasses(User, thisRoom);
  1356.  
  1357. /* Check if this is a valid RNG */
  1358. if (msg[msg.length-1] === '\u200b'){
  1359. msg += '&nbsp;<span style="background:#4A4; color: #000;">☑</span>';
  1360. }
  1361.  
  1362. /* Add pinging higlights */
  1363. try{
  1364. var testRegex = null;
  1365. testRegex = MatchPing(msg);
  1366.  
  1367. if (testRegex !== null) {
  1368. msg = HighlightPing(msg, testRegex);
  1369. HighlightRoom(thisRoom);
  1370. if (pingSound !== null) {
  1371. pingSound.play();
  1372. }
  1373. }
  1374. }
  1375. catch (err) {
  1376. console.log('RPH Tools[PostMessage]: I tried pinging D:', err);
  1377. msg = parseMsg(data.msg);
  1378. }
  1379.  
  1380. if ( msg.charAt(0) === '/' && msg.slice(1,3) === 'me') {
  1381. classes += 'action ';
  1382. msg = msg.slice(3);
  1383. msgHtml = '<span class="first">[' + timestamp +
  1384. ']</span>\n<span style="color:#' + User.props.color +
  1385. '"><a class="name" title="[' + timestamp +
  1386. ']" style="color:#' + User.props.color +
  1387. '">'+ User.props.name + '</a>' + msg + '</span>';
  1388. } else {
  1389. msgHtml = '<span class="first">[' + timestamp + ']<a class="name" title="[' +
  1390. timestamp + ']" style="color:#' + User.props.color + '">' +
  1391. User.props.name +
  1392. '<span class="colon">:</span></a></span>\n<span style="color:#' +
  1393. User.props.color+'">' + msg +'</span>';
  1394. }
  1395.  
  1396.  
  1397. if (GetFlagState(RPHT_NO_ROOM_ICONS)) {
  1398. $el = AppendMessageTextOnly(msgHtml, thisRoom).addClass(classes);
  1399. }
  1400. else{
  1401. $el = thisRoom.appendMessage(msgHtml).addClass(classes);
  1402. }
  1403. $el.find('br:gt(7)').remove();
  1404. });
  1405. }
  1406.  
  1407. /****************************************************************************
  1408. * @brief: Gets the user name's classes that are applicable to it
  1409. * @param: User - User of the message
  1410. * @param: thisRoom - Room that the message is being sent to
  1411. ****************************************************************************/
  1412. function GetClasses(User, thisRoom) {
  1413. var classes = '';
  1414. if ( User.friendOf ) {
  1415. classes += 'friend ';
  1416. }
  1417. if ( isOwnUser(User) ) {
  1418. classes += 'self ';
  1419. }
  1420. if ( isOwnerOf(thisRoom, User) ) {
  1421. classes += 'owner ';
  1422. } else if ( isModOf(thisRoom, User) ) {
  1423. classes += 'mod ';
  1424. }
  1425. if ( isInGroup(thisRoom, User) ) {
  1426. classes += 'group-member ';
  1427. }
  1428.  
  1429. return classes;
  1430. }
  1431.  
  1432. /****************************************************************************
  1433. * @brief: Checks if the message has any ping terms
  1434. * @param: msg - The message for the chat as a string.
  1435. *
  1436. * @return: Returns the match or null
  1437. ****************************************************************************/
  1438. function MatchPing(msg) {
  1439. var pingNames = scriptSettings.pings.split(',');
  1440. var pingFlags = scriptSettings.flags;
  1441. var regexParam = "m";
  1442.  
  1443. if ((pingFlags & 16) === 0) {
  1444. regexParam = 'im';
  1445. }
  1446.  
  1447. for(i = 0; i < pingNames.length; i++) {
  1448. if (pingNames[i] !== "") {
  1449. var regexPattern = pingNames[i].trim();
  1450. if ((pingFlags & 8) > 0) {
  1451. regexPattern = "\\b" + pingNames[i].trim() + "\\b";
  1452. }
  1453.  
  1454. /* Check if search term is not in a link. */
  1455. if (IsInLink(pingNames[i], msg) === false) {
  1456. var testRegex = new RegExp(regexPattern, regexParam);
  1457. if (msg.match(testRegex)) {
  1458. return testRegex;
  1459. }
  1460. }
  1461. }
  1462. }
  1463.  
  1464. return null;
  1465. }
  1466.  
  1467. /****************************************************************************
  1468. * @brief: Adds highlights to the ping term
  1469. * @param: msg - Message to be sent to the chat.
  1470. * @param: testRegex - Regular expression to use to match the term.
  1471. *
  1472. * @param: Modified msg.
  1473. ****************************************************************************/
  1474. function HighlightPing(msg, testRegex) {
  1475. var pingFlags = scriptSettings.flags;
  1476. var pingColor = scriptSettings.color;
  1477. var pingHighlight = scriptSettings.highlight;
  1478. var boldEnabled = "";
  1479. var italicsEnabled = "";
  1480.  
  1481. if ((pingFlags & 2) > 0) {
  1482. boldEnabled = "font-weight: bold; ";
  1483. }
  1484.  
  1485. if ((pingFlags & 4) > 0) {
  1486. italicsEnabled = "font-style:italic; ";
  1487. }
  1488. msg = msg.replace(testRegex, '<span style="color: ' + pingColor +
  1489. '; background: ' + pingHighlight +'; ' + boldEnabled +
  1490. italicsEnabled + '">' + msg.match(testRegex) + '</span>');
  1491.  
  1492. return msg;
  1493. }
  1494.  
  1495. /****************************************************************************
  1496. * @brief: Adds a highlight to the room's tab
  1497. * @param: thisRoom - Room where the ping happened.
  1498. ****************************************************************************/
  1499. function HighlightRoom(thisRoom) {
  1500. //Don't highlight chat tab if the chat is marked as active.
  1501. var testRegex = new RegExp('active', 'im');
  1502. var className = thisRoom.$tabs[0][0].className;
  1503. var pingColor = scriptSettings.color;
  1504. var pingHighlight = scriptSettings.highlight;
  1505.  
  1506. if (className.search(testRegex) == -1) {
  1507. thisRoom.$tabs[0].css('background-color', pingHighlight);
  1508. thisRoom.$tabs[0].css('color', pingColor);
  1509.  
  1510. thisRoom.$tabs[0].click(function() {
  1511. thisRoom.$tabs[0].css('background-color', '#333');
  1512. thisRoom.$tabs[0].css('color', '#6F9FB9');
  1513.  
  1514. thisRoom.$tabs[0].hover(
  1515. function() {
  1516. thisRoom.$tabs[0].css('background-color', '#6F9FB9');
  1517. thisRoom.$tabs[0].css('color', '#333');
  1518. },
  1519. function() {
  1520. thisRoom.$tabs[0].css('background-color', '#333');
  1521. thisRoom.$tabs[0].css('color', '#6F9FB9');
  1522. });
  1523. });
  1524. }
  1525. }
  1526.  
  1527. /****************************************************************************
  1528. * @brief: Adds user name to chat tab and chat textarea
  1529. * @param: thisRoom - Room that was entered
  1530. * @param: userId - ID of the user that entered
  1531. ****************************************************************************/
  1532. function AddNameToUI(thisRoom, userId) {
  1533. getUserById(userId, function(User) {
  1534. var tabsLen = thisRoom.$tabs.length;
  1535. var idRoomName = thisRoom.$tabs[tabsLen-1][0].className.split(' ')[2];
  1536. var newTabHtml = '<span>' + thisRoom.props.name + '</span><p style="font-size: x-small; position: absolute; top: 12px;">' + User.props.name + '</p>';
  1537. thisRoom.$tabs[tabsLen-1].html(newTabHtml);
  1538. $('<a class="close ui-corner-all">x</a>').on('click', function(ev) {
  1539. ev.stopPropagation();
  1540. chatSocket.emit('leave', {userid:User.props.id, name:thisRoom.props.name});
  1541. }).appendTo( thisRoom.$tabs[tabsLen-1] );
  1542. $('textarea.' + idRoomName).prop('placeholder', 'Post as ' + User.props.name);
  1543. $('textarea.' + idRoomName).css('color', "#" + User.props.color);
  1544.  
  1545. userId = User.props.id;
  1546. userName = User.props.name;
  1547. classes = GetClasses(User, thisRoom);
  1548. console.log('RPH Tools[AddNameToUI]: User class:,', User.props.name, classes);
  1549. });
  1550. }
  1551.  
  1552. /****************************************************************************
  1553. * @brief: Initializes extra features if user is a mod of the room.
  1554. * @param: thisRoom - Room that was entered
  1555. * @param: userId - ID of the user that entered
  1556. ****************************************************************************/
  1557. function AddModFeatures(thisRoom, userId) {
  1558. getUserById(userId, function(User) {
  1559. var classes = GetClasses(User, thisRoom);
  1560. if (classes.indexOf("mod") > -1 ||
  1561. classes.indexOf("owner") > -1 ) {
  1562. var roomNamePair = thisRoom.props.name + ': ' + userName;
  1563. var roomNameValue = thisRoom.props.name + '.' + userId;
  1564. var roomNameObj = {
  1565. 'room': thisRoom.props.name,
  1566. 'modName': userName,
  1567. 'modId': userId
  1568. };
  1569.  
  1570. if (roomNamePairs[roomNameValue] === undefined) {
  1571. roomNamePairs[roomNameValue] = roomNameObj;
  1572. $('#roomModSelect').append('<option value="' + roomNameValue + '">' + roomNamePair + '</option>');
  1573. console.log("RPH Tools[AddModFeatures]: Added room mod pair", roomNamePairs);
  1574. }
  1575. }
  1576. });
  1577. }
  1578.  
  1579. /****************************************************************************
  1580. * UTILITY FUNCTIONS
  1581. ****************************************************************************/
  1582. /****************************************************************************
  1583. * @brief Initializes the data structures and initial event handlers for the
  1584. * main dialog.
  1585. ****************************************************************************/
  1586. function InitSettingsDialog(){
  1587. settingsDialog.dialog = {
  1588. button: $('#top a.pings'),
  1589. form: $('#settingsBox'),
  1590. state: false
  1591. };
  1592.  
  1593. settingsDialog.chat = {
  1594. button: $('#chatSettingsHeader'),
  1595. form: $('#chatSettingsForm'),
  1596. state: false
  1597. };
  1598.  
  1599. settingsDialog.pm = {
  1600. button: $('#pmSettingsHeader'),
  1601. form: $('#pmSettingsForm'),
  1602. state: false
  1603. };
  1604.  
  1605. settingsDialog.rng = {
  1606. button: $('#rngHeader'),
  1607. form: $('#rngForm'),
  1608. state: false
  1609. };
  1610.  
  1611. settingsDialog.blocking = {
  1612. button: $('#blockHeader'),
  1613. form: $('#blockForm'),
  1614. state: false
  1615. };
  1616.  
  1617. settingsDialog.modding = {
  1618. button: $('#moddingHeader'),
  1619. form: $('#moddingForm'),
  1620. state: false
  1621. };
  1622.  
  1623. settingsDialog.importExport = {
  1624. button: $('#importExportHeader'),
  1625. form: $('#importExportForm'),
  1626. state: false,
  1627. deleteConfirm: false
  1628. };
  1629.  
  1630. settingsDialog.about = {
  1631. button: $('#aboutHeader'),
  1632. form: $('#aboutHelpForm'),
  1633. state: false
  1634. };
  1635.  
  1636. settingsDialog.dialog.button.click(function() {
  1637. if (settingsDialog.dialog.state === false)
  1638. {
  1639. settingsDialog.dialog.form.show();
  1640. settingsDialog.dialog.state = true;
  1641. ReblockList();
  1642. }
  1643. else
  1644. {
  1645. if (settingsChanged === true) {
  1646. console.log('RPH Tools[SetUpToolsDialog]: Chat settings were changed', scriptSettings);
  1647. settingsChanged = false;
  1648. if (validSettings === true) {
  1649. SaveChatSettings(scriptSettings);
  1650. }
  1651. }
  1652. else{
  1653. console.log('RPH Tools[SetUpToolsDialog]: No chat settings were changed');
  1654. }
  1655. settingsDialog.dialog.form.hide();
  1656. settingsDialog.dialog.state = false;
  1657. $('#deleteSettingsButton').text('Delete Settings');
  1658. settingsDialog.importExport.deleteConfirm = false;
  1659. }
  1660. });
  1661. }
  1662.  
  1663. /****************************************************************************
  1664. * @brief Processes account events.
  1665. *
  1666. * @param account - Data blob countaining the user's account.
  1667. ****************************************************************************/
  1668. function ProcessAccountEvt(account){
  1669. var users = account.users;
  1670. ClearUsersDropLists();
  1671. for(i = 0; i < users.length; i++) {
  1672. AddUserToDroplist(users[i]);
  1673. }
  1674. console.log('RPH Tools[_on.accounts]: Account data blob received, adding users', users);
  1675. }
  1676.  
  1677. /****************************************************************************
  1678. * @brief Processes ignores events.
  1679. *
  1680. * @param data - Data containing the user being ignored.
  1681. ****************************************************************************/
  1682. function ProcessIngoresEvt(data){
  1683. console.log("RPH Tools[_on.ignores]: Blocking user from ignore button", data.ids[0]);
  1684. if (data.ids[0] !== undefined){
  1685. BlockUserById(data.ids[0]);
  1686. }
  1687. }
  1688.  
  1689. /****************************************************************************
  1690. * @brief Toggles one of the settings flags.
  1691. *
  1692. * @param flag - Flag mask to toggle.
  1693. ****************************************************************************/
  1694. function ToggleFlag(flag){
  1695. scriptSettings.flags ^= flag;
  1696. settingsChanged = true;
  1697. }
  1698.  
  1699. /****************************************************************************
  1700. * @brief Get the state of the flag
  1701. *
  1702. * @param flag - Flag mask to check.
  1703. ****************************************************************************/
  1704. function GetFlagState(flag){
  1705. return ((scriptSettings.flags & flag) > 0);
  1706. }
  1707.  
  1708. /****************************************************************************
  1709. * @brief Tests the ping URL to make sure it ends in .wav, otherwise use
  1710. * the default ping URL (not sure if .mp3 and the like are supported)
  1711. *
  1712. * @param PingURL - URL to test
  1713. ****************************************************************************/
  1714. function ValidateUrl(PingURL) {
  1715. var match = false;
  1716. var regexp = /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/;
  1717. var pingExt = PingURL.slice( (PingURL.length-4), (PingURL.length));
  1718.  
  1719. if (PingURL === '') {
  1720. match = true;
  1721. }
  1722. else if (regexp.test(PingURL) === true) {
  1723. if (pingExt == ".wav" || pingExt == ".ogg" || pingExt == ".mp3") {
  1724. match = true;
  1725. }
  1726. }
  1727. return match;
  1728. }
  1729.  
  1730. /****************************************************************************
  1731. * @brief: Tests the highlight color to make sure it's valid
  1732. * @param: HighlightColor - String representation of the color.
  1733. *
  1734. * @return: Returns boolean if the color matches the regex pattern.
  1735. ****************************************************************************/
  1736. function ValidateColor(HighlightColor) {
  1737. var pattern = new RegExp(/(^#[0-9A-Fa-f]{6}$)|(^#[0-9A-Fa-f]{3}$)/i);
  1738. return pattern.test(HighlightColor);
  1739. }
  1740.  
  1741. /****************************************************************************
  1742. * @brief: Tests the color range of the color to ensure its valid
  1743. * @param: TextColor - String representation of the color.
  1744. *
  1745. * @return: True if the color is within range, false otherwise.
  1746. ****************************************************************************/
  1747. function ValidateColorRange(TextColor) {
  1748. var rawHex = TextColor.substring(1,TextColor.length);
  1749. var red = 255;
  1750. var green = 255;
  1751. var blue = 255;
  1752.  
  1753. /* If the color text is 3 characters, limit it to #DDD */
  1754. if (rawHex.length == 3) {
  1755. red = parseInt(rawHex.substring(0,1), 16);
  1756. green = parseInt(rawHex.substring(1,2), 16);
  1757. blue = parseInt(rawHex.substring(2,3), 16);
  1758.  
  1759. if ((red <= 13) && (green <= 13) && (blue <= 13)) {
  1760. return true;
  1761. }
  1762. }
  1763. /* If the color text is 6 characters, limit it to #D2D2D2 */
  1764. else if (rawHex.length == 6) {
  1765. red = parseInt(rawHex.substring(0,2), 16);
  1766. green = parseInt(rawHex.substring(2,4), 16);
  1767. blue = parseInt(rawHex.substring(4,6), 16);
  1768. if ((red <= 210) && (green <= 210) && (blue <= 210)) {
  1769. return true;
  1770. }
  1771. }
  1772.  
  1773. console.log('RPH Tools[ValidateColorRange]: Color check failed', rawHex, red, green, blue);
  1774. return false;
  1775. }
  1776.  
  1777. /****************************************************************************
  1778. * @brief Adds usernames to droplists.
  1779. * @param user_id - ID of username
  1780. ****************************************************************************/
  1781. function AddUserToDroplist(user_id) {
  1782. getUserById(user_id, function(User) {
  1783. $('#pmNamesDroplist').append('<option value="' + user_id + '">' +
  1784. User.props.name + '</option>');
  1785. $('#userColorDroplist').append('<option value="' + user_id + '">' +
  1786. User.props.name + '</option>');
  1787. $('#favUserList').append('<option value="' + user_id + '">' +
  1788. User.props.name + '</option>');
  1789. });
  1790. }
  1791.  
  1792. /****************************************************************************
  1793. * @brief Clears droplists.
  1794. ****************************************************************************/
  1795. function ClearUsersDropLists(){
  1796. $('#pmNamesDroplist').empty();
  1797. $('#userColorDroplist').empty();
  1798. $('#favUserList').empty();
  1799. }
  1800.  
  1801. /****************************************************************************
  1802. * @brief: Marks if there's a problem or not.
  1803. * @param: element - element ID that has the problem
  1804. * @param: mark - true or false if it has a problem
  1805. ****************************************************************************/
  1806. function MarkProblem(element, mark) {
  1807. if (mark === true) {
  1808. $("#"+element).css('background', '#FF7F7F');
  1809. }
  1810. else{
  1811. $("#"+element).css('background', '#FFF');
  1812. }
  1813. }
  1814.  
  1815. /****************************************************************************
  1816. * @brief: Checks if a search term is in an <a href=...> tag.
  1817. * @param: searchTerm - String to look for
  1818. * @param: msg - msg being searched.
  1819. *
  1820. * @return: True or false if there's a match.
  1821. ****************************************************************************/
  1822. function IsInLink(searchTerm, msg) {
  1823. var regexp = new RegExp('href=".*?' + searchTerm + '.*?"', '');
  1824. return regexp.test(msg);
  1825. }
  1826.  
  1827. /****************************************************************************
  1828. * @brief: Gets the user's ID from the chat tab (it's in the class)
  1829. * @param: thisRoom - Room to get the ID from
  1830. ****************************************************************************/
  1831. function GetIdFromChatTab(thisRoom) {
  1832. var tabsLen = thisRoom.$tabs.length;
  1833. var className = thisRoom.$tabs[tabsLen-1][0].className;
  1834. var charID = className.match(new RegExp(' [0-9]+', ''))[0];
  1835. charID = charID.substring(1,charID.length);
  1836. return parseInt(charID);
  1837. }
  1838.  
  1839. /****************************************************************************
  1840. * @brief Appends message to a room without adding an image icon
  1841. * @param html - HTML to add to the room.
  1842. * @param thisRoom - Object to the room receiving the message.
  1843. *
  1844. * @note This was modified from RPH's original code, which is not covered
  1845. * by this license.
  1846. ****************************************************************************/
  1847. function AppendMessageTextOnly(html, thisRoom) {
  1848. var $el = $('<div>\n'+html+'\n</div>').appendTo( thisRoom.$el );
  1849. var extra = 5; //add more if near the bottom
  1850. if ( thisRoom.$el[0].scrollHeight - thisRoom.$el.scrollTop() < 50 ) {
  1851. extra = 60;
  1852. }
  1853. thisRoom.$el.animate({scrollTop: '+='+($el.outerHeight()+extra)}, 180);
  1854.  
  1855. if ( thisRoom.$el.children('div').length > account.settings.maxHistory ) {
  1856. thisRoom.$el.children('div:not(.sys):lt(3)').remove();
  1857. }
  1858.  
  1859. return $el;
  1860. }
  1861.  
  1862. /****************************************************************************
  1863. * @brief In an array of object, return the first instance where a key
  1864. * matches a value.
  1865. *
  1866. * @param objArray - Array of objects
  1867. * @param key - Key to look for
  1868. * @param value - Value of the key to match
  1869. * @return Index of the first instance where the key matches the value, -1
  1870. * otherwise.
  1871. ****************************************************************************/
  1872. function ArrayObjectIndexOf (objArray, key, value) {
  1873. for(var i = 0; i < objArray.length; i++){
  1874. if (objArray[i][key] === value){
  1875. return i;
  1876. }
  1877. }
  1878. return -1;
  1879. }
  1880.  
  1881. /****************************************************************************
  1882. Chat room and PM settings functions
  1883. ****************************************************************************/
  1884. /****************************************************************************
  1885. * @brief: Updates a chat or PM setting.
  1886. * @param: settingId - ID of which setting this
  1887. * @param: pingSetting - Name of setting in scriptSettings to update.
  1888. ****************************************************************************/
  1889. function UpdateChatPmSetting(settingId, pingSetting){
  1890. var validInput = false;
  1891. var input = $('#'+settingId).val();
  1892.  
  1893. switch(pingSetting){
  1894. case "ping_url":
  1895. case "pmPingUrl":
  1896. validInput = ValidateUrl(input);
  1897. break;
  1898.  
  1899. case "color":
  1900. case "highlight":
  1901. validInput = ValidateColor(input);
  1902. break;
  1903. }
  1904.  
  1905. if (validInput === true){
  1906. scriptSettings[pingSetting] = input;
  1907.  
  1908. switch (pingSetting){
  1909. case "ping_url":
  1910. pingSound = new Audio(scriptSettings.ping_url);
  1911. break;
  1912. case "pmPingUrl":
  1913. $('#im-sound').children("audio").attr('src', input);
  1914. break;
  1915. }
  1916.  
  1917. MarkProblem(settingId, false);
  1918. settingsChanged = true;
  1919. validSettings = true;
  1920. }
  1921. else {
  1922. MarkProblem(settingId, true);
  1923. validSettings = false;
  1924. }
  1925. }
  1926.  
  1927. /****************************************************************************
  1928. * @brief: Extracts the data from locally stored settings.
  1929. * @param: settingsObj - Object that holds the stored settings.
  1930. ****************************************************************************/
  1931. function ExtractChatPmSettings(settingsObj){
  1932. for(var setting in scriptSettings){
  1933. if (settingsObj[setting] !== undefined){
  1934. scriptSettings[setting] = settingsObj[setting];
  1935. }
  1936. }
  1937.  
  1938. pingSound = new Audio(scriptSettings.ping_url);
  1939. $('#im-sound').children("audio").attr('src', scriptSettings.pmPingUrl);
  1940. console.log("RPH Tools[InitRphTools]: Loaded chat settings: ", scriptSettings);
  1941. }
  1942.  
  1943. /****************************************************************************
  1944. * @brief: Extracts the data from locally stored block users list.
  1945. * @param: blockedUsersStorage - Object that holds the stored list.
  1946. ****************************************************************************/
  1947. function ExtractBlockSettings(blockedUsersStorage){
  1948. console.log("RPH Tools[InitRphTools]: Loaded blocked users: ", blockedUsers);
  1949.  
  1950. for (var i = 0; i < blockedUsersStorage.length; i++) {
  1951. console.log("RPH Tools[InitRphTools]: Blocking user ", blockedUsersStorage[i]);
  1952. if (blockedUsersStorage[i] !== "") {
  1953. var user = blockedUsersStorage[i];
  1954. BlockUserById(user.id);
  1955. }
  1956. }
  1957. }
  1958.  
  1959. /****************************************************************************
  1960. * @brief: Saves the chat and PM settings into local storage
  1961. ****************************************************************************/
  1962. function SaveChatSettings() {
  1963. localStorage.setItem("chatSettings", JSON.stringify(scriptSettings));
  1964. console.log("RPH Tools[SaveChatSettings]: Saving chat settings... ", localStorage.getItem("chatSettings"));
  1965. }
  1966.  
  1967. /****************************************************************************
  1968. * @brief: Loads the settings from local storage.
  1969. ****************************************************************************/
  1970. function LoadSettings(){
  1971. if (typeof(storage) != "undefined") {
  1972. if (localStorage.getItem("chatSettings") !== null) {
  1973. var storedSettings = JSON.parse(localStorage.getItem("chatSettings"));
  1974. ExtractChatPmSettings(storedSettings);
  1975. }
  1976.  
  1977. if (localStorage.getItem("blockedUsers") !== null) {
  1978. var blockedUsers = JSON.parse(localStorage.getItem("blockedUsers"));
  1979. ExtractBlockSettings(blockedUsers);
  1980. }
  1981. }
  1982. }
  1983.  
  1984. /****************************************************************************
  1985. * @brief: Saves the blocked users list into local storage.
  1986. ****************************************************************************/
  1987. function SaveBlockSettings() {
  1988. localStorage.setItem("blockedUsers", JSON.stringify(blockedUsers));
  1989. console.log("RPH Tools[SaveBlockSettings]: Saving blocked users (storage, session)",
  1990. localStorage.getItem("blockedUsers"), blockedUsers);
  1991. }
  1992. /****************************************************************************
  1993. * @brief Generates a hash value for a string
  1994. *
  1995. * @note This was modified from https://stackoverflow.com/questions/7616461/generate-a-hash-from-string-in-javascript-jquery
  1996. ****************************************************************************/
  1997. String.prototype.hashCode = function() {
  1998. var hash = 0, i, chr, len;
  1999. if (this.length === 0) return hash;
  2000. for (i = 0, len = this.length; i < len; i++) {
  2001. chr = this.charCodeAt(i);
  2002. hash = ((hash << 31) - hash) + chr;
  2003. hash |= 0; // Convert to 32bit integer
  2004. }
  2005. return hash;
  2006. };
  2007.  
  2008. /****************************************************************************
  2009. * @brief: Creating a new prototype for PM messaging, to make image icons
  2010. * not show up if desired.
  2011. ****************************************************************************/
  2012. Pm.prototype.appendMsg = function(html){
  2013. var $el = $(html);
  2014. this.$msgs.append($el);
  2015. if( this.$typing ){
  2016. $el.insertBefore( this.$typing );
  2017. }
  2018. this.$msgs.animate({scrollTop: '+='+($el.outerHeight()+18)}, 250);
  2019.  
  2020. if (GetFlagState(RPHT_NO_PM_ICONS) === false){
  2021. $el.find('.img-wrapper').each(function(){
  2022. var $this = $(this);
  2023. var url = $this.attr('href');
  2024. var $checker = $('<img src="'+url+'"/>').hide().appendTo('body');
  2025. $checker.load(function(){
  2026. if( $checker.height() <= 90 && $checker.width() <= 120 ){
  2027. $this.replaceWith('<img src="'+url+'" class="smily" />');
  2028. } else {
  2029. $this.before($('<a href="#" />').text('Open in dialog box').bind('click', function(ev){
  2030. ev.preventDefault();
  2031. var matched = html.match(/([http|https]+:\/\/\S*\.(jpg|jpeg|png|gif))/i)[0];
  2032. $('<div class="innerbg smallBorders" style="padding:0 2px;height:100%;"><img src="'+matched+'" /></div>').dialog({
  2033. bgiframe: true, title: 'Image', width: $checker.width()
  2034. });
  2035. }).add(
  2036. $('<span />').text(' - ')
  2037. )
  2038. );
  2039. }
  2040. });
  2041. });
  2042. }
  2043. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement