替换localhost为IP

用IP替换localhost,一般是本机IP。

// ==UserScript==
// @license MIT
// @name         替换localhost为IP
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  用IP替换localhost,一般是本机IP。
// @match        http://localhost/*
// @match        https://localhost/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    var savedIPAddress = localStorage.getItem("customIPAddress");
    var ipAddress = savedIPAddress || prompt("Please enter your local IP address:");

    if (ipAddress) {
        localStorage.setItem("customIPAddress", ipAddress);
        var newURL = window.location.href.replace('localhost', ipAddress.trim());
        window.location.href = newURL;
    }
})();