Greasy Fork 还支持 简体中文。

Gmail Label Hider (pref-based)

Hide certain Gmail labels

  1. // ==UserScript==
  2. // @name Gmail Label Hider (pref-based)
  3. // @namespace http://www.arthaey.com
  4. // @description Hide certain Gmail labels
  5. // @include http://gmail.google.com/*
  6. // @include https://gmail.google.com/*
  7. // @include http://mail.google.com/*
  8. // @include https://mail.google.com/*
  9. // @version 1.3
  10. //
  11. // Backed up from http://userscripts.org/scripts/review/11774
  12. // Last updated on 2007-08-29
  13. //
  14. // Based on Ben Hengst's Gmail Label Hider v0.02
  15. // License: http://creativecommons.org/licenses/GPL/2.0/
  16. //
  17. // HOW TO USE:
  18. //
  19. // Right-click on the Greasemonkey monkey-face to access the "User Script
  20. // Commands" menu. Select the "Set list of Gmail labels to hide" menu item.
  21. //
  22. // At the prompt, type in the list of Gmail labels you want to hide, separated
  23. // by the "|" (pipe) character.
  24. //
  25. // KNOWN BUGS:
  26. //
  27. // - Sometimes the labels don't hide themselves when you open a message. I
  28. // haven't yet investigated why this is happening.
  29. //
  30. // CHANGELOG:
  31. //
  32. // v1.3 - made label names case-insenstive ("drafts" and "Drafts" are the same)
  33. // v1.2 - added ability to hide non-label things like Starred, Drafts, etc.
  34. // v1.1 - added "Show All" and "Hide Some" toggle links
  35. // v1.0 - initial release
  36. //
  37. // ==/UserScript==
  38.  
  39. (function () {
  40.  
  41. var TOGGLE_ID = "NavBar_Labels_ToggleLink";
  42.  
  43. function setLabelList() {
  44. var hideList = GM_getValue('hideList', null);
  45. var list = prompt("List of labels to hide, separated by '|'", hideList);
  46. if (list && list != hideList) {
  47. GM_setValue('hideList', list);
  48. window.location.reload(false);
  49. }
  50. }
  51.  
  52. function hideLabels() {
  53. var hideList = GM_getValue('hideList', null);
  54. if (!hideList) return;
  55.  
  56. var hideLabels = hideList.split('|');
  57. var allDivs = document.evaluate(
  58. "//div[@class='lk cs'] | //div[@class='nl']",
  59. document,
  60. null,
  61. XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,
  62. null);
  63.  
  64. for (var i = 0; i < allDivs.snapshotLength; i++) {
  65. var thisDiv = allDivs.snapshotItem(i);
  66.  
  67. for (var j = 0; j < hideLabels.length; j++) {
  68. var regex = new RegExp("^" + hideLabels[j], "i");
  69.  
  70. if (thisDiv.textContent.match(regex)) {
  71. thisDiv.style.display = "none";
  72. break;
  73. }
  74. }
  75. }
  76.  
  77. toggleLink();
  78. }
  79.  
  80. function showLabels() {
  81. var allDivs = document.evaluate(
  82. "//div[@class='lk cs'] | //div[@class='nl']",
  83. document,
  84. null,
  85. XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,
  86. null);
  87.  
  88. for (var i = 0; i < allDivs.snapshotLength; i++) {
  89. var thisDiv = allDivs.snapshotItem(i);
  90. thisDiv.style.display = "block";
  91. }
  92.  
  93. toggleLink();
  94. }
  95.  
  96. function addLink() {
  97. var editLabelsDiv = document.getElementById("prf_l");
  98. if (!editLabelsDiv) return;
  99.  
  100. var link = document.createElement("div");
  101. link.id = TOGGLE_ID;
  102. link.className = "lk cs";
  103. link.style.textAlign = "right";
  104. toggleLink(link);
  105. editLabelsDiv.parentNode.insertBefore(link, editLabelsDiv);
  106. }
  107.  
  108. function toggleLink(linkObj) {
  109. var link = linkObj;
  110. if (!link) link = document.getElementById(TOGGLE_ID);
  111. if (!link) return;
  112.  
  113. if (link.innerHTML.match(/Hide/)) {
  114. link.innerHTML = "Show All";
  115. link.removeEventListener('click', hideLabels, true);
  116. link.addEventListener('click', showLabels, true);
  117. }
  118. else {
  119. link.innerHTML = "Hide Some";
  120. link.removeEventListener('click', showLabels, true);
  121. link.addEventListener('click', hideLabels, true);
  122. }
  123. }
  124.  
  125. window.addEventListener('load', function() {
  126. GM_registerMenuCommand("Set list of Gmail labels to hide", setLabelList);
  127. addLink();
  128. hideLabels();
  129. }, true);
  130.  
  131. })();