-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
34 lines (28 loc) · 1.22 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// ==UserScript==
// @name Redirect localhost or 127.0.0.1 to your pc's true ip address
// @namespace http://tampermonkey.net/
// @version 0.6
// @description Redirect localhost or 127.0.0.1 to your pc's true ip address. 自动将浏览器url的localhost或127.0.0.1跳转到本机当前ip地址,方便web开发。
// @include http://localhost*
// @include http://127.0.0.1*
// @grant none
// ==/UserScript==
// 代码来源网络,本人只是稍作修改以方便遇到和我同样问题的人,如有侵权请留言告知,我好删除,谢谢。
(function () {
'use strict';
var conn = new RTCPeerConnection({
iceServers: []
});
var noop = function () { };
conn.onicecandidate = function (ice) {
if (ice.candidate) {
var ip_regex = /([0-9]{1,3}(\.[0-9]{1,3}){3}|[a-f0-9]{1,4}(:[a-f0-9]{1,4}){7})/;
var ip_addr = ip_regex.exec(ice.candidate.candidate)[1];
var url = window.location.href;
window.location = url.replace(/localhost|127.0.0.1/gi, ip_addr);
conn.onicecandidate = noop;
}
};
conn.createDataChannel('aisin');
conn.createOffer(conn.setLocalDescription.bind(conn), noop);
})();