forked from Ocrosoft/PixivPreviewer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pixiv previewer.user.js
3795 lines (3434 loc) · 155 KB
/
pixiv previewer.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 Pixiv Previewer(Dev)
// @namespace https://github.com/Ocrosoft/PixivPreviewer
// @version 3.7.8
// @description Display preview images (support single image, multiple images, moving images); Download animation(.zip); Sorting the search page by favorite count(and display it). Updated for the latest search page.
// @description:zh-CN 显示预览图(支持单图,多图,动图);动图压缩包下载;搜索页按热门度(收藏数)排序并显示收藏数,适配11月更新。
// @description:ja プレビュー画像の表示(単一画像、複数画像、動画のサポート); アニメーションのダウンロード(.zip); お気に入りの数で検索ページをソートします(そして表示します)。 最新の検索ページ用に更新されました。
// @description:zh_TW 顯示預覽圖像(支持單幅圖像,多幅圖像,運動圖像); 下載動畫(.zip); 按收藏夾數對搜索頁進行排序(並顯示)。 已為最新的搜索頁面適配。
// @author Ocrosoft
// @match *://www.pixiv.net/*
// @grant unsafeWindow
// @compatible Chrome
// @license GPLv3
// @icon https://t0.gstatic.com/faviconV2?client=SOCIAL&type=FAVICON&fallback_opts=TYPE,SIZE,URL&size=32&url=https://www.pixiv.net
// @icon64 https://t0.gstatic.com/faviconV2?client=SOCIAL&type=FAVICON&fallback_opts=TYPE,SIZE,URL&size=64&url=https://www.pixiv.net
// ==/UserScript==
// https://greasyfork.org/zh-CN/scripts/417761-ilog
// 后面把DoLog替换掉
function ILog() {
this.prefix = '';
this.v = function (value) {
if (level <= this.LogLevel.Verbose) {
console.log(this.prefix + value);
}
}
this.i = function (info) {
if (level <= this.LogLevel.Info) {
console.info(this.prefix + info);
}
}
this.w = function (warning) {
if (level <= this.LogLevel.Warning) {
console.warn(this.prefix + warning);
}
}
this.e = function (error) {
if (level <= this.LogLevel.Error) {
console.error(this.prefix + error);
}
}
this.d = function (element) {
if (level <= this.LogLevel.Verbose) {
console.log(element);
}
}
this.setLogLevel = function (logLevel) {
level = logLevel;
}
this.LogLevel = {
Verbose: 0,
Info: 1,
Warning: 2,
Error: 3,
};
let level = this.LogLevel.Verbose;
}
var iLog = new ILog();
// https://greasyfork.org/zh-CN/scripts/417760-checkjquery
var checkJQuery = function () {
let jqueryCdns = [
'http://code.jquery.com/jquery-2.1.4.min.js',
'https://ajax.aspnetcdn.com/ajax/jquery/jquery-2.1.4.min.js',
'https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js',
'https://cdn.staticfile.org/jquery/2.1.4/jquery.min.js',
'https://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js',
];
function isJQueryValid() {
try {
let wd = unsafeWindow;
if (wd.jQuery && !wd.$) {
wd.$ = wd.jQuery;
}
$();
return true;
} catch (exception) {
return false;
}
}
function insertJQuery(url) {
let script = document.createElement('script');
script.src = url;
document.head.appendChild(script);
return script;
}
function converProtocolIfNeeded(url) {
let isHttps = location.href.indexOf('https://') != -1;
let urlIsHttps = url.indexOf('https://') != -1;
if (isHttps && !urlIsHttps) {
return url.replace('http://', 'https://');
} else if (!isHttps && urlIsHttps) {
return url.replace('https://', 'http://');
}
return url;
}
function waitAndCheckJQuery(cdnIndex, resolve) {
if (cdnIndex >= jqueryCdns.length) {
iLog.e('无法加载 JQuery,正在退出。');
resolve(false);
return;
}
let url = converProtocolIfNeeded(jqueryCdns[cdnIndex]);
iLog.i('尝试第 ' + (cdnIndex + 1) + ' 个 JQuery CDN:' + url + '。');
let script = insertJQuery(url);
setTimeout(function () {
if (isJQueryValid()) {
iLog.i('已加载 JQuery。');
resolve(true);
} else {
iLog.w('无法访问。');
script.remove();
waitAndCheckJQuery(cdnIndex + 1, resolve);
}
}, 100);
}
return new Promise(function (resolve) {
if (isJQueryValid()) {
iLog.i('已加载 jQuery。');
resolve(true);
} else {
iLog.i('未发现 JQuery,尝试加载。');
waitAndCheckJQuery(0, resolve);
}
});
}
let Lang = {
// 自动选择
auto: -1,
// 中文-中国大陆
zh_CN: 0,
// 英语-美国
en_US: 1,
// 俄语-俄罗斯
ru_RU: 2,
};
let Texts = {};
Texts[Lang.zh_CN] = {
// 安装或更新后弹出的提示
install_title: '欢迎使用 PixivPreviewer v',
install_body: '<div style="position: absolute;left: 50%;top: 30%;font-size: 20px; color: white;transform:translate(-50%,0);"><p style="text-indent: 2em;">欢迎反馈问题和提出建议!><a style="color: green;" href="https://greasyfork.org/zh-CN/scripts/30766-pixiv-previewer/feedback" target="_blank">反馈页面</a><</p><br><p style="text-indent: 2em;">如果您是第一次使用,推荐到<a style="color: green;" href="https://greasyfork.org/zh-CN/scripts/30766-pixiv-previewer" target="_blank"> 详情页 </a>查看脚本介绍。</p></div>',
upgrade_body: '新功能<br><ul><li>小说排序时可以按收藏数筛选。</li><li>小说排序时可以隐藏已收藏的作品。</li></ul>修复<br><ul><li>修复重置后显示的提示语言可能不正确的问题。</li></ul>',
// 设置项
setting_language: '语言',
setting_preview: '预览',
setting_sort: '排序(仅搜索页生效)',
setting_anime: '动图下载(动图预览及详情页生效)',
setting_origin: '预览时优先显示原图(慢)',
setting_previewDelay: '延迟显示预览图(毫秒)',
setting_previewByKey: '使用按键控制预览图展示(Ctrl)',
setting_previewByKeyHelp: '开启后鼠标移动到图片上不再展示预览图,按下Ctrl键才展示,同时“延迟显示预览”设置项不生效。',
setting_maxPage: '每次排序时统计的最大页数',
setting_hideWork: '隐藏收藏数少于设定值的作品',
setting_hideFav: '排序时隐藏已收藏的作品',
setting_hideFollowed: '排序时隐藏已关注画师作品',
setting_clearFollowingCache: '清除缓存',
setting_clearFollowingCacheHelp: '关注画师信息会在本地保存一天,如果希望立即更新,请点击清除缓存',
setting_followingCacheCleared: '已清除缓存,请刷新页面。',
setting_blank: '使用新标签页打开作品详情页',
setting_turnPage: '使用键盘←→进行翻页(排序后的搜索页)',
setting_save: '保存设置',
setting_reset: '重置脚本',
setting_resetHint: '这会删除所有设置,相当于重新安装脚本,确定要重置吗?',
setting_novelSort: '小说排序',
setting_novelMaxPage: '小说排序时统计的最大页数',
setting_novelHideWork: '隐藏收藏数少于设定值的作品',
setting_novelHideFav: '排序时隐藏已收藏的作品',
// 搜索时过滤值太高
sort_noWork: '没有可以显示的作品(隐藏了 %1 个作品)',
sort_getWorks: '正在获取第%1/%2页作品',
sort_getBookmarkCount: '获取收藏数:%1/%2',
sort_getPublicFollowing: '获取公开关注画师',
sort_getPrivateFollowing: '获取私有关注画师',
sort_filtering: '过滤%1收藏量低于%2的作品',
sort_filteringHideFavorite: '已收藏和',
sort_fullSizeThumb: '全尺寸缩略图(搜索页、用户页)',
// 小说排序
nsort_getWorks: '正在获取第1%/2%页作品',
nsort_sorting: '正在按收藏量排序',
nsort_hideFav: '排序时隐藏已收藏的作品',
nsort_hideFollowed: '排序时隐藏已关注作者作品'
};
// translate by google
Texts[Lang.en_US] = {
install_title: 'Welcome to PixivPreviewer v',
install_body: '<div style="position: absolute;left: 50%;top: 30%;font-size: 20px; color: white;transform:translate(-50%,0);"><p style="text-indent: 2em;">Feedback questions and suggestions are welcome! ><a style="color: green;" href="https://greasyfork.org/zh-CN/scripts/30766-pixiv-previewer/feedback" target="_blank">Feedback Page</a><</p><br><p style="text-indent: 2em;">If you are using it for the first time, it is recommended to go to the<a style="color: green;" href="https://greasyfork.org/zh-CN/scripts/30766-pixiv-previewer" target="_blank"> Details Page </a>to see the script introduction.</p></div>',
upgrade_body: 'Feature<br><ul><li>Add bookmark count filter for novel sorting.</li><li>Add bookmarked filter for novel sorting.</li></ul>Fix<br><ul><li>Fix the problem which that the guide page may display in wrong language after reset the script.</li></ul>',
setting_language: 'Language',
setting_preview: 'Preview',
setting_sort: 'Sorting (Search page)',
setting_anime: 'Animation download (Preview and Artwork page)',
setting_origin: 'Display original image when preview (slow)',
setting_previewDelay: 'Delay of display preview image(Million seconds)',
setting_previewByKey: 'Use keys to control the preview image display (Ctrl)',
setting_previewByKeyHelp: 'After enabling it, move the mouse to the picture and no longer display the preview image. Press the Ctrl key to display it, and the "Delayed Display Preview" setting item does not take effect.',
setting_maxPage: 'Maximum number of pages counted per sort',
setting_hideWork: 'Hide works with bookmark count less than set value',
setting_hideFav: 'Hide favorites when sorting',
setting_hideFollowed: 'Hide artworks of followed artists when sorting',
setting_clearFollowingCache: 'Cache',
setting_clearFollowingCacheHelp: 'The folloing artists info. will be saved locally for one day, if you want to update immediately, please click this to clear cache',
setting_followingCacheCleared: 'Success, please refresh the page.',
setting_blank: 'Open works\' details page in new tab',
setting_turnPage: 'Use ← → to turn pages (Search page)',
setting_save: 'Save',
setting_reset: 'Reset',
setting_resetHint: 'This will delete all settings and set it to default. Are you sure?',
setting_novelSort: 'Sorting (Novel)',
setting_novelMaxPage: 'Maximum number of pages counted for novel sorting',
setting_novelHideWork: 'Hide works with bookmark count less than set value',
setting_novelHideFav: 'Hide favorites when sorting',
sort_noWork: 'No works to display (%1 works hideen)',
sort_getWorks: 'Getting artworks of page: %1 of %2',
sort_getBookmarkCount: 'Getting bookmark count of artworks:%1 of %2',
sort_getPublicFollowing: 'Getting public following list',
sort_getPrivateFollowing: 'Getting private following list',
sort_filtering: 'Filtering%1works with bookmark count less than %2',
sort_filteringHideFavorite: ' favorited works and ',
sort_fullSizeThumb: 'Display not cropped images.(Search page and User page only.)',
nsort_getWorks: 'Getting novels of page: 1% of 2%',
nsort_sorting: 'Sorting by bookmark cound',
nsort_hideFav: 'Hide favorites when sorting',
nsort_hideFollowed: 'Hide artworks of followed authors when sorting'
};
// RU: перевод от vanja-san
Texts[Lang.ru_RU] = {
install_title: 'Добро пожаловать в PixivPreviewer v',
install_body: '<div style="position: absolute;left: 50%;top: 30%;font-size: 20px; color: white;transform:translate(-50%,0);"><p style="text-indent: 2em;">Вопросы и предложения приветствуются! ><a style="color: green;" href="https://greasyfork.org/zh-CN/scripts/30766-pixiv-previewer/feedback" target="_blank">Страница обратной связи</a><</p><br><p style="text-indent: 2em;">Если вы используете это впервые, рекомендуется перейти к<a style="color: green;" href="https://greasyfork.org/zh-CN/scripts/30766-pixiv-previewer" target="_blank"> Странице подробностей </a>, чтобы посмотреть введение в скрипт.</p></div>',
upgrade_body: Texts[Lang.en_US].upgrade_body,
setting_language: 'Язык',
setting_preview: 'Предпросмотр',
setting_sort: 'Сортировка (Страница поиска)',
setting_anime: 'Анимация скачивания (Страницы предпросмотра и Artwork)',
setting_origin: 'При предпросмотре, показывать изображения с оригинальным качеством (медленно)',
setting_previewDelay: 'Задержка отображения предпросмотра изображения (Миллион секунд)',
setting_previewByKey: Texts[Lang.en_US].setting_previewByKey,
setting_previewByKeyHelp: Texts[Lang.en_US].setting_previewByKeyHelp,
setting_maxPage: 'Максимальное количество страниц, подсчитанных за сортировку',
setting_hideWork: 'Скрыть работы с количеством закладок меньше установленного значения',
setting_hideFav: 'При сортировке, скрыть избранное',
setting_hideFollowed: 'При сортировке, скрыть работы художников на которых подписаны',
setting_clearFollowingCache: 'Кэш',
setting_clearFollowingCacheHelp: 'Следующая информация о художниках будет сохранена локально в течение одного дня, если вы хотите обновить её немедленно, нажмите на эту кнопку, чтобы очистить кэш',
setting_followingCacheCleared: 'Готово, обновите страницу.',
setting_blank: 'Открывать страницу с описанием работы на новой вкладке',
setting_turnPage: 'Использовать ← → для перелистывания страниц (Страница поиска)',
setting_save: 'Сохранить',
setting_reset: 'Сбросить',
setting_resetHint: 'Это удалит все настройки и установит их по умолчанию. Продолжить?',
setting_novelSort: Texts[Lang.en_US].setting_novelSort,
setting_novelMaxPage: Texts[Lang.en_US].setting_novelMaxPage,
setting_novelHideWork: 'Скрыть работы с количеством закладок меньше установленного значения',
setting_novelHideFav: 'При сортировке, скрыть избранное',
sort_noWork: 'Нет работ для отображения (%1 works hidden)',
sort_getWorks: 'Получение иллюстраций страницы: %1 из %2',
sort_getBookmarkCount: 'Получение количества закладок artworks:%1 из %2',
sort_getPublicFollowing: 'Получение публичного списка подписок',
sort_getPrivateFollowing: 'Получение приватного списка подписок',
sort_filtering: 'Фильтрация %1 работ с количеством закладок меньше чем %2',
sort_filteringHideFavorite: ' избранные работы и ',
sort_fullSizeThumb: 'Показать неотредактированное изображение (Страницы поиска и Artwork)',
nsort_getWorks: Texts[Lang.en_US].nsort_getWorks,
nsort_sorting: Texts[Lang.en_US].nsort_sorting,
nsort_hideFav: Texts[Lang.en_US].nsort_hideFav,
nsort_hideFollowed: Texts[Lang.en_US].nsort_hideFollowed
};
let LogLevel = {
None: 0,
Error: 1,
Warning: 2,
Info: 3,
Elements: 4,
};
function DoLog(level, msgOrElement) {
if (level <= g_logLevel) {
let prefix = '%c';
let param = '';
if (level == LogLevel.Error) {
prefix += '[Error]';
param = 'color:#ff0000';
} else if (level == LogLevel.Warning) {
prefix += '[Warning]';
param = 'color:#ffa500';
} else if (level == LogLevel.Info) {
prefix += '[Info]';
param = 'color:#000000';
} else if (level == LogLevel.Elements) {
prefix += 'Elements';
param = 'color:#000000';
}
if (level != LogLevel.Elements) {
console.log(prefix + msgOrElement, param);
} else {
console.log(msgOrElement);
}
if (++g_logCount > 512) {
//console.clear();
g_logCount = 0;
}
}
}
// 语言
let g_language = Lang.zh_CN;
// 版本号,第三位不需要跟脚本的版本号对上,第三位更新只有需要弹更新提示的时候才需要更新这里
let g_version = '3.7.6';
// 添加收藏需要这个
let g_csrfToken = '';
// 打的日志数量,超过一定数值清空控制台
let g_logCount = 0;
// 当前页面类型
let g_pageType = -1;
// 图片详情页的链接,使用时替换 #id#
let g_artworkUrl = '/artworks/#id#';
// 获取图片链接的链接
let g_getArtworkUrl = '/ajax/illust/#id#/pages';
// 获取动图下载链接的链接
let g_getUgoiraUrl = '/ajax/illust/#id#/ugoira_meta';
// 获取小说列表的链接
let g_getNovelUrl = '/ajax/search/novels/#key#?word=#key#&p=#page#'
// 鼠标位置
let g_mousePos = { x: 0, y: 0 };
// 加载中图片
let g_loadingImage = 'https://pp-1252089172.cos.ap-chengdu.myqcloud.com/loading.gif';
// 页面打开时的 url
let initialUrl = location.href;
// 默认设置,仅用于首次脚本初始化
let g_defaultSettings = {
'lang': -1,
'enablePreview': 1,
'enableSort': 1,
'enableAnimeDownload': 1,
'original': 0,
'previewDelay': 200,
'previewByKey': 0,
'previewKey': 17,
'pageCount': 3,
'favFilter': 0,
'hideFavorite': 0,
'hideFollowed': 0,
'linkBlank': 1,
'pageByKey': 0,
'fullSizeThumb': 0,
'enableNovelSort': 1,
'novelPageCount': 3,
'novelFavFilter': 0,
'novelHideFavorite': 0,
'novelHideFollowed': 0,
'logLevel': 1,
'version': g_version,
};
// 设置
let g_settings;
// 日志等级
let g_logLevel = LogLevel.Error;
// 排序时同时请求收藏量的 Request 数量,没必要太多,并不会加快速度
let g_maxXhr = 64;
// 排序是否完成(如果排序时页面出现了非刷新切换,强制刷新)
let g_sortComplete = true;
// 页面相关的一些预定义,包括处理页面元素等
let PageType = {
// 搜索(不包含小说搜索)
Search: 0,
// 关注的新作品
BookMarkNew: 1,
// 发现
Discovery: 2,
// 用户主页
Member: 3,
// 首页
Home: 4,
// 排行榜
Ranking: 5,
// 大家的新作品
NewIllust: 6,
// R18
R18: 7,
// 自己的收藏页
BookMark: 8,
// 动态
Stacc: 9,
// 作品详情页(处理动图预览及下载)
Artwork: 10,
// 小说页
NovelSearch: 11,
// 总数
PageTypeCount: 12,
};
let Pages = {};
/* Pages 必须实现的函数
* PageTypeString: string,字符串形式的 PageType
* bool CheckUrl: function(string url),用于检查一个 url 是否是当前页面的目标 url
* ReturnMap ProcessPageElements: function(),处理页面(寻找图片元素、添加属性等),返回 ReturnMap
* ReturnMap GetProcessedPageElements: function(), 返回上一次 ProcessPageElements 的返回值(如果没有上次调用则调用一次)
* Object GetToolBar: function(), 返回工具栏元素(右下角那个,用来放设置按钮)
* HasAutoLoad: bool,表示这个页面是否有自动加载功能
*/
let ReturnMapSample = {
// 页面是否加载完成,false 意味着后面的成员无效
loadingComplete: false,
// 控制元素,每个图片的鼠标响应元素
controlElements: [],
// 可有可无,如果为 true,强制重新刷新预览功能
forceUpdate: false,
};
let ControlElementsAttributesSample = {
// 图片信息,内容如下:
// [必需] 图片 id
illustId: 0,
// [必需] 图片类型(0:普通图片,2:动图)
illustType: 0,
// [必需] 页数
pageCount: 1,
// [可选] 标题
title: '',
// [可选] 作者 id
userId: 0,
// [可选] 作者昵称
userName: '',
// [可选] 收藏数
bookmarkCount: 0,
};
function findToolbarCommon() {
// 目前第三级div,除了目标div外,子元素都是div
return $('#root>div>div>ul').get(0);
}
function findToolbarOld() {
return $('._toolmenu').get(0);
}
function convertThumbUrlToSmall(thumbUrl) {
// 目前发现有以下两种格式的缩略图
// https://i.pximg.net/c/128x128/custom-thumb/img/2021/01/31/20/35/53/87426718_p0_custom1200.jpg
// https://i.pximg.net/c/128x128/img-master/img/2021/01/31/10/57/06/87425082_p0_square1200.jpg
let replace1 = 'c/540x540_70/img-master';
//let replace1 = 'img-master'; // 这个是转到regular的,比small的大多了,会很慢
let replace2 = '_master';
return thumbUrl.replace(/c\/.*\/custom-thumb/, replace1).replace('_custom', replace2)
.replace(/c\/.*\/img-master/, replace1).replace('_square', replace2);
}
function processElementListCommon(lis) {
$.each(lis, function (i, e) {
let li = $(e);
// 只填充必须的几个,其他的目前用不着
let ctlAttrs = {
illustId: 0,
illustType: 0,
pageCount: 1,
};
let img = $(li.find('img').get(0));
let imageLink = img.parent().parent();
let additionDiv = img.parent().prev();
let animationSvg = img.parent().find('svg');
let pageCountSpan = additionDiv.find('span');
if (img == null || imageLink == null) {
DoLog(LogLevel.Warning, 'Can not found img or imageLink, skip this.');
return;
}
let link = imageLink.attr('href');
if (link == null) {
DoLog(LogLevel.Warning, 'Invalid href, skip this.');
return;
}
let linkMatched = link.match(/artworks\/(\d+)/);
let illustId = '';
if (linkMatched) {
ctlAttrs.illustId = linkMatched[1];
} else {
DoLog(LogLevel.Error, 'Get illustId failed, skip this list item!');
return;
}
if (animationSvg.length > 0) {
ctlAttrs.illustType = 2;
}
if (pageCountSpan.length > 0) {
ctlAttrs.pageCount = parseInt(pageCountSpan.text());
}
// 添加 attr
let control = li.children('div:first').children('div:first');
control.attr({
'illustId': ctlAttrs.illustId,
'illustType': ctlAttrs.illustType,
'pageCount': ctlAttrs.pageCount
});
control.addClass('pp-control');
});
}
function replaceThumbCommon(elements) {
$.each(elements, (i, e) => {
e = $(e);
let img = e.find('img');
if (img.length == 0) {
iLog.w('No img in the control element.');
return true;
}
let src = img.attr('src');
let fullSizeSrc = convertThumbUrlToSmall(src);
if (src != fullSizeSrc) {
img.attr('src', fullSizeSrc).css('object-fit', 'contain');
}
});
}
Pages[PageType.Search] = {
PageTypeString: 'SearchPage',
CheckUrl: function (url) {
// 没有 /artworks 的页面不支持
return /^https?:\/\/www.pixiv.net\/tags\/.*\/(artworks|illustrations|manga)/.test(url) ||
/^https?:\/\/www.pixiv.net\/en\/tags\/.*\/(artworks|illustrations|manga)/.test(url);
},
ProcessPageElements: function () {
let returnMap = {
loadingComplete: false,
controlElements: [],
};
let sections = $('section');
DoLog(LogLevel.Info, 'Page has ' + sections.length + ' <section>.');
DoLog(LogLevel.Elements, sections);
let premiumSectionIndex = -1;
let resultSectionIndex = 0;
if (sections.length == 0) {
iLog.e('No suitable <section>!');
return returnMap;
}
$.each(sections, (i, e) => {
if ($(e).find('aside').length > 0) {
premiumSectionIndex = i;
} else {
resultSectionIndex = i;
}
});
iLog.v('premium: ' + premiumSectionIndex);
iLog.v('result: ' + resultSectionIndex);
let ul = $(sections[resultSectionIndex]).find('ul');
let lis = ul.find('li').toArray();
if (premiumSectionIndex != -1) {
let lis2 = $(sections[premiumSectionIndex]).find('ul').find('li');
lis = lis.concat(lis2.toArray());
}
if (premiumSectionIndex != -1) {
let aside = $(sections[premiumSectionIndex]).find('aside');
$.each(aside.children(), (i, e) => {
if (e.tagName.toLowerCase() != 'ul') {
e.remove();
} else {
$(e).css('-webkit-mask', '0');
}
});
aside.next().remove();
}
processElementListCommon(lis);
returnMap.controlElements = $('.pp-control');
this.private.pageSelector = ul.next().get(0);
returnMap.loadingComplete = true;
this.private.imageListConrainer = ul.get(0);
DoLog(LogLevel.Info, 'Process page elements complete.');
DoLog(LogLevel.Elements, returnMap);
this.private.returnMap = returnMap;
return returnMap;
},
GetProcessedPageElements: function () {
if (this.private.returnMap == null) {
return this.ProcessPageElements();
}
return this.private.returnMap;
},
GetToolBar: function () {
return findToolbarCommon();
},
// 搜索页有 lazyload,不开排序的情况下,最后几张图片可能会无法预览。这里把它当做自动加载处理
HasAutoLoad: true,
GetImageListContainer: function () {
return this.private.imageListConrainer;
},
GetFirstImageElement: function () {
return $(this.private.imageListConrainer).find('li').get(0);
},
GetPageSelector: function () {
return this.private.pageSelector;
},
private: {
imageListContainer: null,
pageSelector: null,
returnMap: null,
},
};
Pages[PageType.BookMarkNew] = {
PageTypeString: 'BookMarkNewPage',
CheckUrl: function (url) {
return /^https:\/\/www.pixiv.net\/bookmark_new_illust.php.*/.test(url) ||
/^https:\/\/www.pixiv.net\/bookmark_new_illust_r18.php.*/.test(url);
},
ProcessPageElements: function () {
let returnMap = {
loadingComplete: false,
controlElements: [],
};
let sections = $('section');
DoLog(LogLevel.Info, 'Page has ' + sections.length + ' <section>.');
DoLog(LogLevel.Elements, sections);
let lis = sections.find('ul').find('li');
processElementListCommon(lis);
returnMap.controlElements = $('.pp-control');
returnMap.loadingComplete = true;
DoLog(LogLevel.Info, 'Process page elements complete.');
DoLog(LogLevel.Elements, returnMap);
this.private.returnMap = returnMap;
// 全尺寸缩略图
if (g_settings.fullSizeThumb) {
if (!this.private.returnMap.loadingComplete) {
return;
}
replaceThumbCommon(this.private.returnMap.controlElements);
}
return returnMap;
},
GetProcessedPageElements: function () {
if (this.private.returnMap == null) {
return this.ProcessPageElements();
}
return this.private.returnMap;
},
GetToolBar: function () {
return findToolbarCommon();
},
HasAutoLoad: true,
private: {
returnMap: null,
},
};
Pages[PageType.Discovery] = {
PageTypeString: 'DiscoveryPage',
CheckUrl: function (url) {
return /^https?:\/\/www.pixiv.net\/discovery.*/.test(url);
},
ProcessPageElements: function () {
let returnMap = {
loadingComplete: false,
controlElements: [],
};
let containerDiv = $('.gtm-illust-recommend-zone');
if (containerDiv.length > 0) {
DoLog(LogLevel.Info, 'Found container div.');
DoLog(LogLevel.Elements, containerDiv);
} else {
DoLog(LogLevel.Error, 'Can not found container div.');
return returnMap;
}
let lis = containerDiv.find('ul').children('li');
processElementListCommon(lis);
returnMap.controlElements = $('.pp-control');
returnMap.loadingComplete = true;
DoLog(LogLevel.Info, 'Process page elements complete.');
DoLog(LogLevel.Elements, returnMap);
this.private.returnMap = returnMap;
return returnMap;
},
GetProcessedPageElements: function () {
if (this.private.returnMap == null) {
return this.ProcessPageElements();
}
return this.private.returnMap;
},
GetToolBar: function () {
return findToolbarCommon();
},
HasAutoLoad: true,
private: {
returnMap: null,
},
};
Pages[PageType.Member] = {
PageTypeString: 'MemberPage/MemberIllustPage/MemberBookMark',
CheckUrl: function (url) {
return /^https?:\/\/www.pixiv.net\/users\/\d+/.test(url);
},
ProcessPageElements: function () {
let returnMap = {
loadingComplete: false,
controlElements: [],
};
let sections = $('section');
DoLog(LogLevel.Info, 'Page has ' + sections.length + ' <section>.');
DoLog(LogLevel.Elements, sections);
let lis = sections.find('ul').find('li');
processElementListCommon(lis);
returnMap.controlElements = $('.pp-control');
returnMap.loadingComplete = true;
DoLog(LogLevel.Info, 'Process page elements complete.');
DoLog(LogLevel.Elements, returnMap);
this.private.returnMap = returnMap;
// 全尺寸缩略图
if (g_settings.fullSizeThumb) {
if (!this.private.returnMap.loadingComplete) {
return;
}
replaceThumbCommon(this.private.returnMap.controlElements);
}
return returnMap;
},
GetProcessedPageElements: function () {
if (this.private.returnMap == null) {
return this.ProcessPageElements();
}
return this.private.returnMap;
},
GetToolBar: function () {
return findToolbarCommon();
},
// 跟搜索页一样的情况
HasAutoLoad: true,
private: {
returnMap: null,
},
};
Pages[PageType.Home] = {
PageTypeString: 'HomePage',
CheckUrl: function (url) {
return /https?:\/\/www.pixiv.net\/?$/.test(url) ||
/https?:\/\/www.pixiv.net\/en\/?$/.test(url) ||
/https?:\/\/www.pixiv.net\/cate_r18\.php$/.test(url) ||
/https?:\/\/www.pixiv.net\/en\/cate_r18\.php$/.test(url);
},
ProcessPageElements: function () {
let returnMap = {
loadingComplete: false,
controlElements: [],
forceUpdate: false,
};
let illust_div = $('div[type="illust"]');
DoLog(LogLevel.Info, 'This page has ' + illust_div.length + ' illust <div>.');
if (illust_div.length < 1) {
DoLog(LogLevel.Warning, 'Less than one <div>, continue waiting.');
return returnMap;
}
// 实际里面还套了一个 div,处理一下,方便一点
let illust_div_c = [];
illust_div.each(function (i, e) {
illust_div_c.push($(e).children('div:first'));
});
illust_div = illust_div_c;
$.each(illust_div, function (i, e) {
let _this = $(e);
let a = _this.children('a:first');
if (a.length == 0 || a.attr('href').indexOf('artworks') == -1) {
DoLog(LogLevel.Warning, 'No href or an invalid href was found, skip this.');
return;
}
let ctlAttrs = {
illustId: 0,
illustType: 0,
pageCount: 1,
};
let illustId = a.attr('href').match(/\d+/);
if (illustId == null) {
DoLog(LogLevel.Warning, 'Can not found illust id of this image, skip.');
return;
} else {
ctlAttrs.illustId = illustId[0];
}
let pageCount = a.find('span:first').next();
if (pageCount.length > 0) {
ctlAttrs.pageCount = parseInt($(pageCount.get(pageCount.length - 1)).text());
}
if ($(a.children('div').get(0)).children('svg').length > 0) {
ctlAttrs.illustType = 2;
}
let control = a;
if (control.attr('illustId') != ctlAttrs.illustId) {
returnMap.forceUpdate = true;
}
control.attr({
'illustId': ctlAttrs.illustId,
'illustType': ctlAttrs.illustType,
'pageCount': ctlAttrs.pageCount
});
returnMap.controlElements.push(control.get(0));
});
DoLog(LogLevel.Info, 'Process page elements complete.');
DoLog(LogLevel.Elements, returnMap);
returnMap.loadingComplete = true;
this.private.returnMap = returnMap;
return returnMap;
},
GetProcessedPageElements: function () {
if (this.private.returnMap == null) {
return this.ProcessPageElements();
}
return this.private.returnMap;
},
GetToolBar: function () {
return findToolbarCommon();
},
HasAutoLoad: true,
private: {
returnMap: null,
},
};
Pages[PageType.Ranking] = {
PageTypeString: 'RankingPage',
CheckUrl: function (url) {
return /^https?:\/\/www.pixiv.net\/ranking.php.*/.test(url);
},
ProcessPageElements: function () {
let returnMap = {
loadingComplete: false,
controlElements: [],
};
let works = $('._work');
DoLog(LogLevel.Info, 'Found .work, length: ' + works.length);
DoLog(LogLevel.Elements, works);
works.each(function (i, e) {
let _this = $(e);
let ctlAttrs = {
illustId: 0,
illustType: 0,
pageCount: 1,
};
let href = _this.attr('href');
if (href == null || href === '') {
DoLog('Can not found illust id, skip this.');
return;
}
let matched = href.match(/artworks\/(\d+)/);
if (matched) {
ctlAttrs.illustId = matched[1];
} else {
DoLog('Can not found illust id, skip this.');
return;
}
if (_this.hasClass('multiple')) {
ctlAttrs.pageCount = _this.find('.page-count').find('span').text();
}
if (_this.hasClass('ugoku-illust')) {
ctlAttrs.illustType = 2;
}
// 添加 attr
_this.attr({
'illustId': ctlAttrs.illustId,
'illustType': ctlAttrs.illustType,
'pageCount': ctlAttrs.pageCount
});
returnMap.controlElements.push(e);
});
returnMap.loadingComplete = true;
DoLog(LogLevel.Info, 'Process page elements complete.');
DoLog(LogLevel.Elements, returnMap);
this.private.returnMap = returnMap;
return returnMap;
},
GetProcessedPageElements: function () {
if (this.private.returnMap == null) {
return this.ProcessPageElements();
}
return this.private.returnMap;
},
GetToolBar: function () {
return findToolbarOld();
},
HasAutoLoad: true,
private: {
returnMap: null,
},
};
Pages[PageType.NewIllust] = {
PageTypeString: 'NewIllustPage',
CheckUrl: function (url) {
return /^https?:\/\/www.pixiv.net\/new_illust.php.*/.test(url);
},
ProcessPageElements: function () {
let returnMap = {
loadingComplete: false,
controlElements: [],
};
let ul = $('#root').find('ul:first');
if (ul.length === 0) {
DoLog(LogLevel.Error, 'Can not found <ul>!');
return returnMap;
}
ul.find('li').each(function (i, e) {
let _this = $(e);
let link = _this.find('a:first');
let href = link.attr('href');
if (href == null || href === '') {
DoLog(LogLevel.Error, 'Can not found illust id, skip this.');
return;
}
let ctlAttrs = {
illustId: 0,
illustType: 0,
pageCount: 1,
};
let matched = href.match(/artworks\/(\d+)/);
if (matched) {
ctlAttrs.illustId = matched[1];
} else {
DoLog(LogLevel.Warning, 'Can not found illust id, skip this.');
return;
}
if (link.children().length > 1) {
let span = link.find('svg').parent().parent().next();
if (span.length > 0 && span.get(0).tagName == 'SPAN') {
ctlAttrs.pageCount = span.text();
} else if (link.find('svg').length > 0) {
ctlAttrs.illustType = 2;
}
}
let control = _this.children('div:first').children('div:first');
control.attr({
'illustId': ctlAttrs.illustId,
'illustType': ctlAttrs.illustType,
'pageCount': ctlAttrs.pageCount
});
returnMap.controlElements.push(control.get(0));
});
returnMap.loadingComplete = true;
DoLog(LogLevel.Info, 'Process page elements complete.');
DoLog(LogLevel.Elements, returnMap);