InstaSynchP SysMessage Hide

Hides system messages after a short time to reduce spam in the chat

目前为 2015-01-03 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name InstaSynchP SysMessage Hide
  3. // @namespace InstaSynchP
  4. // @description Hides system messages after a short time to reduce spam in the chat
  5.  
  6. // @version 1
  7. // @author Zod-
  8. // @source https://github.com/Zod-/InstaSynchP-SysMessage-Hide
  9. // @license MIT
  10.  
  11. // @include http://*.instasynch.com/*
  12. // @include http://instasynch.com/*
  13. // @include http://*.instasync.com/*
  14. // @include http://instasync.com/*
  15. // @grant none
  16. // @run-at document-start
  17.  
  18. // @require https://greasyfork.org/scripts/5647-instasynchp-library/code/InstaSynchP%20Library.js?version=22833
  19. // ==/UserScript==
  20.  
  21. function SysMessageHide(version) {
  22. "use strict";
  23. this.version = version;
  24. this.name = 'InstaSynchP SysMessage Hide';
  25. this.settings = [{
  26. 'label': 'Hide',
  27. 'id': 'sysmessage-hide',
  28. 'type': 'checkbox',
  29. 'default': true,
  30. 'section': ['Chat', 'System Messages']
  31. }, {
  32. 'label': 'Hide Delay(ms)',
  33. 'id': 'sysmessage-hide-timeout',
  34. 'type': 'int',
  35. 'min': 0,
  36. 'max': 100000,
  37. 'default': 15000,
  38. 'size': 8,
  39. 'section': ['Chat', 'System Messages']
  40. }];
  41. this.hideTimeoutIds = [];
  42. }
  43.  
  44. SysMessageHide.prototype.executeOnce = function() {
  45. "use strict";
  46. var th = this;
  47.  
  48. events.on(th, 'SettingChange[sysmessage-hide]', function(oldVal, newVal) {
  49. $('#chat-messages .system').parent()[newVal ? 'hide' : 'show']();
  50. //stop all the outstanding timeouts
  51. for (var i = 0, len = th.hideTimeoutIds.length; i < len; i += 1) {
  52. clearTimeout(th.hideTimeoutIds[i]);
  53. }
  54. th.hideTimeoutIds = [];
  55. //scroll to the bottom
  56. $('#chat-messages').scrollTop($('#chat-messages')[0].scrollHeight);
  57. });
  58.  
  59. events.on(th, 'AddMessage', function(user) {
  60. if (user.username !== '' || !gmc.get('sysmessage-hide')) {
  61. return;
  62. }
  63. var lastMessage, timeoutId;
  64.  
  65. lastMessage = $('#chat-messages > :last-child');
  66.  
  67. timeoutId = setTimeout(function() {
  68. lastMessage.hide();
  69. th.hideTimeoutIds.shift();
  70. }, gmc.get('sysmessage-hide-timeout'));
  71.  
  72. th.hideTimeoutIds.push(timeoutId);
  73. });
  74. };
  75.  
  76. /*
  77. button to toggle system messages
  78. SysMessageHide.prototype.preConnect = function() {
  79. "use strict";
  80. var th = this;
  81. <a style="
  82. position: absolute;
  83. top: 2px;
  84. right: 17px;
  85. cursor: pointer;
  86. "><img src="http://puu.sh/e1mf9/dd5400a431.png"></a>
  87. $('#chat-messages').before(
  88. $('<a>').append(
  89. $('<img>', {
  90. src: 'http://puu.sh/e1mf9/dd5400a431.png'
  91. })
  92. ).css('cursor', 'pointer').css('top', '2px').css('position', 'absolute').css('right', '17px')
  93. .click(function() {
  94. gmc.set('sysmessage-hide', !gmc.get('sysmessage-hide'));
  95. plugins.settings.save();
  96. })
  97. );
  98. }*/
  99.  
  100. window.plugins = window.plugins || {};
  101. window.plugins.sysMessageHide = new SysMessageHide('1');