Advertisement
Guest User

Untitled

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