Custom Google Navigation Bar

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

目前为 2014-10-09 提交的版本。查看 最新版本

  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.3.2
  11. // ==/UserScript==
  12. customNav_version = "1.3.2";
  13.  
  14.  
  15. GM_addStyle("\
  16. #customNav {\
  17. padding: 24px;\
  18. padding-top: 18px;\
  19. font-size: 14px;\
  20. }\
  21. #customNav_checkboxes {\
  22. font-size: 14px;\
  23. margin-left: 10px;\
  24. }\
  25. #customNav_checkboxes input {\
  26. margin-bottom: 12px;\
  27. margin-right: 8px;\
  28. padding-top: 2px;\
  29. }\
  30. #customNav_head {\
  31. text-align: center;\
  32. margin-top: 5px;\
  33. margin-bottom: 20px;\
  34. font-size: 18px;\
  35. }\
  36. #customNav_sites {\
  37. width: 100%;\
  38. }\
  39. #customNav_sites td {\
  40. width: 70%;\
  41. padding: 5px 10px;\
  42. }\
  43. #customNav_sites td:first-child {\
  44. width: 30%;\
  45. }\
  46. #customNav_sites td input {\
  47. height: 20px;\
  48. width: 100%;\
  49. }\
  50. #customNav p {\
  51. margin-left: 10px;\
  52. }\
  53. #customNav_small {\
  54. color: #c0c0c0;\
  55. font-size: 12px;\
  56. text-align: center;\
  57. }\
  58. #customNav a {\
  59. color: #c0c0c0;\
  60. }\
  61. #customNav_btns {\
  62. text-align: right;\
  63. }\
  64. #customNav_btns input {\
  65. padding: 8px 20px;\
  66. -moz-border-radius: 2px;\
  67. border-radius: 2px;\
  68. font-size: 11px;\
  69. font-weight: bold;\
  70. font-family: 'Arial', sans-serif;\
  71. }\
  72. #customNav_apply {\
  73. background: #4889f0;\
  74. border: 1px solid #3079ed;\
  75. color: #fff;\
  76. }\
  77. #customNav_apply:hover {\
  78. background: -moz-linear-gradient(top, #4d90fe 0%, #357ae8 100%);\
  79. border: 1px solid #2f5bb7;\
  80. }\
  81. #customNav_cancel {\
  82. background: -moz-linear-gradient(top, #f5f5f5 0%, #f1f1f1 100%);\
  83. border: 1px solid #dadada;\
  84. margin-right: 4px;\
  85. }\
  86. #customNav_cancel:hover {\
  87. background: -moz-linear-gradient(top, #f8f8f8 0%, #f1f1f1 100%);\
  88. border: 1px solid #c6c6c6;\
  89. box-shadow: 0px 1px 0px #d9d9d9;\
  90. }\
  91. ");
  92.  
  93. function getParameterByName(name) {
  94. name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
  95. var regex = new RegExp("[\\?&]" + name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]") + "=([^&#]*)"),
  96. results = regex.exec(location.search);
  97. return results == null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
  98. }
  99.  
  100. if(getParameterByName("customNav_update") == "true") {
  101. if(getParameterByName("customNav_showApps") == "true") GM_setValue("showApps", true);
  102. else GM_setValue("showApps", false);
  103. if(getParameterByName("customNav_showNotifications") == "true") GM_setValue("showNotifications", true);
  104. else GM_setValue("showNotifications", false);
  105. if(getParameterByName("customNav_showShare") == "true") GM_setValue("showShare", true);
  106. else GM_setValue("showShare", false);
  107. if(getParameterByName("customNav_newTab") == "true") GM_setValue("newTab", true);
  108. else GM_setValue("newTab", false);
  109. GM_setValue("link1N", decodeURIComponent(getParameterByName("customNav_link1N")));
  110. GM_setValue("link1U", decodeURIComponent(getParameterByName("customNav_link1U")));
  111. GM_setValue("link2N", decodeURIComponent(getParameterByName("customNav_link2N")));
  112. GM_setValue("link2U", decodeURIComponent(getParameterByName("customNav_link2U")));
  113. GM_setValue("link3N", decodeURIComponent(getParameterByName("customNav_link3N")));
  114. GM_setValue("link3U", decodeURIComponent(getParameterByName("customNav_link3U")));
  115. GM_setValue("link4N", decodeURIComponent(getParameterByName("customNav_link4N")));
  116. GM_setValue("link4U", decodeURIComponent(getParameterByName("customNav_link4U")));
  117. GM_setValue("link5N", decodeURIComponent(getParameterByName("customNav_link5N")));
  118. GM_setValue("link5U", decodeURIComponent(getParameterByName("customNav_link5U")));
  119. GM_setValue("link6N", decodeURIComponent(getParameterByName("customNav_link6N")));
  120. GM_setValue("link6U", decodeURIComponent(getParameterByName("customNav_link6U")));
  121. GM_setValue("link7N", decodeURIComponent(getParameterByName("customNav_link7N")));
  122. GM_setValue("link7U", decodeURIComponent(getParameterByName("customNav_link7U")));
  123. GM_setValue("link8N", decodeURIComponent(getParameterByName("customNav_link8N")));
  124. GM_setValue("link8U", decodeURIComponent(getParameterByName("customNav_link8U")));
  125. GM_setValue("link9N", decodeURIComponent(getParameterByName("customNav_link9N")));
  126. GM_setValue("link9U", decodeURIComponent(getParameterByName("customNav_link9U")));
  127. GM_setValue("link10N", decodeURIComponent(getParameterByName("customNav_link10N")));
  128. GM_setValue("link10U", decodeURIComponent(getParameterByName("customNav_link10U")));
  129. location.replace(location.href.split("?")[0]);
  130. }
  131.  
  132. sett_showApps = GM_getValue("showApps");
  133. sett_showNotifications = GM_getValue("showNotifications");
  134. sett_showShare = GM_getValue("showShare");
  135. sett_newTab = GM_getValue("newTab");
  136. sett_link1N = GM_getValue("link1N") || "";
  137. sett_link1U = GM_getValue("link1U") || "";
  138. sett_link2N = GM_getValue("link2N") || "";
  139. sett_link2U = GM_getValue("link2U") || "";
  140. sett_link3N = GM_getValue("link3N") || "";
  141. sett_link3U = GM_getValue("link3U") || "";
  142. sett_link4N = GM_getValue("link4N") || "";
  143. sett_link4U = GM_getValue("link4U") || "";
  144. sett_link5N = GM_getValue("link5N") || "";
  145. sett_link5U = GM_getValue("link5U") || "";
  146. sett_link6N = GM_getValue("link6N") || "";
  147. sett_link6U = GM_getValue("link6U") || "";
  148. sett_link7N = GM_getValue("link7N") || "";
  149. sett_link7U = GM_getValue("link7U") || "";
  150. sett_link8N = GM_getValue("link8N") || "";
  151. sett_link8U = GM_getValue("link8U") || "";
  152. sett_link9N = GM_getValue("link9N") || "";
  153. sett_link9U = GM_getValue("link9U") || "";
  154. sett_link10N = GM_getValue("link10N") || "";
  155. sett_link10U = GM_getValue("link10U") || "";
  156.  
  157. function testChecked(icon_shown) {
  158. if(icon_shown) return " checked";
  159. return "";
  160. }
  161.  
  162. document.getElementById("fsett").innerHTML += '<a href="javascript:(function(){document.getElementById(\'settingsBackdrop\').style.display = \'block\';document.getElementById(\'settingsPopup\').style.display = \'block\';})();"> Customize navigation bar </a>';
  163.  
  164. settingsBackdrop = document.createElement("div");
  165. settingsBackdrop.style.background = "rgba(128,128,128,0.5)";
  166. settingsBackdrop.style.position = "fixed";
  167. settingsBackdrop.style.top = "0px";
  168. settingsBackdrop.style.bottom = "0px";
  169. settingsBackdrop.style.left = "0px";
  170. settingsBackdrop.style.right = "0px";
  171. settingsBackdrop.style.zIndex = "10000000000000" // To get above the search bar
  172. settingsBackdrop.style.display = "none";
  173. settingsBackdrop.setAttribute("id", "settingsBackdrop");
  174. document.body.appendChild(settingsBackdrop);
  175.  
  176. settingsPopup = document.createElement("div");
  177. settingsPopup.style.position = "absolute";
  178. settingsPopup.style.width = "960px";
  179. settingsPopup.style.height = "720px";
  180. settingsPopup.style.background = "#fff";
  181. settingsPopup.style.top = "50%";
  182. settingsPopup.style.left = "50%";
  183. settingsPopup.style.marginTop = "-360px";
  184. settingsPopup.style.marginLeft = "-480px";
  185. settingsPopup.style.zIndex = "10000000000009"; // To get above the search bar
  186. settingsPopup.style.border = "1px solid #777";
  187. settingsPopup.style.boxShadow = "0px 0px 4px #777"
  188. settingsPopup.style.display = "none";
  189. settingsPopup.setAttribute("id", "settingsPopup");
  190. settingsPopup.innerHTML = '<div id="customNav"><h3 id="customNav_head">Custom Google Navigation Bar ' + customNav_version + '</h3><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><input type="checkbox" autocomplete="off" id="customNav_inputTabs"'+testChecked(sett_newTab)+'>Open links in a new tab</div></div>\
  191. <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><tr><td><input autocomplete="off" id="customNav_inputLinkN9"></td><td><input autocomplete="off" id="customNav_inputLinkU9"></td></tr><tr><td><input autocomplete="off" id="customNav_inputLinkN10"></td><td><input autocomplete="off" id="customNav_inputLinkU10"></td></tr></table>\
  192. <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\';\
  193. location.href = location.href.split(\'?\')[0]+\'?customNav_update=true&&customNav_newTab=\'+document.getElementById(\'customNav_inputTabs\').checked+\'&&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)+\'&&customNav_link9N=\'+encodeURIComponent(document.getElementById(\'customNav_inputLinkN9\').value)+\'&&customNav_link9U=\'+encodeURIComponent(document.getElementById(\'customNav_inputLinkU9\').value)+\'&&customNav_link10N=\'+encodeURIComponent(document.getElementById(\'customNav_inputLinkN10\').value)+\'&&customNav_link10U=\'+encodeURIComponent(document.getElementById(\'customNav_inputLinkU10\').value);\
  194. "></div></div>';
  195. document.body.appendChild(settingsPopup);
  196.  
  197. document.getElementById("customNav_inputLinkN1").value = sett_link1N;
  198. document.getElementById("customNav_inputLinkU1").value = sett_link1U;
  199. document.getElementById("customNav_inputLinkN2").value = sett_link2N;
  200. document.getElementById("customNav_inputLinkU2").value = sett_link2U;
  201. document.getElementById("customNav_inputLinkN3").value = sett_link3N;
  202. document.getElementById("customNav_inputLinkU3").value = sett_link3U;
  203. document.getElementById("customNav_inputLinkN4").value = sett_link4N;
  204. document.getElementById("customNav_inputLinkU4").value = sett_link4U;
  205. document.getElementById("customNav_inputLinkN5").value = sett_link5N;
  206. document.getElementById("customNav_inputLinkU5").value = sett_link5U;
  207. document.getElementById("customNav_inputLinkN6").value = sett_link6N;
  208. document.getElementById("customNav_inputLinkU6").value = sett_link6U;
  209. document.getElementById("customNav_inputLinkN7").value = sett_link7N;
  210. document.getElementById("customNav_inputLinkU7").value = sett_link7U;
  211. document.getElementById("customNav_inputLinkN8").value = sett_link8N;
  212. document.getElementById("customNav_inputLinkU8").value = sett_link8U;
  213. document.getElementById("customNav_inputLinkN9").value = sett_link9N;
  214. document.getElementById("customNav_inputLinkU9").value = sett_link9U;
  215. document.getElementById("customNav_inputLinkN10").value = sett_link10N;
  216. document.getElementById("customNav_inputLinkU10").value = sett_link10U;
  217.  
  218. function esc(v) {
  219. return v.replace(new RegExp("&", "g"), "&amp;").replace(new RegExp("<", "g"), "&gt;").replace(new RegExp(">", "g"), "&gt;");
  220. }
  221. function esc2(v) {
  222. return v.replace(new RegExp("'", "g"), "");
  223. }
  224.  
  225. links = [
  226. [esc(sett_link1N), esc2(sett_link1U)],
  227. [esc(sett_link2N), esc2(sett_link2U)],
  228. [esc(sett_link3N), esc2(sett_link3U)],
  229. [esc(sett_link4N), esc2(sett_link4U)],
  230. [esc(sett_link5N), esc2(sett_link5U)],
  231. [esc(sett_link6N), esc2(sett_link6U)],
  232. [esc(sett_link7N), esc2(sett_link7U)],
  233. [esc(sett_link8N), esc2(sett_link8U)],
  234. [esc(sett_link9N), esc2(sett_link9U)],
  235. [esc(sett_link10N), esc2(sett_link10U)]
  236. ]
  237.  
  238. links = links.filter(function(e) {
  239. if(e[0] != "" && e[1] != "") return true;
  240. return false;
  241. });
  242.  
  243. var content = "";
  244. for(x in links) {
  245. content += "&emsp;<a style='color: #333;text-decoration: none;' onmouseover='this.style.textDecoration = \"underline\";' onmouseout='this.style.textDecoration = \"none\"' href='" + links[x][1] + "'" + function(t){if(t) return " target='_blank'"; return ""}(sett_newTab) + ">" + links[x][0] + "</a>";
  246. } // Combines all links into a single string
  247.  
  248. var elems = document.getElementsByTagName("div"), i;
  249. for (i in elems) {
  250. if((" " + elems[i].className + " ").indexOf(" gb_zc ") > -1) {
  251. elems[i].innerHTML = content;
  252. } // Adds custom links
  253. else if((" " + elems[i].className + " ").indexOf(" gb_yc ") > -1) {
  254. if(!sett_showApps) elems[i].children[1].style.display = "none";
  255. if(!sett_showNotifications) elems[i].children[2].style.display = "none";
  256. if(!sett_showShare) elems[i].children[3].style.display = "none";
  257. elems[i].style.textAlign = "right";
  258. } // Hides icons
  259. else if((" " + elems[i].className + " ").indexOf("gb_Ac gb_f gb_Qc gb_Jc") > -1) {
  260. elems[i].style.display = "none";
  261. }
  262. }