Custom Google Navigation Bar

Choose what you want to see on the Google navigation bar.

当前为 2014-09-29 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Custom Google Navigation Bar
  3. // @description Choose what you want to see on the Google navigation bar.
  4. // @namespace 407d4100-4661-11e4-916c-0800200c9a66
  5. // @grant GM_addStyle
  6. // @grant GM_getValue
  7. // @grant GM_setValue
  8. // @include http://*.google.com/*
  9. // @include https://*.google.com/*
  10. // @version 1.2.0.0
  11. // ==/UserScript==
  12.  
  13. GM_addStyle ( "\
  14. #customNav {\
  15. padding: 24px;\
  16. padding-top: 18px;\
  17. font-size: 14px;\
  18. }\
  19. #customNav_checkboxes {\
  20. font-size: 14px;\
  21. margin-left: 10px;\
  22. }\
  23. #customNav_checkboxes input {\
  24. margin-bottom: 12px;\
  25. margin-right: 8px;\
  26. padding-top: 2px;\
  27. }\
  28. #customNav_head {\
  29. text-align: center;\
  30. margin-top: 0px;\
  31. margin-bottom: 20px;\
  32. font-size: 18px;\
  33. }\
  34. #customNav_sites {\
  35. width: 100%;\
  36. }\
  37. #customNav_sites td {\
  38. width: 70%;\
  39. padding: 5px 10px;\
  40. }\
  41. #customNav_sites td:first-child {\
  42. width: 30%;\
  43. }\
  44. #customNav_sites td input {\
  45. height: 20px;\
  46. width: 100%;\
  47. }\
  48. #customNav p {\
  49. margin-left: 10px;\
  50. }\
  51. #customNav_small {\
  52. color: #c0c0c0;\
  53. font-size: 12px;\
  54. text-align: center;\
  55. }\
  56. #customNav a {\
  57. color: #c0c0c0;\
  58. }\
  59. #customNav_btns {\
  60. text-align: right;\
  61. }\
  62. #customNav_btns input {\
  63. padding: 6px 10px;\
  64. cursor: pointer;\
  65. -moz-border-radius: 2px;\
  66. border-radius: 2px;\
  67. }\
  68. #customNav_apply {\
  69. background: -moz-linear-gradient(top, #58f 0%, #3866ff 100%);\
  70. border: 1px solid #04f;\
  71. color: #fff;\
  72. }\
  73. #customNav_cancel {\
  74. background: -moz-linear-gradient(top, #eee 0%, #ddd 100%);\
  75. border: 1px solid #888;\
  76. margin-right: 4px;\
  77. }\
  78. ");
  79.  
  80. function getParameterByName(name) {
  81. name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
  82. var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
  83. results = regex.exec(location.search);
  84. return results == null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
  85. }
  86. if(getParameterByName("customNav_update") == "true") {
  87. if(getParameterByName("customNav_showApps") == "true") GM_setValue("showApps", true);
  88. else GM_setValue("showApps", false);
  89. if(getParameterByName("customNav_showNotifications") == "true") GM_setValue("showNotifications", true);
  90. else GM_setValue("showNotifications", false);
  91. if(getParameterByName("customNav_showShare") == "true") GM_setValue("showShare", true);
  92. else GM_setValue("showShare", false);
  93. GM_setValue("link1N", decodeURIComponent(getParameterByName("customNav_link1N")));
  94. GM_setValue("link1U", decodeURIComponent(getParameterByName("customNav_link1U")));
  95. GM_setValue("link2N", decodeURIComponent(getParameterByName("customNav_link2N")));
  96. GM_setValue("link2U", decodeURIComponent(getParameterByName("customNav_link2U")));
  97. GM_setValue("link3N", decodeURIComponent(getParameterByName("customNav_link3N")));
  98. GM_setValue("link3U", decodeURIComponent(getParameterByName("customNav_link3U")));
  99. GM_setValue("link4N", decodeURIComponent(getParameterByName("customNav_link4N")));
  100. GM_setValue("link4U", decodeURIComponent(getParameterByName("customNav_link4U")));
  101. GM_setValue("link5N", decodeURIComponent(getParameterByName("customNav_link5N")));
  102. GM_setValue("link5U", decodeURIComponent(getParameterByName("customNav_link5U")));
  103. GM_setValue("link6N", decodeURIComponent(getParameterByName("customNav_link6N")));
  104. GM_setValue("link6U", decodeURIComponent(getParameterByName("customNav_link6U")));
  105. GM_setValue("link7N", decodeURIComponent(getParameterByName("customNav_link7N")));
  106. GM_setValue("link7U", decodeURIComponent(getParameterByName("customNav_link7U")));
  107. GM_setValue("link8N", decodeURIComponent(getParameterByName("customNav_link8N")));
  108. GM_setValue("link8U", decodeURIComponent(getParameterByName("customNav_link8U")));
  109. location.href = location.href.split("?")[0];
  110. }
  111.  
  112. sett_showApps = GM_getValue("showApps") == true;
  113. sett_showNotifications = GM_getValue("showNotifications") == true;
  114. sett_showShare = GM_getValue("showShare") == true;
  115. sett_link1N = GM_getValue("link1N") || "";
  116. sett_link1U = GM_getValue("link1U") || "";
  117. sett_link2N = GM_getValue("link2N") || "";
  118. sett_link2U = GM_getValue("link2U") || "";
  119. sett_link3N = GM_getValue("link3N") || "";
  120. sett_link3U = GM_getValue("link3U") || "";
  121. sett_link4N = GM_getValue("link4N") || "";
  122. sett_link4U = GM_getValue("link4U") || "";
  123. sett_link5N = GM_getValue("link5N") || "";
  124. sett_link5U = GM_getValue("link5U") || "";
  125. sett_link6N = GM_getValue("link6N") || "";
  126. sett_link6U = GM_getValue("link6U") || "";
  127. sett_link7N = GM_getValue("link7N") || "";
  128. sett_link7U = GM_getValue("link7U") || "";
  129. sett_link8N = GM_getValue("link8N") || "";
  130. sett_link8U = GM_getValue("link8U") || "";
  131.  
  132. function testChecked(icon_shown) {
  133. if(icon_shown) return " checked";
  134. return "";
  135. }
  136.  
  137. document.getElementById("fsett").innerHTML += '<a href="javascript:(function(){document.getElementById(\'settingsBackdrop\').style.display = \'block\';document.getElementById(\'settingsPopup\').style.display = \'block\';})();"> Customize Navigation Bar </a>';
  138.  
  139. settingsBackdrop = document.createElement("div");
  140. settingsBackdrop.style.background = "rgba(128,128,128,0.5)";
  141. settingsBackdrop.style.position = "fixed";
  142. settingsBackdrop.style.top = "0px";
  143. settingsBackdrop.style.bottom = "0px";
  144. settingsBackdrop.style.left = "0px";
  145. settingsBackdrop.style.right = "0px";
  146. settingsBackdrop.style.zIndex = "10000000000000" // To get above the search bar
  147. settingsBackdrop.style.display = "none";
  148. settingsBackdrop.setAttribute("id", "settingsBackdrop");
  149. document.body.appendChild(settingsBackdrop);
  150.  
  151. settingsPopup = document.createElement("div");
  152. settingsPopup.style.position = "absolute";
  153. settingsPopup.style.width = "960px";
  154. settingsPopup.style.height = "640px";
  155. settingsPopup.style.background = "#fff";
  156. settingsPopup.style.top = "50%";
  157. settingsPopup.style.left = "50%";
  158. settingsPopup.style.marginTop = "-320px";
  159. settingsPopup.style.marginLeft = "-480px";
  160. settingsPopup.style.zIndex = "10000000000009"; // To get above the search bar
  161. settingsPopup.style.border = "1px solid #777";
  162. settingsPopup.style.boxShadow = "0px 0px 4px #777"
  163. settingsPopup.style.display = "none";
  164. settingsPopup.setAttribute("id", "settingsPopup");
  165. settingsPopup.innerHTML = '<div id="customNav"><h3 id="customNav_head">Google Navigation Bar Settings (v1.2.0)</h3><p>Choose which icons to display on the navigation bar.</p><div id="customNav_checkboxes"><div><input type="checkbox" autocomplete="off" id="customNav_inputApps"'+testChecked(sett_showApps)+'>Display Apps List</div><div><input type="checkbox" autocomplete="off" id="customNav_inputNotifications"'+testChecked(sett_showNotifications)+'>Display Notifications</div><div><input type="checkbox" autocomplete="off" id="customNav_inputShare"'+testChecked(sett_showShare)+'>Display Google+ Share</div></div>\
  166. <p>Choose the links to be displayed on the navigation bar.</p><table id="customNav_sites"><tr><th>Name</th><th>URL</th></tr><tr><td><input autocomplete="off" id="customNav_inputLinkN1"></td><td><input autocomplete="off" id="customNav_inputLinkU1"></td></tr><tr><td><input autocomplete="off" id="customNav_inputLinkN2"></td><td><input autocomplete="off" id="customNav_inputLinkU2"></td></tr><tr><td><input autocomplete="off" id="customNav_inputLinkN3"></td><td><input autocomplete="off" id="customNav_inputLinkU3"></td></tr><tr><td><input autocomplete="off" id="customNav_inputLinkN4"></td><td><input autocomplete="off" id="customNav_inputLinkU4"></td></tr><tr><td><input autocomplete="off" id="customNav_inputLinkN5"></td><td><input autocomplete="off" id="customNav_inputLinkU5"></td></tr><tr><td><input autocomplete="off" id="customNav_inputLinkN6"></td><td><input autocomplete="off" id="customNav_inputLinkU6"></td></tr><tr><td><input autocomplete="off" id="customNav_inputLinkN7"></td><td><input autocomplete="off" id="customNav_inputLinkU7"></td></tr><tr><td><input autocomplete="off" id="customNav_inputLinkN8"></td><td><input autocomplete="off" id="customNav_inputLinkU8"></td></tr></table>\
  167. <p id="customNav_small">Custom Google Navigation Bar is a GreaseMonkey script developed by <a href="https://greasyfork.org/users/5353">Qvcool</a>. Download it at <a href="https://greasyfork.org/scripts/5332">https://greasyfork.org/scripts/5332</a>.</p><div id="customNav_btns"><input id="customNav_cancel" type="button" value="Cancel" onclick="document.getElementById(\'settingsBackdrop\').style.display=\'none\';document.getElementById(\'settingsPopup\').style.display=\'none\';location.reload();"><input id="customNav_apply" type="button" value="Apply" onclick="document.getElementById(\'settingsBackdrop\').style.display=\'none\';document.getElementById(\'settingsPopup\').style.display=\'none\';\
  168. location.href = location.href.split(\'?\')[0]+\'?\'+\'customNav_update=true&&customNav_showApps=\'+document.getElementById(\'customNav_inputApps\').checked+\'&&customNav_showNotifications=\'+document.getElementById(\'customNav_inputNotifications\').checked+\'&&customNav_showShare=\'+document.getElementById(\'customNav_inputShare\').checked+\'&&customNav_link1N=\'+encodeURIComponent(document.getElementById(\'customNav_inputLinkN1\').value)+\'&&customNav_link1U=\'+encodeURIComponent(document.getElementById(\'customNav_inputLinkU1\').value)+\'&&customNav_link2N=\'+encodeURIComponent(document.getElementById(\'customNav_inputLinkN2\').value)+\'&&customNav_link2U=\'+encodeURIComponent(document.getElementById(\'customNav_inputLinkU2\').value)+\'&&customNav_link3N=\'+encodeURIComponent(document.getElementById(\'customNav_inputLinkN3\').value)+\'&&customNav_link3U=\'+encodeURIComponent(document.getElementById(\'customNav_inputLinkU3\').value)+\'&&customNav_link4N=\'+encodeURIComponent(document.getElementById(\'customNav_inputLinkN4\').value)+\'&&customNav_link4U=\'+encodeURIComponent(document.getElementById(\'customNav_inputLinkU4\').value)+\'&&customNav_link5N=\'+encodeURIComponent(document.getElementById(\'customNav_inputLinkN5\').value)+\'&&customNav_link5U=\'+encodeURIComponent(document.getElementById(\'customNav_inputLinkU5\').value)+\'&&customNav_link6N=\'+encodeURIComponent(document.getElementById(\'customNav_inputLinkN6\').value)+\'&&customNav_link6U=\'+encodeURIComponent(document.getElementById(\'customNav_inputLinkU6\').value)+\'&&customNav_link7N=\'+encodeURIComponent(document.getElementById(\'customNav_inputLinkN7\').value)+\'&&customNav_link7U=\'+encodeURIComponent(document.getElementById(\'customNav_inputLinkU7\').value)+\'&&customNav_link8N=\'+encodeURIComponent(document.getElementById(\'customNav_inputLinkN8\').value)+\'&&customNav_link8U=\'+encodeURIComponent(document.getElementById(\'customNav_inputLinkU8\').value);\
  169. "></div></div>';
  170. document.body.appendChild(settingsPopup);
  171.  
  172. document.getElementById("customNav_inputLinkN1").value = sett_link1N;
  173. document.getElementById("customNav_inputLinkU1").value = sett_link1U;
  174. document.getElementById("customNav_inputLinkN2").value = sett_link2N;
  175. document.getElementById("customNav_inputLinkU2").value = sett_link2U;
  176. document.getElementById("customNav_inputLinkN3").value = sett_link3N;
  177. document.getElementById("customNav_inputLinkU3").value = sett_link3U;
  178. document.getElementById("customNav_inputLinkN4").value = sett_link4N;
  179. document.getElementById("customNav_inputLinkU4").value = sett_link4U;
  180. document.getElementById("customNav_inputLinkN5").value = sett_link5N;
  181. document.getElementById("customNav_inputLinkU5").value = sett_link5U;
  182. document.getElementById("customNav_inputLinkN6").value = sett_link6N;
  183. document.getElementById("customNav_inputLinkU6").value = sett_link6U;
  184. document.getElementById("customNav_inputLinkN7").value = sett_link7N;
  185. document.getElementById("customNav_inputLinkU7").value = sett_link7U;
  186. document.getElementById("customNav_inputLinkN8").value = sett_link8N;
  187. document.getElementById("customNav_inputLinkU8").value = sett_link8U;
  188.  
  189. links = [
  190. [sett_link1N, sett_link1U],
  191. [sett_link2N, sett_link2U],
  192. [sett_link3N, sett_link3U],
  193. [sett_link4N, sett_link4U],
  194. [sett_link5N, sett_link5U],
  195. [sett_link6N, sett_link6U],
  196. [sett_link7N, sett_link7U],
  197. [sett_link8N, sett_link8U],
  198. ]
  199.  
  200. var content = "";
  201. for(x in links) {
  202. content += "&emsp;<a style='color: #333;text-decoration: none;' onmouseover='this.style.textDecoration = \"underline\";' onmouseout='this.style.textDecoration = \"none\"' href='" + links[x][1] + "'>" + links[x][0] + "</a>";
  203. } // Meshes all links into a single string
  204.  
  205. var elems = document.getElementsByTagName("div"), i;
  206. for (i in elems) {
  207. if((" " + elems[i].className + " ").indexOf(" gb_zc ") > -1) {
  208. elems[i].innerHTML = content;
  209. } // Adds custom links
  210. else if((" " + elems[i].className + " ").indexOf(" gb_yc ") > -1) {
  211. if(!sett_showApps) elems[i].children[1].style.display = "none";
  212. if(!sett_showNotifications) elems[i].children[2].style.display = "none";
  213. if(!sett_showShare) elems[i].children[3].style.display = "none";
  214. elems[i].style.textAlign = "right";
  215. } // Hides icons
  216. }