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