-
Notifications
You must be signed in to change notification settings - Fork 0
/
i-jump(开发环境-ip-域名-一键切换).js
63 lines (57 loc) · 2.37 KB
/
i-jump(开发环境-ip-域名-一键切换).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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// ==UserScript==
// @name i-jump
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author You
// @match http://*/waimai/*
// @match http://*/eshop/*
// @match http://*/common/*
// @match http://*/app/microweb/*
// @match http://*/market/*
// @grant none
// ==/UserScript==
(function () {
'use strict';
// Your code here...
// 在开发网站时,可以从ip网址,跳到域名,反向也可以。
// 使用正则匹配在适用网址激活功能
// 域名网址为虚构
// 使用方法是,网址后面加上 ?ijump 或者 &ijump,重新载入网页。
let jumpFunc = function (myIP) {
let href = window.location.href
let letUsJump = (/[?&]ijump/).test(href)
let letUsJumpPre = (/[?&]ijump-pre/).test(href)
let IMTest = (/m\.test\.ggf\.net/).test(href)
let IMPre = (/m\.prepub\.ggf\.net/).test(href)
let IMLocal = (/:9999/).test(href)
if (letUsJump) {
let jumpJump
if (IMTest) {
jumpJump = href.replace('m.test.ggf.net', `${myIP}:9999`).replace('?ijump', '').replace('&ijump', '')
} else if (IMPre) {
jumpJump = href.replace('m.prepub.ggf.net', `${myIP}:9999`).replace('?ijump', '').replace('&ijump', '')
} else if (IMLocal) {
if(letUsJumpPre) {
jumpJump = href.replace(`${myIP}:9999`, 'm.prepub.ggf.net').replace('?ijump-pre', '').replace('&ijump-pre', '')
} else {
jumpJump = href.replace(`${myIP}:9999`, 'm.test.ggf.net').replace('?ijump', '').replace('&ijump', '')
}
}
window.location.replace(jumpJump)
}
}
window.RTCPeerConnection = window.RTCPeerConnection || window.mozRTCPeerConnection || window.webkitRTCPeerConnection
//compatibility for firefox and chrome
let pc = new RTCPeerConnection({ iceServers: [] }), noop = function () {
}
pc.createDataChannel("") //create a bogus data channel
pc.createOffer(pc.setLocalDescription.bind(pc), noop) // create offer and set local description
pc.onicecandidate = function (ice) { //listen for candidate events
if (!ice || !ice.candidate || !ice.candidate.candidate) return
let myIP = /([0-9]{1,3}(\.[0-9]{1,3}){3}|[a-f0-9]{1,4}(:[a-f0-9]{1,4}){7})/.exec(ice.candidate.candidate)[1]
console.log('my IP: ', myIP)
pc.onicecandidate = noop
jumpFunc(myIP)
}
})();