Greasy Fork 支持 简体中文。

Google Chrome - Set New Tab

Set a specified URL as new tab page on Google Chrome.

  1. // ==UserScript==
  2. // @id chrome-newtab@loucypher
  3. // @name Google Chrome - Set New Tab
  4. // @namespace https://github.com/LouCypher/userscripts
  5. // @description Set a specified URL as new tab page on Google Chrome.
  6. // @version 2.1
  7. // @author LouCypher
  8. // @license MIT License
  9. // @contributionURL http://loucypher.github.io/userscripts/donate.html?Google+Chrome+-+Set+New+Tab
  10. // @homepageURL https://greasyfork.org/scripts/217
  11. // @supportURL https://greasyfork.org/scripts/217/feedback
  12. // @resource CHANGELOG https://raw.github.com/LouCypher/userscripts/master/tampermonkey/set-new-tab/CHANGELOG.txt
  13. // @resource LICENSE https://raw.github.com/LouCypher/userscripts/master/tampermonkey/set-new-tab/LICENSE.txt
  14. // @match http://*/*
  15. // @match https://*/*
  16. // @run-at document-start
  17. // @grant GM_getValue
  18. // @grant GM_setValue
  19. // @grant GM_registerMenuCommand
  20. // ==/UserScript==
  21.  
  22. const REGEXP = /^https?:\/\/www.google.[a-z.]+\/\_\/chrome\/newtab.*/;
  23. var isDefaultNewTab = REGEXP.test(top.location.href);
  24.  
  25. function setNewTabURL(aURL, aMsg) {
  26. var message = "Enter URL as new tab.\n" +
  27. "Enter 'about:blank' to use a blank page.\n" +
  28. "Enter empty string to use browser default.";
  29. if (aMsg)
  30. message = aMsg + "\nor\n" + message;
  31.  
  32. if (isDefaultNewTab)
  33. aURL = "";
  34.  
  35. var newTabURL = prompt(message, aURL);
  36. if (newTabURL || newTabURL === "")
  37. GM_setValue("newTabURL", newTabURL);
  38. }
  39.  
  40. if (isDefaultNewTab) { // If default new tab
  41. var newTabURL = GM_getValue("newTabURL", "");
  42. if (newTabURL) {
  43. stop(); // in the name of love
  44. document.documentElement.innerHTML = "<head></head><body></body>";
  45. location.replace(newTabURL); // Redirect to a specified new tab
  46. }
  47. }
  48.  
  49. GM_registerMenuCommand("New Tab: set a new location", function() {
  50. setNewTabURL(GM_getValue("newTabURL", ""));
  51. });
  52.  
  53. if (!isDefaultNewTab) {
  54. GM_registerMenuCommand("New Tab: use current page", function() {
  55. setNewTabURL(top.location.href, "Press 'OK' to use current page");
  56. });
  57. }