Greasy Fork is available in English.

CustomChat v2

Un script pour customiser la shoutbox de PMT !

  1. // ==UserScript==
  2. // @name CustomChat v2
  3. // @description Un script pour customiser la shoutbox de PMT !
  4. // @include https://realitygaming.fr/
  5. // @include https://realitygaming.fr/
  6. // @include https://realitygaming.fr/
  7. // @include https://realitygaming.fr/
  8. // @include https://realitygaming.fr/chatbox/
  9. // @include https://realitygaming.fr/chatbox/
  10. // @include https://realitygaming.fr/chatbox/
  11. // @include https://realitygaming.fr/chatbox/
  12. // @version 2.0
  13. // @grant none
  14. // @namespace https://greatest.deepsurf.us/users/47201
  15. // ==/UserScript==
  16.  
  17. $(function() {
  18.  
  19. // chat aliases
  20. var you = 'You';
  21. var robot = 'Buddy';
  22. // slow reply by 400 to 800 ms
  23. var delayStart = 400;
  24. var delayEnd = 800;
  25. // initialize
  26. var bot = new chatBot();
  27. var chat = $('.chat');
  28. var waiting = 0;
  29. $('.busy').text(robot + ' is typing...');
  30. // submit user input and get chat-bot's reply
  31. var submitChat = function() {
  32. var input = $('.input input').val();
  33. if(input == '') return;
  34. $('.input input').val('');
  35. updateChat(you, input);
  36. var reply = bot.respondTo(input);
  37. if(reply == null) return;
  38. var latency = Math.floor((Math.random() * (delayEnd - delayStart)) + delayStart);
  39. $('.busy').css('display', 'block');
  40. waiting++;
  41. setTimeout( function() {
  42. if(typeof reply === 'string') {
  43. updateChat(robot, reply);
  44. } else {
  45. for(var r in reply) {
  46. updateChat(robot, reply[r]);
  47. }
  48. }
  49. if(--waiting == 0) $('.busy').css('display', 'none');
  50. }, latency);
  51. }
  52. // add a new line to the chat
  53. var updateChat = function(party, text) {
  54. var style = 'you';
  55. if(party != you) {
  56. style = 'other';
  57. }
  58. var line = $('<div><span class="party"></span> <span class="text"></span></div>');
  59. line.find('.party').addClass(style).text(party + ':');
  60. line.find('.text').text(text);
  61. chat.append(line);
  62. chat.stop().animate({ scrollTop: chat.prop("scrollHeight")});
  63. }
  64. // event binding
  65. $('.input').bind('keydown', function(e) {
  66. if(e.keyCode == 13) {
  67. submitChat();
  68. }
  69. });
  70. $('.input a').bind('click', submitChat);
  71. // initial chat state
  72. updateChat(robot, 'Hi there. Try typing something!');
  73.  
  74. });