StopMultipleMessage

Block spam on over-clicking

当前为 2017-11-24 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name StopMultipleMessage
  3. // @namespace Forum
  4. // @author Kmaschta
  5. // @date 19/09/2015
  6. // @version 1.3
  7. // @description Block spam on over-clicking
  8. // @match https://www.dreadcast.net/Main
  9. // @match https://www.dreadcast.net/Forum*
  10. // @match https://www.dreadcast.net/FAQ*
  11. // @require http://code.jquery.com/jquery-latest.min.js
  12. // @grant none
  13. // ==/UserScript==
  14.  
  15. // CHANGELOG
  16. // 1.1: Set cursor to 'wait' when locked
  17. // 1.2: Change DNS to .eu
  18. // 1.3: Change DNS to .net
  19.  
  20. jQuery.noConflict();
  21.  
  22. function unlock_button(elem, onclick, content) {
  23. elem.attr('onclick', onclick);
  24. elem.removeAttr('style');
  25. elem.html(content);
  26. elem.removeClass('locked');
  27. }
  28.  
  29. function lock_button(elem) {
  30. // Save event action
  31. var onclick = elem.attr('onclick');
  32. var content = elem.html();
  33.  
  34. // Lock button
  35. elem.removeAttr('onclick');
  36. elem.unbind('click');
  37. elem.html('Verrouillé');
  38. elem.attr('style', 'cursor: wait;');
  39. elem.addClass('locked');
  40.  
  41. // Still unlock after 5s
  42. var tid = setTimeout(function() {
  43. if(elem.hasClass('locked')) {
  44. unlock_button(elem, onclick, content);
  45. elem.unbind('dblclick');
  46. }
  47. }, 5000);
  48.  
  49. // Unlock button on dbl click
  50. elem.dblclick(function() {
  51. clearTimeout(tid);
  52. unlock_button(elem, onclick, content);
  53. // Rebind lock on click
  54. elem.click(function() { lock_button(elem); });
  55. });
  56. }
  57.  
  58. $(document).ready( function() {
  59. // Forum "Poster" button
  60. $('#zone_reponse .bouton.poster').not('.locked').click(function() {
  61. lock_button($(this));
  62. });
  63.  
  64. // IG "Envoyer" response message
  65. $(document).ajaxComplete(function() {
  66. $('.zone_reponse .btnTxt').not('.locked').unbind('click').click(function() {
  67. lock_button($(this));
  68. });
  69. });
  70.  
  71. console.log('StopMultipleMessage on');
  72. });