forked from 018/tampermonkey
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path油猴助手.user.js
204 lines (194 loc) · 7.59 KB
/
油猴助手.user.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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
// ==UserScript==
// @name 油猴助手
// @description 帮助坚持访问的网站是否有油猴插件
// @author 018(lyb018@gmail.com)
// @contributor Rhilip
// @connect *
// @grant GM_xmlhttpRequest
// @grant GM_setClipboard
// @grant GM_addStyle
// @grant GM_setValue
// @grant GM_getValue
// @grant GM_listValues
// @grant GM_deleteValue
// @grant GM_registerMenuCommand
// @require https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js
// @include *
// @version 0.1.0
// @icon https://greasyfork.org/packs/media/images/blacklogo16-5421a97c75656cecbe2befcec0778a96.png
// @run-at document-end
// @namespace http://018.ai
// ==/UserScript==
// This Userscirpt can't run under Greasemonkey 4.x platform
if (typeof GM_xmlhttpRequest === 'undefined') {
alert('不支持Greasemonkey 4.x,请换用暴力猴或Tampermonkey')
return
}
;(function () {
'use strict';
$(document).ready(function () {
sniffer(location.host)
})
function sniffer(host) {
var url = 'https://greasyfork.org/zh-CN/scripts/by-site/' + host + '?filter_locale=0'
loadDoc(url, {url: url}, function(doc, responseDetail, meta) {
var list = doc.querySelector('#browse-script-list');
if (list) {
$('body').after('<style type="text/css" nonce="A3C4C117-4422-47B2-A80D-795EAAB84A46">/*! normalize.css v3.0.1 | MIT License | git.io/normalize */\
.greasyfork-alert {\
cursor: pointer;\
left: 0;\
top: 0;\
position: fixed !important;\
z-index: 2147483647 !important;\
width: 40px !important;\
height: 40px !important;\
zoom: 1 !important;\
display: inline-block !important;\
margin: 0 !important;\
border: 0 !important;\
padding: 0 !important;\
will-change: transform;\
opacity: 1;\
touch-action: none;\
-ms-touch-action: none;\
min-height: auto !important;\
max-height: auto !important;\
min-width: auto !important;\
max-width: auto !important;\
background-size: 28px!important;\
background-position: center center!important;\
background-repeat: no-repeat !important;\
background-color: #fff !important;\
border: none !important;\
box-shadow: 0 0 10px 3px rgba(162, 161, 161, 0.3) !important;\
border-radius: 100% !important;\
transition: background-color 0.3s ease;\
}\
.greasyfork-alert.sg_hide_element {\
display: none!important;\
}\
.greasyfork-alert.logo-small {\
width: 24px !important;\
height: 24px !important;\
background-position: 50% 6px!important;\
background-size: 14px!important;\
}\
.greasyfork-alert:hover {\
background-color: #ccf0d4 !important;\
}\
@media print {\
.greasyfork-alert {\
display: none!important;\
}\
}\
.greasyfork-assistant-button-main-logo {\
background-image: url(https://greasyfork.org/packs/media/images/blacklogo96-b2384000fca45aa17e45eb417cbcbb59.png) !important;\
}\
.greasyfork-assistant-button-bottom {\
top: auto;\
bottom: 0;\
}\
.greasyfork-assistant-button-bottom.greasyfork-assistant-button-left {\
left: 0;\
right: auto;\
transform: translate3d(10px, -10px, 0);\
}\
.greasyfork-assistant-button-bottom.greasyfork-assistant-button-right {\
left: auto;\
right: 0;\
transform: translate3d(-10px, -10px, 0);\
}\
.greasyfork-assistant-button-right {\
left: auto;\
right: 0;\
}\
</style>\
<a class="greasyfork-alert greasyfork-assistant-button-main-logo greasyfork-assistant-button-bottom greasyfork-assistant-button-right" href="' + meta.url +
'" title="找到油猴插件" onclick="this.style.visibility = \'hidden\'" target="_blank"></a>');
} else if(host.indexOf('.') > -1) {
sniffer(host.replace(/^[a-zA-z0-9\-_]*\./, ''))
}
}, function(responseDetail, meta) {
console.error(responseDetail)
});
}
// 判断,空返回空字符串
function opt(val) {
if (!val) return '';
if (val instanceof Array) {
if (val.length > 0) {
return val[0];
}
} else {
return val;
}
}
// 对使用GM_xmlhttpRequest返回的html文本进行处理并返回DOM树
function page_parser(responseText) {
// 替换一些信息防止图片和页面脚本的加载,同时可能加快页面解析速度
responseText = responseText.replace(/s+src=/ig, ' data-src='); // 图片,部分外源脚本
responseText = responseText.replace(/<script[^>]*?>[\S\s]*?<\/script>/ig, ''); //页面脚本
return (new DOMParser()).parseFromString(responseText, 'text/html');
}
// 加载网页
function loadDoc (url, meta, callback, fail) {
GM_xmlhttpRequest({
method: 'GET',
url: url,
onload: function (responseDetail) {
if (responseDetail.status === 200) {
let doc = page_parser(responseDetail.responseText)
callback(doc, responseDetail, meta)
} else if (fail){
fail(responseDetail, meta);
}
},
onerror: function(err) {
if (fail) {
fail(err, meta);
}
}
})
}
// get请求
function doGet (url, meta, callback, fail) {
GM_xmlhttpRequest({
method: 'GET',
url: url,
onload: function (responseDetail) {
if (responseDetail.status === 200) {
callback(JSON.parse(responseDetail.responseText), responseDetail, meta)
} else if (fail){
fail(responseDetail, meta);
}
},
onerror: function(err) {
if (fail) {
fail(err, meta);
}
}
})
}
// post请求
function doPost (url, headers, data, meta, callback, fail) {
GM_xmlhttpRequest({
method: "POST",
url: url,
data: data,
headers: headers,
onload: function(responseDetail){
if (responseDetail.status === 200) {
callback(JSON.parse(responseDetail.responseText), responseDetail, meta)
} else if (fail){
fail(responseDetail, meta);
}
},
onerror: function(err) {
if (fail) {
fail(err, meta);
}
}
})
}
})()