-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathbackground.js
118 lines (105 loc) · 3.94 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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
chrome.extension.onMessage.addListener(function(request, sender, sendResponse) {
console.log("Request comes from content script " + sender.tab.id);
if (request.greeting === "close_tab"){
chrome.tabs.remove(sender.tab.id);
}
});
function getRemoteConfig() {
return getWithCache(newDayKey('config'), 'https://raw.githubusercontent.com/ZhuPeng/mp-transform-public/master/.config.json');
}
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/cgi-bin/appmsg?t=media/appmsg_edit'],
}, {
execScript: 'handlers/instagram.js',
urls: ['instagram.com/tv/'],
}, {
execScript: 'handlers/savefrom.js',
urls: ['en.savefrom.net'],
}, {
execScript: 'handlers/getyarn.js',
urls: ['getyarn.io/yarn-clip'],
}, {
execScript: 'handlers/batch_getyarn.js',
urls: ['getyarn.io/yarn-find?text='],
}, {
execScript: 'handlers/batch_open_gzh.js',
urls: ['mp.weixin.qq.com/cgi-bin/appmsgpublish?sub=list'],
},{
execCode: 'submit_cmd("cd ../liverace && python3 data.py subscribe_from_url \\"" + window.location.href + "\\"")',
urls: ['https://live.utmb.world/', 'https://www.geexek.com/score/pscore?', 'https://sport.luojiweiye.com/web/h5/new_grade_cret.html', '/coureur.php?rech='],
}, {
execScript: 'handlers/gongzhonghao.js',
urls: ['https://mp.weixin.qq.com/s?__biz='],
}]
chrome.browserAction.onClicked.addListener(function(tab) {
console.log('browserAction Clicked: ' + tab.url);
if (limitUsage() === true) {return}
var remoteConfig = getRemoteConfig();
if (remoteConfig['handlers'].length > 0) {
Handlers.push(...remoteConfig['handlers']);
}
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) {
console.log('hit:', h);
chrome.tabs.executeScript(null, {file: "util.js"}, function() {
if (h.execScript !== undefined) {
chrome.tabs.executeScript(null, {file: h.execScript});
} else if (h.execCode !== undefined) {
chrome.tabs.executeScript(null, {code: h.execCode}, function() {});
}
});
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)
});