ブックマークレットでURLスイッチ
テスト環境と本番環境を切り替えるときに便利なブックマークレット
javascript: (function () { const URL_LIST = [ ['http://example.com', 'https://test.example.com'], ['http://sp.example.com', 'http://sptest.example.com'], ]; const url = location.protocol + '//' + location.host; for (let i = 0; i < URL_LIST.length; i++) { for (let j = 0; j < URL_LIST[i].length; j++) { if (url.match(URL_LIST[i][j])) { if (URL_LIST[i].length > j+1) { window.open(URL_LIST[i][j+1] + location.pathname + location.search + location.hash); } else { window.open(URL_LIST[i][0] + location.pathname + location.search + location.hash); } } } } })();
上記の例では
http://example.com → https://test.example.com → http://example.com
http://sp.example.com → http://sptest.example.com → http://sp.example.com
のようにスイッチします。