Skip to content

Commit f5b7806

Browse files
committed
缩略图工具:解决页面改版后缩略图工具不能用的问题
1 parent 0dbcf18 commit f5b7806

6 files changed

+136
-127
lines changed

Thumbnail/ETTHelper-Thumbnail.user.js

+125-115
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// @include *://exhentai.org/upl*d/managegallery*
1313
// @include *://upl*d.exhentai.org/upl*d/managegallery*
1414
// @resource ui-style https://github.com/EhTagTranslation/UserScripts/raw/master/Thumbnail/ETTHelper-Thumbnail.ui.css?v=3.1
15-
// @version 3.1.0
15+
// @version 3.2.0
1616
// @grant GM_getResourceText
1717
// @grant GM_addStyle
1818
// @grant GM_setClipboard
@@ -23,129 +23,139 @@
2323
// @supportURL https://github.com/EhTagTranslation/UserScripts/issues
2424
// ==/UserScript==
2525

26-
const styleText = GM_getResourceText("ui-style");
27-
GM_addStyle(styleText);
28-
const { thumbs, thumbType } = (()=>{
29-
let thumbs, thumbType;
30-
if (/^\/g\//.test(location.pathname)) {//图像画廊
31-
thumbs = Array.from(document.querySelectorAll('#gdt>.gdtl'));
32-
thumbType = 'gallery';
33-
}
34-
else if (/^\/lofi\//.test(location.pathname)) {//手机版画廊
35-
thumbs = Array.from(document.querySelectorAll('#gh>.gi'));
36-
thumbType = 'lofi';
37-
}
38-
else if (/managegallery/.test(location.pathname)) {//画廊编辑
39-
thumbs = Array.from(document.querySelectorAll('#t>.nosel>div'));
40-
thumbType = 'upload';
41-
}
42-
return { thumbs, thumbType };
43-
})();
44-
45-
if (thumbType === 'lofi') {
46-
const pageLink = thumbs[0]?.nodeName == 'A' ? thumbs[0] : thumbs[0]?.querySelector('a');
47-
const match = pageLink.pathname.match(/\-(\d+)$/);
48-
const firstPage = parseInt(match[1],10);
49-
const styleText2 = `
50-
body{
51-
counter-reset: page ${firstPage-1};
52-
}
53-
.EWHT-ul::before{
54-
counter-increment: page;
55-
content: "P" counter(page) ": ";
26+
(()=>{
27+
const styleText = GM_getResourceText("ui-style");
28+
GM_addStyle(styleText);
29+
const { thumbs, thumbType } = (()=>{
30+
let thumbs, thumbType;
31+
if (/^\/g\//.test(location.pathname)) {//图像画廊
32+
thumbs = Array.from(document.querySelectorAll('#gdt>a'));
33+
thumbType = 'gallery';
5634
}
57-
`;
58-
GM_addStyle(styleText2);
59-
}
60-
61-
const getImgId = (src) => {
62-
const url = new URL(src);
63-
if (url.searchParams.get('fileid'))
64-
{
65-
return url.searchParams.get('fileid');
66-
}else
67-
{
68-
const RegRes = /(\w+)\-(\d+)\-(\d+)\-(\d+)\-(\w+)(?:_l|_250)\b/i.exec(src);
69-
if (RegRes) {
70-
return `${RegRes[1]}-${RegRes[2]}-${RegRes[3]}-${RegRes[4]}-${RegRes[5]}`;
35+
else if (/^\/lofi\//.test(location.pathname)) {//手机版画廊
36+
thumbs = Array.from(document.querySelectorAll('#gh>a'));
37+
thumbType = 'lofi';
7138
}
72-
else {
73-
return null;
39+
else if (/managegallery/.test(location.pathname)) {//画廊编辑
40+
thumbs = Array.from(document.querySelectorAll('#t>.nosel>div'));
41+
thumbType = 'upload';
7442
}
75-
}
76-
}
77-
const creat_li = (type) => {
78-
const li = document.createElement("li");
79-
li.className = "EWHT-li";
80-
const btn = li.appendChild(document.createElement("button"));
81-
btn.className = "EWHT-btn";
82-
btn.dataset.type = type;
83-
btn.onclick = copyString;
84-
return li
85-
}
86-
const buildBtnList = () => {
87-
const ul = document.createElement("ul");
88-
ul.className = "EWHT-ul";
89-
ul.append(
90-
creat_li("纯"),
91-
creat_li("图"),
92-
creat_li("隐"),
93-
creat_li("限")
94-
);
95-
return ul;
96-
}
43+
return { thumbs, thumbType };
44+
})();
9745

