-
Notifications
You must be signed in to change notification settings - Fork 6
/
background.js
104 lines (93 loc) · 3 KB
/
background.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
function checkIsPaid(email) {
fetch('https://raw.githubusercontent.com/ZhuPeng/mp-transform-public/master/.user')
.then(response => response.text())
.then(data => {
console.log(data)
if (data.indexOf(email) > -1) {
console.log('user is paied')
localStorage.setItem('isPaid', true);
alert("恭喜你成为尊贵的付费用户,付费用户享有多种权益,详情咨询管理员。\n")
return false
}
})
.catch(error => {
console.log(error);
});
}
chrome.identity.getProfileUserInfo(function(userInfo) {
console.log(userInfo);
email = userInfo.email;
var isPaid = localStorage.getItem('isPaid') || false;
if (isPaid) {return}
checkIsPaid(email)
});
function limitUsage() {
var key = 'usageCount'
var usageCount = localStorage.getItem(key) || 0;
usageCount++;
localStorage.setItem(key, usageCount);
if (usageCount <= 10) {
return false;
}
var isPaid = localStorage.getItem('isPaid') || false;
if (isPaid) {return false}
checkIsPaid(email);
alert("超过使用限制,请联系管理员开通付费服务\n用户名:" + email + "\n管理员(微信):15652961268\n")
return true
}
var Handlers = [{
execScript: 'contentScript.js',
urls: ['mp.weixin.qq.com'],
}, {
execScript: 'instagram.js',
urls: ['instagram.com/tv/'],
}, {
execScript: 'video.js',
urls: ['facebook.com', 'youtube.com', 'fb.watch', 'instagram.com'],
}, {
execScript: 'savefrom.js',
urls: ['en.savefrom.net'],
}, {
execScript: 'getyarn.js',
urls: ['getyarn.io/yarn-clip'],
}, {
execScript: 'batch_getyarn.js',
urls: ['getyarn.io/yarn-find?text='],
}, {
execScript: 'savethevideo-com.js',
urls: ['vimeo.com/'],
}, {
execScript: 'snapany-com.js',
urls: ['bilibili.com/video/'],
}, {
execScript: 'tiqu-cc.js',
urls: ['xiaohongshu.com/explore/', 'xhslink.com', 'tiktok.com', 'douyin.com'],
}, {
execScript: 'cookie.js',
urls: ['weibo.com'],
}]
chrome.browserAction.onClicked.addListener(function(tab) {
console.log('browserAction Clicked: ' + tab.url);
if (limitUsage() === true) {return}
for (var i = 0; i < Handlers.length; i++) {
var h = Handlers[i];
for (var j = 0; j < h.urls.length; j++) {
var url = h.urls[j];
if (tab.url.indexOf(url) > -1) {
chrome.tabs.executeScript(null, {file: "util.js"}, function() {
chrome.tabs.executeScript(null, {file: h.execScript});
});
return
}
}
}
var supportUrls = '';
for (var i = 0; i < Handlers.length; i++) {
var h = Handlers[i];
for (var j = 0; j < h.urls.length; j++) {
supportUrls += '\n' + h.urls[j];
}
}
console.log("not support")
alert("插件在不支持的页面运行\n\n\n支持的网站列表如下:" + supportUrls)
});