Google Chrome - Set New Tab

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

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

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @id              chrome-newtab@loucypher
// @name            Google Chrome - Set New Tab
// @namespace       https://github.com/LouCypher/userscripts
// @description     Set a specified URL as new tab page on Google Chrome.
// @version         2.0
// @author          LouCypher
// @license         MIT License
// @contributionURL http://loucypher.github.io/userscripts/donate.html?Google+Chrome+-+Set+New+Tab
// @homepageURL     https://greasyfork.org/scripts/217
// @supportURL      https://greasyfork.org/scripts/217/feedback
// @resource        CHANGELOG https://raw.github.com/LouCypher/userscripts/master/tampermonkey/set-new-tab/CHANGELOG.txt
// @resource        LICENSE https://raw.github.com/LouCypher/userscripts/master/tampermonkey/set-new-tab/LICENSE.txt
// @match           http://*/*
// @match           https://*/*
// @run-at          document-start
// @grant           GM_getValue
// @grant           GM_setValue
// @grant           GM_registerMenuCommand
// ==/UserScript==

var isDefaultNewTab = /^https?:\/\/www.google.[a-z.]+\/\_\/chrome\/newtab.*/.test(top.location.href);

function setNewTabURL(aMsg, aURL) {
  if (isDefaultNewTab)
    aURL = "";

  var newTabURL = prompt(aMsg, aURL);
  if (newTabURL || newTabURL === "")
    GM_setValue("newTabURL", newTabURL);
}

if (isDefaultNewTab) {
  var newTabURL = GM_getValue("newTabURL", "");
  if (newTabURL) {
    document.documentElement.innerHTML = "<head></head><body></body>";
    location.replace(newTabURL);
  }
}

GM_registerMenuCommand("New Tab: set a new location", function() {
  setNewTabURL("Enter URL as new tab.\n" +
               "Enter 'about:blank' to use a blank page.\n" +
               "Leave it empty to use the default.",
               GM_getValue("newTabURL", ""));
});

GM_registerMenuCommand("New Tab: use current page", function() {
  setNewTabURL("Press 'OK' to use current page or enter a new location as new tab.",
               top.location.href);
});