This repository has been archived by the owner on Dec 7, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 59
/
ETTWikiHelper-Thumbnail.user.js
262 lines (254 loc) · 6.83 KB
/
ETTWikiHelper-Thumbnail.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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
// ==UserScript==
// @name ETTWikiHelper-Thumbnail
// @name:zh-CN E绅士标签翻译辅助工具-缩略图
// @namespace http://www.mapaler.com/
// @description Help to get thumbnail for write EhTagTranslator's wiki info.
// @description:zh-CN 自动将E绅士大缩略图域名改为手机站域名,并可以一键复制各站点格式的缩略图。
// @include /^https?://(exhentai\.org|e-hentai\.org)/$/
// @include /^https?://(exhentai\.org|e-hentai\.org)/g/\d+/\w+/.*$/
// @include /^https?://(exhentai\.org|e-hentai\.org)/(index\.php)?\?.*$/
// @include /^https?://(exhentai\.org|e-hentai\.org)/(tag|uploader)/.*$/
// @include /^https?://(exhentai\.org|e-hentai\.org)/(doujinshi|manga|artistcg|gamecg|western|non-h|imageset|cosplay|asianporn|misc).*$/
// @version 2.1.0
// @grant GM_setClipboard
// @author Mapaler <[email protected]>
// @copyright 2017+, Mapaler <[email protected]>
// ==/UserScript==
//没有扩展时的debug
if(typeof(GM_setClipboard) == "undefined")
{
var GM_setClipboard = function(str){
prompt(str,str);
console.debug("使用GM_setClipboard,值为",str);
}
}
//发送网页通知
function spawnNotification(theBody, theIcon, theTitle)
{
var options = {
body: theBody,
icon: theIcon
}
if (!("Notification" in window))
{
alert(theBody);
}
else if (Notification.permission === "granted") {
Notification.requestPermission(function (permission) {
// If the user is okay, let's create a notification
var n = new Notification(theTitle, options);
});
}
// Otherwise, we need to ask the user for permission
else if (Notification.permission !== 'denied') {
Notification.requestPermission(function (permission) {
// If the user is okay, let's create a notification
if (permission === "granted") {
var n = new Notification(theTitle, options);
}
});
}
}
var thumbnailPattern = "https?://(\\d+\\.\\d+\\.\\d+\\.\\d+|ul\\.ehgt\\.org|ehgt\\.org|exhentai\\.org)(?:/t)?/(\\w+)/(\\w+)/(\\w+)\-(\\d+)\-(\\d+)\-(\\d+)\-(\\w+)_(l|250).jpg"; //缩略图地址正则匹配式
var gdtlObj = function(){
var obj = {
dom:"",
fullsrc:"",
domain:"",
path1:"",
path2:"",
hash1:"",
hash2:"",
width:"",
height:"",
extension:"",
size:"",
addImgFrom_gdtlDom: function(dom)
{
if (dom == undefined) dom = this.dom;
else this.dom = dom;
var img = dom.querySelector("img");
if (img == null) console.log(dom)
var addsrc = this.addImgFromSrc(img.src);
if (addsrc)
return true;
else
return false;
},
addImgFromSrc: function(src)
{
if (src == undefined) return false;
this.fullsrc = src;
var regSrc = new RegExp(thumbnailPattern, "ig");
var regResult = regSrc.exec(src);
if (regResult)
{
this.domain = regResult[1];
this.path1 = regResult[2];
this.path2 = regResult[3];
this.hash1 = regResult[4];
this.hash2 = regResult[5];
this.width = regResult[6];
this.height = regResult[7];
this.extension = regResult[8];
this.size = regResult[9];
}
return true;
},
replaceImgSrcFrom_gdtlDom: function(dom,type)
{
if (dom == undefined) dom = this.dom;
else this.dom = dom;
var img = dom.getElementsByTagName("img")[0];
img.src = this.getSrc(type);
},
getSrc: function()
{
var srcA = [];
srcA.push(location.protocol,"//ehgt.org/",this.path1,"/",this.path2,"/",this.hash1,"-",this.hash2,"-",this.width,"-",this.height,"-",this.extension,"_",this.size,".jpg");
return srcA.join("");
},
addBtnList: function(dom)
{
if (dom == undefined) dom = this.dom;
function creat_li(caption,href,type){
var li = document.createElement("li");
li.className = "EWHT-li";
var btn = document.createElement("button");
btn.className = "EWHT-btn";
btn.appendChild(document.createTextNode(caption));
btn.onclick = function(){
var str = href;
var typeName = "单纯地址";
if (caption == "图")
{
str = "![图](" + href + ")";
typeName = "MD格式图片地址";
}else if (caption == "隐")
{
str = "![图](# \"" + href + "\")";
typeName = "R18 MD格式图片地址";
}else if (caption == "限")
{
str = "![图](## \"" + href + "\")";
typeName = "R18G限制级 MD格式图片地址";
}
GM_setClipboard(str);
spawnNotification(str,href,"已复制到剪贴板 - " + typeName);
}
li.appendChild(btn);
return li
}
var ul = document.createElement("ul");
ul.className = "EWHT-ul";
ul.appendChild(creat_li("纯",this.getSrc()));
ul.appendChild(creat_li("图",this.getSrc()));
ul.appendChild(creat_li("隐",this.getSrc()));
ul.appendChild(creat_li("限",this.getSrc()));
dom.appendChild(ul);
},
}
return obj;
}
var style = document.createElement("style");
style.type = "text/css";
var styleTxt = [
//画廊缩略图
["#gdt .gdtl","{"
,[
,"position:relative"
].join(';\r\n '),"}"].join('\r\n'),
["#gdt .EWHT-ul","{"
,[
,"top:0px"
,"right:0px"
].join(';\r\n '),"}"].join('\r\n'),
//画廊封面
["#gleft .EWHT-ul","{"
,[
,"top:15px"
,"left:-5px"
].join(';\r\n '),"}"].join('\r\n'),
//搜索列表
[".itg .id1","{"
,[
,"position:relative"
].join(';\r\n '),"}"].join('\r\n'),
[".itg .EWHT-ul","{"
,[
,"top:33px"
,"right:-5px"
].join(';\r\n '),"}"].join('\r\n'),
//图片浏览页
["#i3","{"
,[
,"position:relative"
].join(';\r\n '),"}"].join('\r\n'),
["#i3 .EWHT-ul","{"
,[
,"top:-30px"
,"right:0px"
].join(';\r\n '),"}"].join('\r\n'),
//通用
[".EWHT-ul","{"
,[
,"position:absolute"
,"list-style:none"
,"padding:0px"
,"margin:0px"
].join(';\r\n '),"}"].join('\r\n'),
[".EWHT-ul .EWHT-btn","{"
,[
,"padding:0px"
,"font-size:12px"
,"width:18px"
].join(';\r\n '),"}"].join('\r\n'),
].join('\r\n');
style.innerHTML = styleTxt;
var head = document.head || document.querySelector('head');
head.appendChild(style);
var gdt = document.querySelector("#gdt");
var itg = document.querySelector(".itg");
if (gdt) //画廊
{
var gdtls = gdt.getElementsByClassName("gdtl");
if (gdtls.length>0)
{
for (var gdi = 0,len= gdtls.length ; gdi <len; gdi++)
{
var gdtl_this = new gdtlObj;
var addRes = gdtl_this.addImgFrom_gdtlDom(gdtls[gdi]);
if (addRes) {
gdtl_this.addBtnList(gdtls[gdi]);
}
else console.debug("缩略图添加网址失败");
}
}
else
{
console.debug("小图模式,本脚本不起作用。");
}
}
else if (itg) //搜索列表
{
var id1s = itg.getElementsByClassName("id1");
if (id1s.length>0)
{
for (var id1i = 0,len= id1s.length ; id1i <len; id1i++)
{
var id3s = id1s[id1i].querySelector(".id3");
var id3_this = new gdtlObj;
var addRes = id3_this.addImgFrom_gdtlDom(id3s);
if (addRes) id3_this.addBtnList(id1s[id1i]);
else console.debug("添加网址失败");
}
}
else
{
console.debug("找不到图象列表。");
}
}
else //都不是
{
console.debug("本脚本在该页面上不运行");
}