mmmturkeybacon Unclick Radio Button

Allows you to unclick (i.e. clear, deselected, uncheck) a radio button by clicking on the radio button or the radio buttons label. This script is a helpful companion to mmmturkeybacon Embiggen Radio Buttons and Checkboxes.

  1. // ==UserScript==
  2. // @name mmmturkeybacon Unclick Radio Button
  3. // @author mmmturkeybacon
  4. // @description Allows you to unclick (i.e. clear, deselected, uncheck) a radio button by clicking on the radio button or the radio buttons label. This script is a helpful companion to mmmturkeybacon Embiggen Radio Buttons and Checkboxes.
  5. // @namespace http://userscripts.org/users/523367
  6. // @match http://*/*
  7. // @match https://*/*
  8. // @exclude https://*.surveymonkey.com/*
  9. // @require https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js
  10. // @version 1.00
  11. // @grant GM_log
  12. // ==/UserScript==
  13.  
  14. //NOTE: surveymonkey radio buttons already allow themselves to be unclicked (cleared).
  15.  
  16. $(window).load(function()
  17. {
  18. var is_already_checked = null;
  19. /* When a label that surrounds a radio button is clicked, it triggers a radio button click,
  20. * which triggers another label click, so it needs to be debounced. */
  21. var is_in_bounce_interval = false;
  22.  
  23.  
  24. $(document).on('mousedown', 'input[type="radio"]', function(event)
  25. {
  26. is_already_checked = $(this).is(':checked')
  27. });
  28.  
  29. $(document).on('click', 'input[type="radio"]', function(event)
  30. {
  31. is_in_bounce_interval = true;
  32. setTimeout(function(){is_in_bounce_interval = false;}, 0);
  33. if ($(this).is(':checked') && is_already_checked)
  34. {
  35. $(this).attr('checked', null);
  36. }
  37. });
  38.  
  39.  
  40. $(document).on('click', 'label', function(event)
  41. {
  42. var $this = $(this);
  43. var id = $this.attr('for');
  44.  
  45. if (id)
  46. {
  47. var $radio = $('input[id="'+id+'"][type="radio"]');
  48. }
  49. else
  50. {
  51. var $radio = $this.find('input[type="radio"]');
  52. }
  53.  
  54. is_already_checked = $radio.is(':checked');
  55. if (is_already_checked && !is_in_bounce_interval)
  56. {
  57. event.preventDefault();
  58. $radio.attr('checked', null);
  59. }
  60. });
  61. });

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址