-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathETTHelper-Thumbnail.user.js
More file actions
161 lines (149 loc) · 4.9 KB
/
ETTHelper-Thumbnail.user.js
File metadata and controls
161 lines (149 loc) · 4.9 KB
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
// ==UserScript==
// @name ETTHelper-Thumbnail
// @name:zh-CN E绅士标签翻译辅助工具-缩略图
// @namespace EhTagTranslation
// @description Help to get thumbnail for write EhTagTranslation's translation detail.
// @description:zh-CN 一键复制E绅士的缩略图,便于书写标签翻译项目的详细介绍。
// @include *://exhentai.org/g/*
// @include *://e-hentai.org/g/*
// @include *://e-hentai.org/lofi/g/*
// @include *://upl*d.e-hentai.org/managegallery*
// @include *://upl*d.e-hentai.org/upl*d/managegallery*
// @include *://exhentai.org/upl*d/managegallery*
// @include *://upl*d.exhentai.org/upl*d/managegallery*
// @resource ui-style https://github.com/EhTagTranslation/UserScripts/raw/master/Thumbnail/ETTHelper-Thumbnail.ui.css?v=3.1
// @version 3.2.0
// @grant GM_getResourceText
// @grant GM_addStyle
// @grant GM_setClipboard
// @grant GM_notification
// @author Mapaler <mapaler@163.com>
// @copyright 2017+, Mapaler <mapaler@163.com>
// @homepage https://github.com/EhTagTranslation/UserScripts
// @supportURL https://github.com/EhTagTranslation/UserScripts/issues
// ==/UserScript==
(()=>{
const styleText = GM_getResourceText("ui-style");
GM_addStyle(styleText);
const { thumbs, thumbType } = (()=>{
let thumbs, thumbType;
if (/^\/g\//.test(location.pathname)) {//图像画廊
thumbs = Array.from(document.querySelectorAll('#gdt>a'));
thumbType = 'gallery';
}
else if (/^\/lofi\//.test(location.pathname)) {//手机版画廊
thumbs = Array.from(document.querySelectorAll('#gh>a'));
thumbType = 'lofi';
}
else if (/managegallery/.test(location.pathname)) {//画廊编辑
thumbs = Array.from(document.querySelectorAll('#t>.nosel>div'));
thumbType = 'upload';
}
return { thumbs, thumbType };
})();
if (thumbType === 'gallery' || thumbType === 'lofi') {
const pageLink = thumbs[0]?.nodeName == 'A' ? thumbs[0] : thumbs[0]?.querySelector('a');
const match = pageLink.pathname.match(/\-(\d+)$/);
const firstPage = parseInt(match[1],10);
const styleText2 = `
body{
counter-reset: page ${firstPage-1};
}
.EWHT-ul::before{
counter-increment: page;
content: "P" counter(page) ": ";
}
`;
GM_addStyle(styleText2);
}
const getImgId = (src) => {
const url = new URL(src);
if (url.searchParams.get('fileid'))
{
return url.searchParams.get('fileid');
}else
{
const RegRes = /(\w+)\-(\d+)\-(\d+)\-(\d+)\-(\w+)(?:_l|_250)\b/i.exec(src);
if (RegRes) {
return `${RegRes[1]}-${RegRes[2]}-${RegRes[3]}-${RegRes[4]}-${RegRes[5]}`;
}
else {
return null;
}
}
}
function copyString(event) {
event.stopPropagation();
event.preventDefault();
const type = this.dataset.type;
const imgNode = this.parentNode.parentNode.parentNode.querySelector(":where(img, [title][style*=background])");
const src_original = ((node)=>{
if (node.nodeName == "IMG") return node.src;
const computedStyle = window.getComputedStyle(node, false);
const bgiSrc = computedStyle.backgroundImage.replace(/url\(["']?(.+?)["']?\)/gi, "$1");
return URL.canParse(bgiSrc) && bgiSrc;
})(imgNode);
const fileId = getImgId(src_original);
if (fileId === null) {
alert('错误:\n未找到符合格式的图片 ID。');
return;
}
const src_out = `https://ehgt.org/${fileId.substring(0,2)}/${fileId.substring(2,4)}/${fileId}_l.jpg`
let outstr,typeName;
switch(type) {
case "图":{
outstr = ``;
typeName = "MD 格式图片地址";
break;
}
case "隐":{
outstr = ``;
typeName = "R18 MD 格式图片地址";
break;
}
case "限":{
outstr = ``;
typeName = "R18G 限制级 MD 格式图片地址";
break;
}
default:{
outstr = src_out;
typeName = "单纯图片地址";
break;
}
}
GM_setClipboard(outstr);
GM_notification(outstr, //显示的文本
`已复制到剪贴板 - ${typeName}`, //标题
//src_original //显示原版地址,这样可以节省加载时间
);
}
const creat_li = (type) => {
const li = document.createElement("li");
li.className = "EWHT-li";
const btn = li.appendChild(document.createElement("button"));
btn.className = "EWHT-btn";
btn.dataset.type = type;
btn.onclick = copyString;
return li
}
const buildBtnList = () => {
const list = ["纯","图","隐","限"].map(creat_li);
const ul = document.createElement("ul");
ul.className = "EWHT-ul";
ul.append(...list);
return ul;
}
thumbs.forEach(thumb=>{
// //获取到图像
// const img = thumb.querySelector(":where(img, [title][style*=background])");
// //如果图像有title
// if (img.title) {
// const filename = document.createElement("div");
// filename.className = "filename";
// filename.textContent = img.title;
// img.parentElement.append(filename);
// }
thumb.appendChild(buildBtnList());
});
})();