Gmail Basic Select All

Add select all/none button to Gmail Basic

目前为 2016-07-19 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name Gmail Basic Select All
  3. // @namespace mailto:badocelot@badocelot.com
  4. // @description Add select all/none button to Gmail Basic
  5. // @include https://mail.google.com/mail/*/h/*
  6. // @include https://mail.google.com/mail/h/*
  7. // @version 2
  8. // @license MIT/Expat
  9. // @grant none
  10. // ==/UserScript==
  11.  
  12. /* User script to add a "select all/none" button to Gmail Basic
  13. *
  14. * @licstart The following is the entire license notice for the JavaScript
  15. * code in this file.
  16. *
  17. * Copyright (C) 2016 James M. Jensen II
  18. *
  19. * Permission is hereby granted, free of charge, to any person obtaining
  20. * a copy of this software and associated documentation files (the
  21. * "Software"), to deal in the Software without restriction, including
  22. * without limitation the rights to use, copy, modify, merge, publish,
  23. * distribute, sublicense, and/or sell copies of the Software, and to
  24. * permit persons to whom the Software is furnished to do so, subject to
  25. * the following conditions:
  26. *
  27. * The above copyright notice and this permission notice shall be included
  28. * in all copies or substantial portions of the Software.
  29. *
  30. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  31. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  32. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  33. * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
  34. * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  35. * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  36. * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  37. *
  38. * @licend The following is the entire license notice for the JavaScript
  39. * code in this file.
  40. */
  41.  
  42. // So, the way this works is we look up the "Archive" buttons that start the
  43. // bars above and below the email list, and for each one we create a button
  44. // to inject before the archive button.
  45. //
  46. // When the button is clicked, it loops through the checkboxes on each
  47. // conversation and counts how many are checked or unchecked. If the majority
  48. // are checked, it unchecks all of them, and vice versa.
  49.  
  50. function toggleBoxes () {
  51. var i;
  52. var checkboxes = document.getElementsByName('t');
  53.  
  54. // Check whether majority are checked or unchecked to determine
  55. // which way to toggle them
  56. var num_checked = 0;
  57. var num_unchecked = 0;
  58. for (i = 0; i < checkboxes.length; i++) {
  59. if (checkboxes[i].checked) {
  60. num_checked++;
  61. } else {
  62. num_unchecked++;
  63. }
  64. }
  65.  
  66. var shouldCheck;
  67. if (num_unchecked < num_checked) {
  68. shouldCheck = false;
  69. } else {
  70. shouldCheck = true;
  71. }
  72.  
  73. // (un)check all checkboxes
  74. for (i = 0; i < checkboxes.length; i++) {
  75. var c = checkboxes[i];
  76. c.checked = shouldCheck;
  77. }
  78. }
  79.  
  80. var archButtons = document.getElementsByName('nvp_a_arch');
  81. for (var i = 0; i < archButtons.length; i++) {
  82. var btn = archButtons[i];
  83. var toggle = document.createElement('button');
  84. toggle.type = 'button';
  85. toggle.innerHTML = '&#x2714;';
  86. // hack to fix the right-side gap -- I have no idea why this is necessary
  87. toggle.style.marginRight = '6px';
  88. toggle.onclick = toggleBoxes;
  89. var buttonRow = btn.parentElement;
  90. buttonRow.insertBefore(toggle, btn);
  91. }