-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgoto.js
48 lines (41 loc) · 1.04 KB
/
goto.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
const url = require('url');
const isMobile = require('isMobile');
class Goto {
constructor() {
this.args = url('?') || {}
}
// For Mobile client
computer(url) {
this.url = url;
this.isMobileSite = true;
this.__delay();
return this;
}
// For Computer client
mobile(url) {
this.url = url;
this.isMobileSite = false;
this.__delay();
return this;
}
filter(key, value) {
this.filter.key = key;
this.filter.value = value;
}
__delay() {
setTimeout(e => this.__change(), 0)
}
__change() {
if(
// 跳转规则检查
// PC设备访问Mobile网站 => false
// Mobile设备访问PC网站 => false
isMobile.any !== this.isMobileSite &&
// 过滤规则检查
(!this.filter.key || this.filter.key && this.args[this.filter.key] !== this.filter.value)
){
location.href = this.url
}
}
}
module.exports = new Goto;