Google Chrome - Set New Tab

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

スクリプトをインストールするには、Tampermonkey, GreasemonkeyViolentmonkey のような拡張機能のインストールが必要です。

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

スクリプトをインストールするには、TampermonkeyViolentmonkey のような拡張機能のインストールが必要です。

スクリプトをインストールするには、TampermonkeyUserscripts のような拡張機能のインストールが必要です。

このスクリプトをインストールするには、Tampermonkeyなどの拡張機能をインストールする必要があります。

このスクリプトをインストールするには、ユーザースクリプト管理ツールの拡張機能をインストールする必要があります。

(ユーザースクリプト管理ツールは設定済みなのでインストール!)

このスタイルをインストールするには、Stylusなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus などの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus tなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

(ユーザースタイル管理ツールは設定済みなのでインストール!)

このスクリプトの質問や評価の投稿はこちら通報はこちらへお寄せください
// ==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.1
// @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==

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

function setNewTabURL(aURL, aMsg) {
  var message = "Enter URL as new tab.\n" +
                "Enter 'about:blank' to use a blank page.\n" +
                "Enter empty string to use browser default.";
  if (aMsg)
    message = aMsg + "\nor\n" + message;

  if (isDefaultNewTab)
    aURL = "";

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

if (isDefaultNewTab) {  // If default new tab
  var newTabURL = GM_getValue("newTabURL", "");
  if (newTabURL) {
    stop(); // in the name of love
    document.documentElement.innerHTML = "<head></head><body></body>";
    location.replace(newTabURL);  // Redirect to a specified new tab
  }
}

GM_registerMenuCommand("New Tab: set a new location", function() {
  setNewTabURL(GM_getValue("newTabURL", ""));
});

if (!isDefaultNewTab) {
  GM_registerMenuCommand("New Tab: use current page", function() {
    setNewTabURL(top.location.href, "Press 'OK' to use current page");
  });
}