-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathunlfavs.user.js
1714 lines (1566 loc) · 62.5 KB
/
unlfavs.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
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// ==UserScript==
// @name unlimited favs
// @namespace [email protected]
// @author ZerataX
// @description Adds unlimited local favorite lists to sadpanda
// @homepage https://github.com/ZerataX/unlimted_favorites/
// @homepageURL https://github.com/ZerataX/unlimted_favorites/
// @supportURL https://github.com/ZerataX/unlimted_favorites/issues/
// @license UNLICENSE
// @include /^https://e(x|-)hentai\.org/.*$/
// @grant GM_getValue
// @grant GM_setValue
// @grant GM_addStyle
// @version 1.1.0
// ==/UserScript==
/* global GM_setValue GM_getValue GM_info GM_addStyle, selected, popUp, show_image_pane, hide_image_pane */
(async function () {
// CONSTANTS
const select = query => window.document.querySelector(query)
const selectAll = query => window.document.querySelectorAll(query)
const urlParams = new URLSearchParams(window.location.search)
// Magic Numbers
const HUEOFFSET = 75
// GLOBALS
let importString = ''
// CLASSES
class FavLists {
constructor (lists = []) {
this._lists = lists
}
get lists () { return this._lists }
newList (name = '', id = _ULF.newID(), galleries = []) {
console.debug(`new List with name: "${name}" and id: "${id}"`)
const index = _ULF.counter++
if (!name) {
name = `Favorites ${9 + index}`
}
const list = new FavList(name, id, galleries)
this._lists.push(list)
}
removeList (listID) {
this._lists.splice(this._lists.findIndex(list => list.id === listID), 1)
}
getListByGid (galleryID) {
return this._lists.find(list => list.getGallery(galleryID))
}
getListByLid (listID) {
return this._lists.find(list => list.id === listID)
}
toJSON () {
return this._lists.map(list => list.toJSON())
}
save () {
_ULF.json.lists = this.toJSON()
saveGM()
console.debug('ULF data saved')
}
}
class FavList {
constructor (name, id, galleries = []) {
this._name = name
this._id = id
this._galleries = galleries
}
get id () { return this._id }
get name () { return this._name }
set name (name) {
this._name = name
}
galleries (search = false, order = 'favorited', page = 0, count = 200) {
let galleries = this._galleries
const index = page * count
const tags = {
artist: [],
character: [],
female: [],
group: [],
language: [],
male: [],
other: [],
parody: [],
reclass: []
}
if (search) {
const tagsRE = /-?(?:([a-zA-Z]+):)?(".+?\$?"|-?[\w*%$?]+)/g
let match
while (match = tagsRE.exec(search.text)) { // eslint-disable-line no-cond-assign
const [str, namespace, tag] = match
const include = (str[0] !== '-')
const regexString = tag
const regex = new RegExp(regexString.replace(/"/g, '')
.replace(/\?/g, '.')
.replace(/_/g, '.')
.replace(/\*/g, '.*?')
.replace(/%/g, '.*?'), 'i')
switch (namespace) {
case 'artist':
tags.artist.push({ include, regex })
break
case 'f':
tags.female.push({ include, regex })
break
case 'female':
tags.female.push({ include, regex })
break
case 'c':
tags.character.push({ include, regex })
break
case 'character':
tags.character.push({ include, regex })
break
case 'g':
tags.group.push({ include, regex })
break
case 'group':
tags.group.push({ include, regex })
break
case 'circle':
tags.group.push({ include, regex })
break
case 'creator':
tags.group.push({ include, regex })
break
case 'l':
tags.language.push({ include, regex })
break
case 'language':
tags.language.push({ include, regex })
break
case 'm':
tags.male.push({ include, regex })
break
case 'male':
tags.male.push({ include, regex })
break
case 'p':
tags.parody.push({ include, regex })
break
case 'parody':
tags.parody.push({ include, regex })
break
case 'series':
tags.parody.push({ include, regex })
break
case 'r':
tags.reclass.push({ include, regex })
break
case 'reclass':
tags.reclass.push({ include, regex })
break
case 'other':
tags.other.push({ include, regex })
break
case undefined:
tags.other.push({ include, regex })
break
default:
throw SyntaxError(`namespace '${namespace}' not supported`)
}
}
console.debug(tags)
const titleMatcher = (include, title, matchedTags = []) => {
let match = false
if (!(tags.other.length)) { return false }
tags.other.forEach(tag => {
if (include) {
if (tag.include && tag.regex.test(title)) {
matchedTags.push(tag)
match = true
}
} else {
if (!tag.include && tag.regex.test(title)) {
matchedTags.push(tag)
match = true
}
}
})
return match
}
const includeMatcher = (includeTag, includeNamespace, tags) => {
if (!includeTag.include) { return true }
return tags.some(tag => {
const [namespace, name] = (tag.includes(':')) ? tag.split(':') : ['other', tag]
if (includeNamespace === 'other' || includeNamespace === namespace) {
return includeTag.regex.test(name)
}
return false
})
}
// get galleries to include
console.debug(`galleries before include: ${galleries.length}`)
galleries = galleries.filter(gallery => {
let show = false
const matchedTags = [] // search tags used for notes / title should not be reused for gallery tags
if (search.name) {
show = (gallery.info.title && titleMatcher(true, gallery.info.title, matchedTags)) ||
(gallery.info.title_jpn && titleMatcher(true, gallery.info.title_jpn, matchedTags))
}
if (search.notes) {
show = show || titleMatcher(true, gallery.note, matchedTags)
}
if (search.tags) {
for (const namespace in tags) {
show = tags[namespace].every(tag => {
return matchedTags.some(mTag => tag.regex === mTag.regex) ||
includeMatcher(tag, namespace, gallery.info.tags)
})
if (!show) { break }
}
}
return show
})
console.debug(`galleries after include: ${galleries.length}`)
const excludeMatcher = (string) => {
const [namespace, name] = (string.includes(':')) ? string.split(':') : ['other', string]
// check if string matches any tag in same namespace or in other namespace
return (tags[namespace].some(tag => {
if (tag.include) { return false }
return tag.regex.test(name)
})) || (tags.other.some(tag => {
if (tag.include) { return false }
return tag.regex.test(name)
}))
}
// now check for excludes
galleries = galleries.filter(gallery => {
if (search.name) {
if ((gallery.info.title && titleMatcher(false, gallery.info.title)) ||
(gallery.info.title_jpn && titleMatcher(false, gallery.info.title_jpn))) { return false }
}
if (search.notes) {
if (titleMatcher(false, gallery.note)) { return false }
}
if (search.tags) {
if (gallery.info.tags.some(tag => excludeMatcher(tag))) { return false }
}
return true
})
console.debug(`galleries after exclude: ${galleries.length}`)
console.debug(galleries)
}
switch (order) {
case 'favorited':
galleries.sort((a, b) => {
return new Date(b.timestamp) - new Date(a.timestamp)
})
break
case 'posted':
galleries.sort((a, b) => {
// unix to date: new Date(UNIX_timestamp * 1000);
return b.info.posted - a.info.posted
})
break
default:
throw SyntaxError('"order" has to be either "posted" or "favorited"')
}
return {
galleries: galleries.slice(index, index + count) || null,
number: galleries.length || 0,
tags: tags
}
}
getGallery (id) {
return this._galleries.find(gallery => gallery.id === parseInt(id))
}
removeGallery (id) {
this._galleries = this._galleries.filter(gallery => gallery.id !== parseInt(id))
}
addGallery (id, token, note = '') {
return new Promise((resolve, reject) => {
if (!this.getGallery(id)) {
try {
const gallery = new Gallery(id, token, note)
getGalleryInfo([gallery]).then(info => {
gallery.info = info[0]
this._galleries.push(gallery)
resolve('gallery added!')
})
} catch (error) {
// window.InternalError('could not get gallery info!')
reject(window.InternalError('could not get gallery info!'))
}
} else {
// window.Error('already added to this list!')
reject(window.Error('already added to this list!'))
}
})
}
toJSON () {
return {
name: this._name,
id: this._id,
galleries: this._galleries.map(gallery => gallery.toJSON())
}
}
}
class Gallery {
constructor (id, token, note = '', timestamp = new Date(), info = false) {
this._id = parseInt(id)
this._token = token
this._note = note
this._timestamp = timestamp
this._info = info
}
toJSON () {
return {
gid: this._id,
gt: this._token,
note: this._note,
timestamp: this._timestamp,
info: this._info
}
}
get id () { return this._id }
get token () { return this._token }
get note () { return this._note }
set note (note) { this._note = note }
get timestamp () { return this._timestamp }
get info () { return this._info }
set info (info) { this._info = info }
}
// FUNCTIONS
function parser (html) {
const template = document.createElement('template')
template.innerHTML = html
return template.content.firstElementChild
}
// SCRIPT INITIALIZATION
function createLists () {
const lists = _ULF.json.lists.map(list => {
_ULF.counter++
return new FavList(list.name,
list.id,
list.galleries.map(gallery => new Gallery(gallery.gid,
gallery.gt,
gallery.note,
gallery.timestamp,
gallery.info)))
})
return new FavLists(lists)
}
// LOAD SCRIPT
const _ULF = {
json: loadGM(),
counter: 0,
newID: () => { return '_' + Math.random().toString(36).substr(2, 9) }
}
_ULF.dict = createLists()
console.log(_ULF)
saveGM()
// USERSCRIPT SPECIFIC
function clearFavs () {
_ULF.json = {}
saveGM()
window.location.reload()
}
// save settings persistently
function saveGM () {
// save value to greasemonkey/tampermonkey etc.
GM_setValue('__unlimitedfavs__', JSON.stringify(_ULF.json))
}
// load persistently saved settings, or from a given JSON string
function loadGM (importString) {
const GMString = String(importString || GM_getValue('favsJson', '') || GM_getValue('__unlimitedfavs__', ''))
// set default if no import and no saved version
const defaultValue = {
lists: [{
name: 'Favorites 11',
id: '_' + Math.random().toString(36).substr(2, 9),
galleries: []
}],
version: GM_info.script.version
}
try {
const GMJSON = (GMString && GMString !== '{}') ? JSON.parse(GMString) : defaultValue
console.debug(GMJSON)
// VERSION ADJUSTMENTS
if (!GMJSON.version) {
GMJSON.version = '0.6.5'
}
// Allow to backup before doing any other changes to the user data
if (versionCompare(String(GMJSON.version), GM_info.script.version) === -1) {
// only backup on major version change
const oldMajor = parseInt(GMJSON.version.split('.')[1])
const newMajor = parseInt(GM_info.script.version.split('.')[1])
if (oldMajor !== newMajor) {
const confirmation = window.confirm(`Unlimited Favorites has been updated to version ${GM_info.script.version}, ` +
'do you want to create a backup before updating your data?\n' +
`see what's new here: https://github.com/ZerataX/unlimted_favorites/releases/tag/${GM_info.script.version}`)
if (confirmation) {
const fileName = 'unl_favs_' + new Date().toISOString() + '.json'
download(JSON.stringify(GMJSON), fileName, 'text/json')
}
}
}
if (versionCompare(String(GMJSON.version), '0.7.0') === -1) {
// fix saved JSONs from < 0.7.0 versions
// id from string to int
for (const list of GMJSON.lists) {
for (const gallery of list.galleries) {
gallery.gid = parseInt(gallery.gid)
}
}
}
if (versionCompare(String(GMJSON.version), '0.8.0') === -1) {
// fix saved JSONs from < 0.8.0 versions
// rename date to timestamp
for (const list of GMJSON.lists) {
list.id = '_' + Math.random().toString(36).substr(2, 9)
for (const gallery of list.galleries) {
gallery.timestamp = gallery.date
delete gallery.date
}
}
delete GMJSON.display
delete GMJSON.order
}
if (versionCompare(String(GMJSON.version), '1.1.0') === -1) {
// fix saved JSONs from < 1.1.0 versions
// misc got renamed to other
for (const list of GMJSON.lists) {
for (const gallery of list.galleries) {
for (const tags of gallery.info.tags) {
const other_tags = tags.misc
tags.other = other_tags
delete tags.misc
}
}
}
}
// update version
GMJSON.version = GM_info.script.version
// remove old save data
GM_setValue('favsJson', '')
return GMJSON
} catch {
window.alert('something went wrong trying to parse your settings, please download your settings and create an issue with them attached here: https://github.com/ZerataX/unlimted_favorites/issues/new')
const fileName = 'unl_favs_' + new Date().toISOString() + '.json'
download(GMString, fileName, 'text/json')
return defaultValue
}
}
// SADPANDA API
function handleErrors (response) {
if (!response.ok || response.status !== 200) {
throw Error(response.statusText)
}
return response
}
async function getGalleryInfo (galleries) {
// [' + id +', "' + token + '" ]
const request = new window.Request('https://e-hentai.org/api.php',
{
method: 'POST',
body: JSON.stringify({
method: 'gdata',
gidlist: galleries.map(gallery => [parseInt(gallery.id), gallery.token]),
namespace: 1
})
})
return window.fetch(request)
.then(handleErrors)
.then(response => response.json())
.then(json => json.gmetadata)
.catch(error => {
console.error(error)
})
}
Promise.eachLimit = async (funcs, limit, ms) => {
const rest = funcs.slice(limit)
await Promise.all(funcs.slice(0, limit).map(async func => {
await func()
while (rest.length) {
try {
await sleep(ms).then(() => rest.shift()())
} catch (TypeError) {}
}
}))
}
// download file to local storage
function download (text, name, type) {
const a = document.createElement('a')
const file = new window.Blob([text], { type: type })
a.href = URL.createObjectURL(file)
a.download = name
a.click()
}
// based on: https://stackoverflow.com/a/6078873
function timeConverter (epoch) {
const months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
const a = new Date(epoch * 1000)
const year = a.getFullYear()
const month = months[a.getMonth()]
const date = a.getDate()
const hour = a.getHours()
const min = a.getMinutes() < 10 ? '0' + a.getMinutes() : a.getMinutes()
// const sec = a.getSeconds() < 10 ? '0' + a.getSeconds() : a.getSeconds()
const time = year + '-' + month + '-' + date + ' ' + hour + ':' + min
return time
}
// based on: https://gist.github.com/alexey-bass/1115557
function versionCompare (left, right) {
if (typeof left + typeof right !== 'stringstring') { return false }
const a = left.split('.')
const b = right.split('.')
let i = 0; const len = Math.max(a.length, b.length)
for (; i < len; i++) {
if ((a[i] && !b[i] && parseInt(a[i]) > 0) || (parseInt(a[i]) > parseInt(b[i]))) {
return 1
} else if ((b[i] && !a[i] && parseInt(b[i]) > 0) || (parseInt(a[i]) < parseInt(b[i]))) {
return -1
}
}
return 0
}
const sleep = ms => new Promise(resolve => setTimeout(resolve, ms))
// UI-MODIFICATIONS
// create list name input to rename/delete/add list
function getLargeThumbnail (url) {
// from: https://ehgt.org/ec/d6/ecd610aa9bc328660cdedfb7ba0200b80962e3b6-3994778-805-1240-png_l.jpg
// to: //ehgt.org/t/ec/d6/ecd610aa9bc328660cdedfb7ba0200b80962e3b6-3994778-805-1240-png_250.jpg
// from: https://exhentai.org/t/8b/d3/8bd3813abf795a744596201ddd7bb162ec95a86d-4438498-2400-3300-jpg_l.jpg
// to: //ehgt.org/t/8b/d3/8bd3813abf795a744596201ddd7bb162ec95a86d-4438498-2400-3300-jpg_250.jpg
return '//ehgt.org//t/' + url.split('/').slice(3).join('/').replace('_l', '_250')
}
function getRatingStyle (rating) {
// not entirely correct
const ratingOffset = [0, 0]
ratingOffset[1] = (80 - Math.round(rating) * 16) * -1
if ((Math.round(rating) - Math.floor(rating)) === 0) {
ratingOffset[0] = -20
ratingOffset[1] += 16
}
return `background-position:${ratingOffset[1]}px ${ratingOffset[0]}px;opacity:1`
}
function getCategoryClass (category) {
switch (category) {
case 'other':
return 'ct1'
case 'Doujinshi':
return 'ct2'
case 'Manga':
return 'ct3'
case 'Artist CG':
return 'ct4'
case 'Artist CG Sets':
return 'ct4'
case 'Game CG':
return 'ct5'
case 'Image Set':
return 'ct6'
case 'Cosplay':
return 'ct7'
case 'Asian Porn':
return 'ct8'
case 'Non-H':
return 'ct9'
case 'Western':
return 'cta'
default:
throw window.InternalError(`category type '${category}' not supported!`)
}
}
let inputcounter = 0
function newInput (name, id, template, counter, last = false) {
const selection = template.cloneNode(true)
const input = selection.lastElementChild.lastElementChild
input.name = `favorite_${10 + counter}`
input.placeholder = 'new list...'
input.setAttribute('lid', id)
input.value = name
input.classList.add('ulf', 'ulf_list_rename')
input.addEventListener('focusout', event => clickDeleteList(event.srcElement))
if (last) {
input.id = 'ulf_last_input'
input.addEventListener('focusout', event => clickAddList(event.srcElement))
}
selection.querySelector('.i').style.filter = `invert(100%) hue-rotate(${inputcounter * HUEOFFSET}deg)`
inputcounter++
return selection
}
function newItem (list, template, checked) {
const selection = template.cloneNode(true)
const counterDIV = selection.firstElementChild
const nameDIV = selection.lastElementChild
counterDIV.innerHTML = list._galleries.length
nameDIV.innerHTML = list.name
selection.onclick = () => { window.document.location = `/favorites.php?favcat=0&page=0&lid=${list.id}&ulfpage=0` }
selection.querySelector('.i').style.filter = `invert(100%) hue-rotate(${inputcounter * HUEOFFSET}deg)`
if (checked) {
selection.classList.add('fps')
} else {
selection.classList.remove('fps')
}
inputcounter++
return selection
}
function newExtended (gallery, template, tags = false) {
const selection = template.cloneNode(true)
const image = selection.querySelector('img')
const title = selection.querySelector('.glink')
const category = selection.querySelector('.gl3e')
const categoryTitle = category.children[0]
const dateUploaded = category.children[1]
const rating = category.children[2]
const uploader = category.children[3].firstElementChild
const pageCounter = category.children[4]
const torrent = category.children[5]
const dateFavorited = category.children[6].lastElementChild
const tagsSection = selection.querySelector('.gl3e').nextElementSibling
const note = selection.querySelector('.glfnote')
const checkbox = selection.querySelector('input[name="modifygids[]"]')
image.src = getLargeThumbnail(gallery.info.thumb)
image.alt = gallery.info.title || gallery.info.title_jpn
image.title = gallery.info.title || gallery.info.title_jpn
title.innerHTML = gallery.info.title || gallery.info.title_jpn
dateUploaded.innerHTML = timeConverter(gallery.info.posted)
dateUploaded.onclick = () => popUp(`/gallerypopups.php?gid=${gallery.id}&t=${gallery.token}&act=addfav`, 675, 415)
dateUploaded.id = `posted_${gallery.id}`
uploader.href = `uploader/${gallery.info.uploader}`
uploader.innerHTML = gallery.info.uploader
pageCounter.innerHTML = gallery.info.filecount
dateFavorited.innerHTML = timeConverter(new Date(gallery.timestamp).getTime() / 1000)
categoryTitle.innerHTML = gallery.info.category
categoryTitle.className = `cn ${getCategoryClass(gallery.info.category)}`
if ('torrents' in gallery.info && gallery.info.torrents.length) {
torrent.innerHTML = `<a href="/gallerytorrents.php?gid=${gallery.id}&t=${gallery.token}"` +
`onclick="return popUp('/gallerytorrents.php?gid=${gallery.id}&t=${gallery.token}', 610, 590)" rel="nofollow">` +
'<img src="https://ehgt.org/g/t.png" alt="T" title="Show torrents"></a>'
} else {
torrent.innerHTML = '<img src="https://ehgt.org/g/td.png" alt="T" title="No torrents available">'
}
note.innerHTML = (gallery.note) ? `Note: ${gallery.note}` : ''
note.id = `favnote_${gallery.id}`
note.style = ''
checkbox.value = gallery.id
rating.style = getRatingStyle(gallery.info.rating)
// add tags
const entryPoint = tagsSection.querySelector('tbody')
entryPoint.innerHTML = ''
const tagsCategorized = {}
gallery.info.tags.forEach(tag => {
const [namespace, name] = (tag.includes(':')) ? tag.split(':') : ['other', tag]
if (!(namespace in tagsCategorized)) {
tagsCategorized[namespace] = []
}
const highlight = tags
? (tags[namespace].some(matchTag => matchTag.include && matchTag.regex.test(name)) ||
tags.other.some(matchTag => matchTag.include && matchTag.regex.test(name)))
: false
tagsCategorized[namespace].push({ name, highlight })
})
for (const category in tagsCategorized) {
const categoryTR = parser('<tr></tr>')
const categoryTD = parser('<td></td>')
entryPoint.appendChild(categoryTR)
categoryTR.appendChild(parser(`<td class="tc">${category}:</td>`))
categoryTR.appendChild(categoryTD)
tagsCategorized[category].forEach(tag => {
const style = tag.highlight ? 'color:#090909;border-color:#ffbf36;background:radial-gradient(#ffbf36,#ffba00) !important' : ''
categoryTD.appendChild(parser(`<div class="gt" style="${style}" title="${category}:${tag.name}">${tag.name}</div>`))
})
}
// change links
const url = `/g/${gallery.id}/${gallery.token}/`
selection.querySelector('a').href = url
tagsSection.href = url
return selection
}
function newThumbnail (gallery, template, tags = false) {
const selection = template.cloneNode(true)
const image = selection.querySelector('img')
const title = selection.querySelector('.glink')
const category = selection.querySelector('.gl5t')
const categoryTitle = category.firstElementChild.firstElementChild
const dateUploaded = category.firstElementChild.children[1]
const rating = category.lastElementChild.firstElementChild
const pageCounter = category.lastElementChild.children[1]
const torrent = category.lastElementChild.children[2]
const tagsSection = selection.querySelector('.gl6t')
const note = selection.querySelector('.glfnote')
const checkbox = selection.querySelector('input[name="modifygids[]"]')
image.src = getLargeThumbnail(gallery.info.thumb)
image.alt = gallery.info.title || gallery.info.title_jpn
image.title = gallery.info.title || gallery.info.title_jpn
title.innerHTML = gallery.info.title || gallery.info.title_jpn
dateUploaded.innerHTML = timeConverter(gallery.info.posted)
dateUploaded.onclick = () => popUp(`/gallerypopups.php?gid=${gallery.id}&t=${gallery.token}&act=addfav`, 675, 415)
dateUploaded.id = `posted_${gallery.id}`
pageCounter.innerHTML = gallery.info.filecount
categoryTitle.innerHTML = gallery.info.category
categoryTitle.className = `cn ${getCategoryClass(gallery.info.category)}`
if ('torrents' in gallery.info && gallery.info.torrents.length) {
torrent.innerHTML = `<a href="/gallerytorrents.php?gid=${gallery.id}&t=${gallery.token}"` +
`onclick="return popUp('/gallerytorrents.php?gid=${gallery.id}&t=${gallery.token}', 610, 590)" rel="nofollow">` +
'<img src="https://exhentai.org/img/t.png" alt="T" title="Show torrents"></a>'
} else {
torrent.innerHTML = '<img src="https://exhentai.org/img/td.png" alt="T" title="No torrents available">'
}
note.innerHTML = (gallery.note) ? `Note: ${gallery.note}` : ''
note.id = `favnote_${gallery.id}`
note.style = ''
checkbox.value = gallery.id
rating.style = getRatingStyle(gallery.info.rating)
// add tags
tagsSection.innerHTML = ''
const tagsCategorized = {
female: [],
artist: [],
male: [],
character: [],
group: [],
language: [],
other: [],
parody: [],
reclass: []
}
gallery.info.tags.forEach(tag => {
const [namespace, name] = (tag.includes(':')) ? tag.split(':') : ['other', tag]
const highlight = tags
? (tags[namespace].some(matchTag => matchTag.include && matchTag.regex.test(name)) ||
tags.other.some(matchTag => matchTag.include && matchTag.regex.test(name)))
: false
tagsCategorized[namespace].push({ name, highlight })
})
let index = 0
for (const category in tagsCategorized) {
tagsCategorized[category].forEach(tag => {
const style = 'color:#090909;border-color:#b58411c9;background:radial-gradient(#ffbf36,#ffba00);' +
`filter: hue-rotate(${index * HUEOFFSET}deg);`
if (tag.highlight) {
tagsSection.appendChild(parser(`<div class="gt" style="${style}" title="${category}:${tag.name}">${tag.name}</div>`))
}
})
index++
}
// change links
const url = `/g/${gallery.id}/${gallery.token}/`
selection.querySelector('a').href = url
image.parentElement.href = url
return selection
}
function newCompact (gallery, template, offset, tags = false) {
const selection = template.cloneNode(true)
const pane = selection.querySelector('.glthumb')
const paneImage = pane.querySelector('img')
const paneInfo = pane.lastElementChild
const paneCategoryTitle = paneInfo.firstElementChild.firstElementChild
const paneDate = paneInfo.firstElementChild.lastElementChild
const paneRating = paneInfo.lastElementChild.firstElementChild
const panePages = paneInfo.lastElementChild.lastElementChild
const categoryTitle = selection.querySelector('.glcat').firstElementChild
const glcut = selection.querySelector('.glcut')
const userInfo = selection.querySelector('.gl2c').lastElementChild
const dateUploaded = userInfo.children[0]
const rating = userInfo.children[1]
const torrent = userInfo.children[2]
const info = selection.querySelector('.glname')
const title = info.firstElementChild.children[0]
const tagsSection = info.firstElementChild.children[1]
const note = info.firstElementChild.children[2]
const dateFaved = selection.querySelector('.glfav')
const checkbox = selection.querySelector('input[name="modifygids[]"]')
info.onmouseover = () => show_image_pane(gallery.id)
info.onmouseout = () => hide_image_pane(gallery.id)
title.innerHTML = gallery.info.title || gallery.info.title_jpn
glcut.id = `ic${gallery.id}`
pane.id = `it${gallery.id}`
paneImage.src = getLargeThumbnail(gallery.info.thumb)
paneImage.alt = gallery.info.title || gallery.info.title_jpn
paneImage.title = gallery.info.title || gallery.info.title_jpn
paneCategoryTitle.innerHTML = gallery.info.category
paneCategoryTitle.className = `cn ${getCategoryClass(gallery.info.category)}`
paneCategoryTitle.id = `postedpop_${gallery.id}`
paneDate.innerHTML = timeConverter(gallery.info.posted)
paneDate.onclick = () => popUp(`/gallerypopups.php?gid=${gallery.id}&t=${gallery.token}&act=addfav`, 675, 415)
paneDate.id = `posted_${gallery.id}`
paneDate.style = 'border-color: rgb(238, 136, 238); background-color: rgba(224, 128, 224, 0.1);'
paneDate.style.filter = `invert(100%) hue-rotate(${offset * HUEOFFSET}deg)`
paneRating.style = getRatingStyle(gallery.info.rating)
panePages.innerHTML = gallery.info.filecount
dateUploaded.innerHTML = timeConverter(gallery.info.posted)
dateUploaded.onclick = () => popUp(`/gallerypopups.php?gid=${gallery.id}&t=${gallery.token}&act=addfav`, 675, 415)
dateUploaded.id = `posted_${gallery.id}`
dateFaved.innerHTML = timeConverter(new Date(gallery.timestamp).getTime() / 1000).replace(' ', '<br>')
categoryTitle.innerHTML = gallery.info.category
categoryTitle.className = `cn ${getCategoryClass(gallery.info.category)}`
if ('torrents' in gallery.info && gallery.info.torrents.length) {
torrent.innerHTML = `<a href="/gallerytorrents.php?gid=${gallery.id}&t=${gallery.token}"` +
`onclick="return popUp('/gallerytorrents.php?gid=${gallery.id}&t=${gallery.token}', 610, 590)" rel="nofollow">` +
'<img src="https://exhentai.org/img/t.png" alt="T" title="Show torrents"></a>'
} else {
torrent.innerHTML = '<img src="https://exhentai.org/img/td.png" alt="T" title="No torrents available">'
}
note.innerHTML = (gallery.note) ? `Note: ${gallery.note}` : ''
note.id = `favnote_${gallery.id}`
note.style = ''
checkbox.value = gallery.id
rating.style = getRatingStyle(gallery.info.rating)
// add tags
tagsSection.innerHTML = ''
const tagsCategorized = {
female: [],
artist: [],
male: [],
character: [],
group: [],
language: [],
other: [],
parody: [],
reclass: []
}
gallery.info.tags.forEach(tag => {
const [namespace, name] = (tag.includes(':')) ? tag.split(':') : ['other', tag]
const highlight = tags
? (tags[namespace].some(matchTag => matchTag.include && matchTag.regex.test(name)) ||
tags.other.some(matchTag => matchTag.include && matchTag.regex.test(name)))
: false
if (highlight) {
tagsCategorized[namespace].unshift({ name, highlight })
} else {
tagsCategorized[namespace].push({ name, highlight })
}
})
let count = 0
for (const category in tagsCategorized) {
tagsCategorized[category].some(tag => {
const style = (tag.highlight) ? 'color:#090909;border-color:#b58411c9;background:radial-gradient(#ffbf36,#ffba00);' : ''
tagsSection.appendChild(parser(`<div class="gt" style="${style}" title="${category}:${tag.name}">${tag.name}</div>`))
count++
return count > 8
})
if (count > 8) { break }
}
// change links
const url = `/g/${gallery.id}/${gallery.token}/`
title.parentElement.href = url
// image.parentElement.href = url
return selection
}
function newMinimal (gallery, template, offset, tags = false) {
const selection = template.cloneNode(true)
const pane = selection.querySelector('.glthumb')
const paneImage = pane.querySelector('img')
const paneInfo = pane.lastElementChild
const paneCategoryTitle = paneInfo.firstElementChild.firstElementChild
const paneDate = paneInfo.firstElementChild.lastElementChild
const paneRating = paneInfo.lastElementChild.firstElementChild
const panePages = paneInfo.lastElementChild.lastElementChild
const categoryTitle = selection.querySelector('.glcat').firstElementChild
const glcut = selection.querySelector('.glcut')
const dateUploaded = selection.querySelector('.gl2m').children[2]
const rating = selection.querySelector('.gl4m').firstElementChild
const torrent = selection.querySelector('.gldown')
const info = selection.querySelector('.glname')
const title = info.firstElementChild.children[0]
const tagsSection = info.firstElementChild.children[1]
// if no tags the note section is at the position of the tagsection
const note = (tags) ? info.firstElementChild.children[2] : tagsSection
const dateFaved = selection.querySelector('.glfav')
const checkbox = selection.querySelector('input[name="modifygids[]"]')
info.onmouseover = () => show_image_pane(gallery.id)
info.onmouseout = () => hide_image_pane(gallery.id)
title.innerHTML = gallery.info.title || gallery.info.title_jpn
glcut.id = `ic${gallery.id}`
pane.id = `it${gallery.id}`
paneImage.src = getLargeThumbnail(gallery.info.thumb)
paneImage.alt = gallery.info.title || gallery.info.title_jpn
paneImage.title = gallery.info.title || gallery.info.title_jpn
paneCategoryTitle.innerHTML = gallery.info.category
paneCategoryTitle.className = `cn ${getCategoryClass(gallery.info.category)}`
paneCategoryTitle.id = `postedpop_${gallery.id}`
paneDate.innerHTML = timeConverter(gallery.info.posted)
paneDate.onclick = () => popUp(`/gallerypopups.php?gid=${gallery.id}&t=${gallery.token}&act=addfav`, 675, 415)
paneDate.id = `posted_${gallery.id}`
paneDate.style = 'border-color: rgb(238, 136, 238); background-color: rgba(224, 128, 224, 0.1);'
paneDate.style.filter = `invert(100%) hue-rotate(${offset * HUEOFFSET}deg)`
paneRating.style = getRatingStyle(gallery.info.rating)
panePages.innerHTML = gallery.info.filecount
dateUploaded.innerHTML = timeConverter(gallery.info.posted)
dateUploaded.onclick = () => popUp(`/gallerypopups.php?gid=${gallery.id}&t=${gallery.token}&act=addfav`, 675, 415)
dateUploaded.id = `posted_${gallery.id}`
dateFaved.innerHTML = timeConverter(new Date(gallery.timestamp).getTime() / 1000)
categoryTitle.innerHTML = gallery.info.category
categoryTitle.className = `cs ${getCategoryClass(gallery.info.category)}`
if ('torrents' in gallery.info && gallery.info.torrents.length) {
torrent.innerHTML = `<a href="/gallerytorrents.php?gid=${gallery.id}&t=${gallery.token}"` +
`onclick="return popUp('/gallerytorrents.php?gid=${gallery.id}&t=${gallery.token}', 610, 590)" rel="nofollow">` +
'<img src="https://exhentai.org/img/t.png" alt="T" title="Show torrents"></a>'
} else {
torrent.innerHTML = '<img src="https://exhentai.org/img/td.png" alt="T" title="No torrents available">'
}
note.innerHTML = (gallery.note) ? `Note: ${gallery.note}` : ''
note.id = `favnote_${gallery.id}`
note.style = ''
checkbox.value = gallery.id
rating.style = getRatingStyle(gallery.info.rating)
// add tags
tagsSection.innerHTML = ''
const tagsCategorized = {
female: [],
artist: [],
male: [],
character: [],
group: [],
language: [],
other: [],
parody: [],
reclass: []