98-
function copyString() {
99-
const type = this.dataset.type;
100-
const src_original = this.parentNode.parentNode.parentNode.querySelector('img').src;
101-
const fileId = getImgId(src_original);
102-
if (fileId === null) {
103-
alert('错误:\n未找到符合格式的图片 ID。');
104-
return;
46+
if (thumbType === 'gallery' || thumbType === 'lofi') {
47+
const pageLink = thumbs[0]?.nodeName == 'A' ? thumbs[0] : thumbs[0]?.querySelector('a');
48+
const match = pageLink.pathname.match(/\-(\d+)$/);
49+
const firstPage = parseInt(match[1],10);
50+
const styleText2 = `
51+
body{
52+
counter-reset: page ${firstPage-1};
53+
}
54+
.EWHT-ul::before{
55+
counter-increment: page;
56+
content: "P" counter(page) ": ";
57+
}
58+
`;
59+
GM_addStyle(styleText2);
10560
}
106-
const src_out = `https://ehgt.org/${fileId.substring(0,2)}/${fileId.substring(2,4)}/${fileId}_l.jpg`
107-
108-
let outstr,typeName;
109-
switch(type) {
110-
case "图":{
111-
outstr = `![${type}](${src_out})`;
112-
typeName = "MD 格式图片地址";
113-
break;
114-
}
115-
case "隐":{
116-
outstr = `![${type}](# "${src_out}")`;
117-
typeName = "R18 MD 格式图片地址";
118-
break;
61+
62+
const getImgId = (src) => {
63+
const url = new URL(src);
64+
if (url.searchParams.get('fileid'))
65+
{
66+
return url.searchParams.get('fileid');
67+
}else
68+
{
69+
const RegRes = /(\w+)\-(\d+)\-(\d+)\-(\d+)\-(\w+)(?:_l|_250)\b/i.exec(src);
70+
if (RegRes) {
71+
return `${RegRes[1]}-${RegRes[2]}-${RegRes[3]}-${RegRes[4]}-${RegRes[5]}`;
72+
}
73+
else {
74+
return null;
75+
}
11976
}
120-
case "限":{
121-
outstr = `![${type}](## "${src_out}")`;
122-
typeName = "R18G 限制级 MD 格式图片地址";
123-
break;
77+
}
78+
79+
function copyString(event) {
80+
event.stopPropagation();
81+
event.preventDefault();
82+
83+
const type = this.dataset.type;
84+
const imgNode = this.parentNode.parentNode.parentNode.querySelector(":where(img, [title][style*=background])");
85+
86+
const src_original = ((node)=>{
87+
if (node.nodeName == "IMG") return node.src;
88+
const computedStyle = window.getComputedStyle(node, false);
89+
const bgiSrc = computedStyle.backgroundImage.replace(/url\(["']?(.+?)["']?\)/gi, "$1");
90+
return URL.canParse(bgiSrc) && bgiSrc;
91+
})(imgNode);
92+
93+
const fileId = getImgId(src_original);
94+
if (fileId === null) {
95+
alert('错误:\n未找到符合格式的图片 ID。');
96+
return;
12497
}
125-
default:{
126-
outstr = src_out;
127-
typeName = "单纯图片地址";
128-
break;
98+
const src_out = `https://ehgt.org/${fileId.substring(0,2)}/${fileId.substring(2,4)}/${fileId}_l.jpg`
99+
100+
let outstr,typeName;
101+
switch(type) {
102+
case "图":{
103+
outstr = `![${type}](${src_out})`;
104+
typeName = "MD 格式图片地址";
105+
break;
106+
}
107+
case "隐":{
108+
outstr = `![${type}](# "${src_out}")`;
109+
typeName = "R18 MD 格式图片地址";
110+
break;
111+
}
112+
case "限":{
113+
outstr = `![${type}](## "${src_out}")`;
114+
typeName = "R18G 限制级 MD 格式图片地址";
115+
break;
116+
}
117+
default:{
118+
outstr = src_out;
119+
typeName = "单纯图片地址";
120+
break;
121+
}
129122
}
130-
}
131123

132-
GM_setClipboard(outstr);
133-
GM_notification(outstr, //显示的文本
134-
`已复制到剪贴板 - ${typeName}`, //标题
135-
src_original //显示原版地址,这样可以节省加载时间
136-
);
137-
}
124+
GM_setClipboard(outstr);
125+
GM_notification(outstr, //显示的文本
126+
`已复制到剪贴板 - ${typeName}`, //标题
127+
//src_original //显示原版地址,这样可以节省加载时间
128+
);
129+
}
138130

139-
thumbs.forEach(thumb=>{
140-
//获取到图像
141-
const img = thumb.querySelector("img");
142-
//如果图像有title
143-
if (img.title) {
144-
const filename = document.createElement("div");
145-
filename.className = "filename";
146-
filename.textContent = img.title;
147-
img.parentElement.insertBefore(filename, img.nextSibling?.nextSibling?.nextSibling);
131+
const creat_li = (type) => {
132+
const li = document.createElement("li");
133+
li.className = "EWHT-li";
134+
const btn = li.appendChild(document.createElement("button"));
135+
btn.className = "EWHT-btn";
136+
btn.dataset.type = type;
137+
btn.onclick = copyString;
138+
return li
148139
}
140+
const buildBtnList = () => {
141+
const list = ["纯","图","隐","限"].map(creat_li);
142+
const ul = document.createElement("ul");
143+
ul.className = "EWHT-ul";
144+
ul.append(...list);
145+
return ul;
146+
}
147+
148+
thumbs.forEach(thumb=>{
149+
// //获取到图像
150+
// const img = thumb.querySelector(":where(img, [title][style*=background])");
151+
// //如果图像有title
152+
// if (img.title) {
153+
// const filename = document.createElement("div");
154+
// filename.className = "filename";
155+
// filename.textContent = img.title;
156+
// img.parentElement.append(filename);
157+
// }
149158

150-
thumb.appendChild(buildBtnList());
151-
});
159+
thumb.appendChild(buildBtnList());
160+
});
161+
})();

Thumbnail/README.md

+11-12
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,16 @@
55
去到处找能在 E 站看的图还是很困难的一件工作,此脚本工具可以快速将E站作品缩略图复制为 Wiki 使用的格式。
66
[安装脚本](//sleazyfork.org/scripts/31743)
77

8-
画廊内点击 `Large` 开启**大图模式**
9-
![打开大图模式](./images/OpenLargeThumbnail.png)
8+
在账号设置内设置缩略图大小为普通,以开启**独立图片**模式
9+
![打开大图模式](./images/SetLargeThumbnail.webp)
1010

11-
点击按钮自动将对应的站点格式复制到剪贴板。(里站、表站、手机版)
12-
* 点击“纯”,即可直接复制得 `图片网址`
13-
获得单纯图片网址
14-
* 点击“图”,即可直接复制得 `![图](图片网址)`
15-
获得MD图片格式
16-
* 点击“隐”,即可直接复制得 `![图](# "图片网址")`
17-
获得隐藏的MD图片格式
18-
* 点击“限”,即可直接复制得 `![图](## "图片网址")`
19-
获得R18G限制级的MD图片格式
11+
点击按钮自动将对应的站点格式复制到剪贴板。(里站、表站、手机版)
2012

21-
![预览](./images/Preview.png)
13+
| 按钮名 | 格式 | 解释 |
14+
| ----- | ---- | ---- |
15+
| **** | `图片网址` | 单纯图片网址 |
16+
| **** | `![图](图片网址)` | MarkDown 格式图片格式 |
17+
| **** | `![图](# "图片网址")` | 隐藏的 MarkDown 格式图片格式 |
18+
| **** | `![图](## "图片网址")` | R18G 限制级的 MarkDown 格式图片格式 |
19+
20+
![预览](./images/Preview.webp)
-28.1 KB
Binary file not shown.

Thumbnail/images/Preview.png

-37.5 KB
Binary file not shown.

Thumbnail/images/Preview.webp

22.1 KB
Binary file not shown.
7.13 KB
Binary file not shown.

0 commit comments

Comments
 (0)