12
12
// @include *://exhentai.org/upl*d/managegallery*
13
13
// @include *://upl*d.exhentai.org/upl*d/managegallery*
14
14
// @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
16
16
// @grant GM_getResourceText
17
17
// @grant GM_addStyle
18
18
// @grant GM_setClipboard
23
23
// @supportURL https://github.com/EhTagTranslation/UserScripts/issues
24
24
// ==/UserScript==
25
25
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 ( / ^ \/ l o f i \/ / . test ( location . pathname ) ) { //手机版画廊
35
- thumbs = Array . from ( document . querySelectorAll ( '#gh>.gi' ) ) ;
36
- thumbType = 'lofi' ;
37
- }
38
- else if ( / m a n a g e g a l l e r y / . 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' ;
56
34
}
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 | _ 2 5 0 ) \b / i. exec ( src ) ;
69
- if ( RegRes ) {
70
- return `${ RegRes [ 1 ] } -${ RegRes [ 2 ] } -${ RegRes [ 3 ] } -${ RegRes [ 4 ] } -${ RegRes [ 5 ] } ` ;
35
+ else if ( / ^ \/ l o f i \/ / . test ( location . pathname ) ) { //手机版画廊
36
+ thumbs = Array . from ( document . querySelectorAll ( '#gh>a' ) ) ;
37
+ thumbType = 'lofi' ;
71
38
}
72
- else {
73
- return null ;
39
+ else if ( / m a n a g e g a l l e r y / . test ( location . pathname ) ) { //画廊编辑
40
+ thumbs = Array . from ( document . querySelectorAll ( '#t>.nosel>div' ) ) ;
41
+ thumbType = 'upload' ;
74
42
}
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
+ } ) ( ) ;
97
45
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 ) ;
105
60
}
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 = `` ;
112
- typeName = "MD 格式图片地址" ;
113
- break ;
114
- }
115
- case "隐" :{
116
- outstr = `` ;
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 | _ 2 5 0 ) \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
+ }
119
76
}
120
- case "限" :{
121
- outstr = `` ;
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 ( / u r l \( [ " ' ] ? ( .+ ?) [ " ' ] ? \) / 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 ;
124
97
}
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 = `` ;
104
+ typeName = "MD 格式图片地址" ;
105
+ break ;
106
+ }
107
+ case "隐" :{
108
+ outstr = `` ;
109
+ typeName = "R18 MD 格式图片地址" ;
110
+ break ;
111
+ }
112
+ case "限" :{
113
+ outstr = `` ;
114
+ typeName = "R18G 限制级 MD 格式图片地址" ;
115
+ break ;
116
+ }
117
+ default :{
118
+ outstr = src_out ;
119
+ typeName = "单纯图片地址" ;
120
+ break ;
121
+ }
129
122
}
130
- }
131
123
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
+ }
138
130
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
148
139
}
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
+ // }
149
158
150
- thumb . appendChild ( buildBtnList ( ) ) ;
151
- } ) ;
159
+ thumb . appendChild ( buildBtnList ( ) ) ;
160
+ } ) ;
161
+ } ) ( ) ;
0 commit comments