-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPornHub Plus.user.js
1362 lines (1144 loc) · 41.4 KB
/
PornHub Plus.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==
// @author Mr. Nope
// @version 2022-07-23
// @name PornHub Plus
// @match *://*.pornhub.com/*
// @match *://*.pornhubpremium.com/*
// @description A kinder PornHub. Because you're worth it.
// @date 2022-07-23
// @license CC0
// ==/UserScript==
/**
* # CHANGELOG
*
* ## 2022-07-22
*
* Adapting the script for modern user script managers that maximise their use of the WebExtension
* API for higher quality and better performing solutions more integrated with the browser without
* questionable implementation choices.
*
* Changes mean less meta-data and no more wrapper functions. It's currently only being tested in
* FireMonkey but incompatibilities should be minor and simple to fix.
*
* ### Features
*
* - **Redirect to free if a model has no premium videos**
* Videos pages of models with no premium content redirects to free, as many popular models
* don't make premium videos and there's no way to toggle free content. Removing "premium"
* from the URL can reveal tons of videos.
*
* ### Chores
*
* - Adding the changelog which for now resides in the script itself.
* - Formatting properly and removing unnecessary wrapper functions.
* - Adding Prettier and EditorConfig formatter rules (not yet automated).
*
* ### Notes
*
* - Switching from SemVer to DateVer for simplicity (nobody gives a shit except the updater).
* - Needs a major overhaul and should be rewritten for more structure.
* - Tooling would be useful: NPM, linting, formatting, versioning, changelog generation, etc.
*/
'use strict';
setTimeout(() => {
const OPTIONS = {
showTitles: JSON.parse(localStorage.getItem('plus_showTitles')) || false,
loadMore: JSON.parse(localStorage.getItem('plus_loadMore')) || true,
cinemaMode: JSON.parse(localStorage.getItem('plus_cinemaMode')) || false,
openWithoutPlaylist: JSON.parse(localStorage.getItem('plus_openWithoutPlaylist')) || true,
showOnlyHd: JSON.parse(localStorage.getItem('plus_showOnlyHd')) || false,
redirectToVideos: JSON.parse(localStorage.getItem('plus_redirectToVideos')) || false,
redirectPremiumVideos: JSON.parse(localStorage.getItem('plus_redirectPremiumVideos')) || false,
hideWatchedVideos: JSON.parse(localStorage.getItem('plus_hideWatchedVideos')) || false,
hidePlaylistBar: JSON.parse(localStorage.getItem('plus_hidePlaylistBar')) || false,
durationFilter: JSON.parse(localStorage.getItem('plus_durationFilter')) || {
max: 0,
min: 0
},
durationPresets: [{
label: 'Micro',
min: 0,
max: 2
},
{
label: 'Short',
min: 3,
max: 8
},
{
label: 'Average',
min: 8,
max: 18
},
{
label: 'Long',
min: 18,
max: 40
},
{
label: 'Magnum',
min: 40,
max: 0
}
],
relatedColumns: JSON.parse(localStorage.getItem('plus_relatedColumns')) || 3,
};
/**
* Player settings
*
* Reference as of 8/16/2022:
* {
* "buildNumber": "220808.544",
* "version": "6.2.2",
* "adrolls": {
* "0": {
* "commonTime": 0,
* "views": 0,
* "timeouts": {
* "attempt": 0,
* "time": 0,
* "report": true
* }
* }
* },
* "quality": 1080,
* "playbackRate": 1,
* "adaptive": {
* "hlsLevel": 2
* },
* "volume": {
* "volume": 52,
* "muted": false
* },
* "focusedPlayer": "playerDiv_336166192"
* }
*/
// const playerSettings = JSON.parse(localStorage.getItem('mgp_player'));
// Change default quality from 720p to 1080p
// playerSettings.quality = 1080;
// Prevent problem with videos not loading unless clearing cache and reloading.
// localStorage.setItem('mgp_player', JSON.stringify(playerSettings));
/**
* Shared styles
*/
const sharedStyles = `
/* Our own elements */
.plus-buttons {
background: rgba(27, 27, 27, 0.9);
box-shadow: 0px 0px 12px rgba(20, 111, 223, 0.9);
font-size: 12px;
position: fixed;
bottom: 10px;
padding: 10px 22px 8px 24px;
right: 0;
z-index: 100;
transition: all 0.2s ease;
/* Negative margin-right calculated later based on width of buttons */
}
.plus-buttons:hover {
box-shadow: 0px 0px 3px rgba(0, 0, 0, 0.3);
}
.plus-buttons .plus-button {
margin: 10px 0;
padding: 6px 15px;
border-radius: 4px;
font-weight: 700;
display: block;
position: relative;
text-align: center;
vertical-align: top;
cursor: pointer;
border: none;
text-decoration: none;
}
.plus-buttons a.plus-button {
background: rgb(221, 221, 221);
color: rgb(51, 51, 51);
}
.plus-buttons a.plus-button:hover {
background: rgb(187, 187, 187);
color: rgb(51, 51, 51);
}
.plus-buttons a.plus-button.plus-button-isOn {
background: rgb(20, 111, 223);
color: rgb(255, 255, 255);
}
.plus-buttons a.plus-button.plus-button-isOn:hover {
background: rgb(0, 91, 203);
color: rgb(255, 255, 255);
}
.plus-hidden {
display: none !important;
}
.plus-letters {
align-items: center;
color: #ccc;
display: flex;
justify-content: space-between;
margin: 0 22px 18px;
text-transform: uppercase;
}
.plus-letters span {
cursor: pointer;
}
`;
/**
* Color Theme
*/
const themeStyles = `
.plus-buttons {
box-shadow: 0px 0px 12px rgba(255, 153, 0, 0.85);
}
.plus-buttons:hover {
box-shadow: 0px 0px 3px rgba(0, 0, 0, 0.3);
}
.plus-buttons a.plus-button {
background: rgb(47, 47, 47);
color: rgb(172, 172, 172);
}
.plus-buttons a.plus-button:hover {
background: rgb(79, 79, 79);
color: rgb(204, 204, 204);
}
.plus-buttons a.plus-button.plus-button-isOn {
background: rgb(255, 153, 0);
color: rgb(0, 0, 0);
}
.plus-buttons a.plus-button.plus-button-isOn:hover {
background: rgb(255, 153, 0);
color: rgb(255, 255, 255);
}
`;
/**
* Site-Specific Styles
*/
const generalStyles = `
/* Hide elements */
.realsex,
.mhp1138_cinemaState,
.networkBar,
.sniperModeEngaged,
.footer,
.footer-title,
.ad-link,
.removeAdLink,
.removeAdLink + iframe,
.abovePlayer,
.streamatesModelsContainer,
#welcome,
#welcomePremium,
#headerUpgradePremiumBtn,
#PornhubNetworkBar,
#js-abContainterMain,
#hd-rightColVideoPage > :not(#relatedVideosVPage),
.bottomNotification,
.trailerUnderplayerPreview,
.sectionCarousel {
display: none !important;
visibility: hidden !important;
opacity: 0 !important;
height: 0 !important;
width: 0 !important;
}
/* Allow narrower page width */
html.supportsGridLayout.fluidContainer .container,
html.supportsGridLayout.fluidContainer .section_wrapper {
min-width: 700px !important;
}
/* Hide tricky ads with obfuscated tag names */
.adLinks + *,
.adLinks + * + *,
.wrapper.hd + * {
display: none !important;
}
/* Full-width video */
#vpContentContainer {
display: block !important;
}
/* Recommended videos */
#recommendedVideosVPage {
text-align: center !important;
}
/* "Recommended Porn" heading */
#recommendedVideosVPage h3 {
text-align: center !important;
display: block !important;
float: unset !important;
}
/* Recommended videos layout */
#recommendedVideos {
list-style: none !important;
display: flex !important;
flex-direction: row !important;
align-items: flex-start !important;
justify-content: space-between !important;
text-align: left !important;
}
/* Thumbnail wrapper */
#recommendedVideosPage .videoBox {
font-size: 0.813rem !important; /* 13px/16px = 0.813rem */
color: #a6adc8 !important; /* Mocha -> Subtext0 */
margin: 0 5px !important;
}
/* Thumbnail wrapper */
#recommendedVideos .videoBox .phimage {
width: auto !important;
border-radius: 4px !important;
}
/* Thumbnail info wrapper */
.thumbnail-info-wrapper {
color: #a6adc8 !important; /* Mocha -> Subtext0 */
font-size: 0.813rem !important; /* 13px/16px = 0.813rem */
float: none !important;
width: auto !important;
}
/* Title of video or playlist */
.thumbnail-info-wrapper .title {
font-size: 0.813rem !important;
font-weight: 700 !important;
margin: 12px 0 3px !important;
}
/* The user/channel name wrapper */
.thumbnail-info-wrapper .usernameWrap {
margin-top: -1px; /* Fixes slight off-center text */
}
/* The user/channel name link */
.thumbnail-info-wrapper .usernameWrap a {
font-size: 0.813rem !important; /* 13px/16px = 0.813rem */
color: #a6adc8 !important;
}
/* The verified badge and user/channel name wrapper */
.thumbnail-info-wrapper .videoUploaderBlock {
margin-bottom: 5px !important;
}
/* The verified badge */
.thumbnail-info-wrapper .own-video-thumbnail {
margin-right: 2px !important;
}
/* The views and likes wrapper */
.thumbnail-info-wrapper .videoDetailsBlock {
margin-bottom: 5px !important;
}
/* The views */
.thumbnail-info-wrapper .videoDetailsBlock .views {
font-size: 0.813rem !important; /* 13px/16px = 0.813rem */
}
/* The rating */
.thumbnail-info-wrapper .videoDetailsBlock .rating-container i,
.thumbnail-info-wrapper .videoDetailsBlock .rating-container .value {
font-size: 0.813rem !important; /* 13px/16px = 0.813rem */
}
/* The "load more" button */
.more_recommended_btn {
margin: 2rem 0 !important;
}
/* Make "HD" icon more visible on thumbnails */
.hd-thumbnail {
color: #f90 !important;
}
/* Show all playlists without scrolling in "add to" */
.slimScrollDiv {
height: auto !important;
}
#scrollbar_watch {
max-height: unset !important;
}
/* Hide premium video from related videos sidebar */
#relateRecommendedItems li:nth-of-type(5) {
display: none !important;
}
/* Prevent animating player size change on each page load */
#main-container .video-wrapper #player.wide {
transition: none !important;
}
/* Allow narrower player */
#player {
min-width: 0 !important;
}
/* Fit more playlists into "add to" popup */
.playlist-menu-addTo {
display: none;
}
.add-to-playlist-menu #scrollThumbs,
.playlist-option-menu #scrollThumbs {
height: 320px !important;
max-height: 35vh !important;
}
.add-to-playlist-menu ul.custom-playlist li {
font-size: 12px;
height: 24px;
}
.add-to-playlist-menu .playlist-menu-createNew {
font-size: 12px !important;
height: 38px !important;
}
.add-to-playlist-menu .playlist-menu-createNew a {
padding-top: 8px !important;
font-weight: 400 !important;
}
/* Hide playlist bar if disabled in options */
.playlist-bar {
display: ${OPTIONS.hidePlaylistBar ? 'none' : 'block'};
}
/**
* Improve loading indicator lines on thumbnails
*
* Using colors from the Catppuccin palette available at https://github.com/catppuccin.
*/
.preloadLine {
background: #81c8be; /* Mocha -> Teal */
box-shadow: 0 0 3px #1e1e2e; /* Mocha -> Base */
}
/* Fade in and out semitransparent elements */
.tab-menu-item {
opacity: 0.4 !important;
padding: 0 16px !important;
transition: all 0.2s ease !important;
}
.tab-menu-item.active {
opacity: 0.5 !important;
}
.tab-menu-wrapper-cell:hover .tab-menu-item {
opacity: 1 !important;
}
.votes-fav-wrap .icon-wrapper:hover,
.votes-fav-wrap .icon-wrapper.active:hover {
opacity: 1 !important;
}
.votes-fav-wrap .icon-wrapper {
opacity: 0.4 !important;
transition: all 0.2s ease !important;
}
.votes-fav-wrap .icon-wrapper.active {
opacity: 0.7 !important;
}
`;
/**
* References to video element and container if they exist on the page
*/
const player = document.querySelector('#player');
const video = document.querySelector('video');
const distractions = [
'.video-info-row:not(.userRow)',
'#header'
];
const isOnVideoPage =
/^http[s]*:\/\/[www.]*pornhub\.com\/view_video.php/.test(window.location.href) && player;
/**
* Creation of option buttons
*/
const showTitlesButton = document.createElement('a');
const showTitlesButtonText = document.createElement('span');
const showTitlesButtonState = getButtonState(OPTIONS.showTitles);
const loadMoreButton = document.createElement('a');
const loadMoreButtonText = document.createElement('span');
const loadMoreButtonState = getButtonState(OPTIONS.loadMore);
const cinemaButton = document.createElement('a');
const cinemaButtonText = document.createElement('span');
const cinemaButtonState = getButtonState(OPTIONS.cinemaMode);
const scrollButton = document.createElement('a');
const scrollButtonText = document.createElement('span');
const scrollPlaylistsButton = document.createElement('a');
const scrollPlaylistsButtonText = document.createElement('span');
const playlistBarButton = document.createElement('a');
const playlistBarButtonText = document.createElement('span');
const playlistBarButtonState = getButtonState(OPTIONS.hidePlaylistBar);
const verifiedButton = document.createElement('a');
const verifiedButtonText = document.createElement('span');
const verifiedButtonState = getButtonState(OPTIONS.showOnlyVerified);
const hideWatchedButton = document.createElement('a');
const hideWatchedButtonText = document.createElement('span');
const hideWatchedButtonState = getButtonState(OPTIONS.hideWatchedVideos);
const hdButton = document.createElement('a');
const hdButtonText = document.createElement('span');
const hdButtonState = getButtonState(OPTIONS.showOnlyHd);
const redirectToVideosButton = document.createElement('a');
const redirectToVideosButtonText = document.createElement('span');
const redirectToVideosButtonState = getButtonState(OPTIONS.redirectToVideos);
const redirectPremiumVideosButton = document.createElement('a');
const redirectPremiumVideosButtonText = document.createElement('span');
const redirectPremiumVideosButtonState = getButtonState(OPTIONS.redirectPremiumVideos);
const durationShortButton = document.createElement('a');
const durationShortButtonText = document.createElement('span');
const durationShortButtonState = getButtonState(!OPTIONS.durationFilter.min);
const durationMediumButton = document.createElement('a');
const durationMediumButtonText = document.createElement('span');
const durationMediumButtonState = getButtonState(OPTIONS.durationFilter.min <= 8 && OPTIONS.durationFilter.max >= 20);
const openWithoutPlaylistButton = document.createElement('a');
const openWithoutPlaylistButtonText = document.createElement('span');
const openWithoutPlaylistButtonState = getButtonState(OPTIONS.openWithoutPlaylist);
const largerButton = document.createElement('a');
const largerButtonText = document.createElement('span');
const smallerButton = document.createElement('a');
const smallerButtonText = document.createElement('span');
/**
* Returns an `on` or `off` CSS class name based on the boolean evaluation
* of the `state` parameter, as convenience method when setting UI state.
*/
function getButtonState(state) {
return state ? 'plus-button-isOn' : 'plus-button-isOff';
}
cinemaButtonText.textContent = 'Cinema Mode';
cinemaButtonText.classList.add('text');
cinemaButton.appendChild(cinemaButtonText);
cinemaButton.classList.add(cinemaButtonState, 'plus-button');
cinemaButton.addEventListener('click', () => {
OPTIONS.cinemaMode = !OPTIONS.cinemaMode;
localStorage.setItem('plus_cinemaMode', OPTIONS.cinemaMode);
if (OPTIONS.cinemaMode) {
cinemaButton.classList.replace('plus-button-isOff', 'plus-button-isOn');
} else {
cinemaButton.classList.replace('plus-button-isOn', 'plus-button-isOff');
}
if (isOnVideoPage) {
handleDistractions();
}
});
showTitlesButtonText.textContent = "Show video titles";
showTitlesButtonText.classList.add('text');
showTitlesButton.appendChild(showTitlesButtonText);
showTitlesButton.classList.add('plus-button');
showTitlesButton.addEventListener('click', () => {
const container = document.querySelector('#main-container');
if (isOnVideoPage) {
container.scrollIntoView();
}
});
loadMoreButtonText.textContent = "Autoload more";
loadMoreButtonText.classList.add('text');
loadMoreButton.appendChild(loadMoreButtonText);
loadMoreButton.classList.add('plus-button');
loadMoreButton.addEventListener('click', () => {
if (OPTIONS.loadMore) {
loadMoreButton.classList.replace('plus-button-isOff', 'plus-button-isOn');
} else {
loadMoreButton.classList.replace('plus-button-isOn', 'plus-button-isOff');
}
if (document.querySelector('.videoBox') && OPTIONS.loadMore) {
loadMore();
}
});
scrollButtonText.textContent = "Scroll to Video";
scrollButtonText.classList.add('text');
scrollButton.appendChild(scrollButtonText);
scrollButton.classList.add('plus-button');
scrollButton.addEventListener('click', () => {
const container = document.querySelector('#main-container');
if (container) {
container.scrollIntoView();
}
});
scrollPlaylistsButtonText.textContent = "Scroll to Playlists";
scrollPlaylistsButtonText.classList.add('text');
scrollPlaylistsButton.appendChild(scrollPlaylistsButtonText);
scrollPlaylistsButton.classList.add('plus-button');
scrollPlaylistsButton.addEventListener('click', () => {
const container = document.querySelector('#under-player-playlists');
if (container) {
container.scrollIntoView();
}
});
verifiedButtonText.textContent = 'Verified Only';
verifiedButtonText.classList.add('text');
verifiedButton.appendChild(verifiedButtonText);
verifiedButton.classList.add(verifiedButtonState, 'plus-button');
verifiedButton.addEventListener('click', () => {
OPTIONS.showOnlyVerified = !OPTIONS.showOnlyVerified;
localStorage.setItem('plus_showOnlyVerified', OPTIONS.showOnlyVerified);
if (OPTIONS.showOnlyVerified) {
verifiedButton.classList.replace('plus-button-isOff', 'plus-button-isOn');
} else {
verifiedButton.classList.replace('plus-button-isOn', 'plus-button-isOff');
}
filterVideos();
});
hdButtonText.textContent = 'HD Only';
hdButtonText.classList.add('text');
hdButton.appendChild(hdButtonText);
hdButton.classList.add(hdButtonState, 'plus-button');
hdButton.addEventListener('click', () => {
OPTIONS.showOnlyHd = !OPTIONS.showOnlyHd;
localStorage.setItem('plus_showOnlyHd', OPTIONS.showOnlyHd);
if (OPTIONS.showOnlyHd) {
hdButton.classList.replace('plus-button-isOff', 'plus-button-isOn');
} else {
hdButton.classList.replace('plus-button-isOn', 'plus-button-isOff');
}
filterVideos();
});
playlistBarButtonText.textContent = 'Hide Playlist Bar';
playlistBarButtonText.classList.add('text');
playlistBarButton.appendChild(playlistBarButtonText);
playlistBarButton.classList.add(playlistBarButtonState, 'plus-button');
playlistBarButton.addEventListener('click', () => {
OPTIONS.hidePlaylistBar = !OPTIONS.hidePlaylistBar;
localStorage.setItem('plus_hidePlaylistBar', OPTIONS.hidePlaylistBar);
if (OPTIONS.hidePlaylistBar) {
playlistBarButton.classList.replace('plus-button-isOff', 'plus-button-isOn');
} else {
playlistBarButton.classList.replace('plus-button-isOn', 'plus-button-isOff');
}
const playlistBar = document.querySelector('.playlist-bar');
if (playlistBar) {
playlistBar.style.display = OPTIONS.hidePlaylistBar ? 'none' : 'block';
}
});
hideWatchedButtonText.textContent = 'Unwatched Only';
hideWatchedButtonText.classList.add('text');
hideWatchedButton.appendChild(hideWatchedButtonText);
hideWatchedButton.classList.add(hideWatchedButtonState, 'plus-button');
hideWatchedButton.addEventListener('click', () => {
OPTIONS.hideWatchedVideos = !OPTIONS.hideWatchedVideos;
localStorage.setItem('plus_hideWatchedVideos', OPTIONS.hideWatchedVideos);
if (OPTIONS.hideWatchedVideos) {
hideWatchedButton.classList.replace('plus-button-isOff', 'plus-button-isOn');
} else {
hideWatchedButton.classList.replace('plus-button-isOn', 'plus-button-isOff');
}
filterVideos();
});
redirectToVideosButtonText.textContent = 'Redirect Profiles to Uploads';
redirectToVideosButtonText.classList.add('text');
redirectToVideosButton.appendChild(redirectToVideosButtonText);
redirectToVideosButton.classList.add(redirectToVideosButtonState, 'plus-button');
redirectToVideosButton.addEventListener('click', () => {
OPTIONS.redirectToVideos = !OPTIONS.redirectToVideos;
localStorage.setItem('plus_redirectToVideos', OPTIONS.redirectToVideos);
if (OPTIONS.redirectToVideos) {
redirectToVideosButton.classList.replace('plus-button-isOff', 'plus-button-isOn');
} else {
redirectToVideosButton.classList.replace('plus-button-isOn', 'plus-button-isOff');
}
});
redirectPremiumVideosButtonText.textContent = 'Redirect Empty Premium Members To Regular';
redirectPremiumVideosButtonText.classList.add('text');
redirectPremiumVideosButton.appendChild(redirectPremiumVideosButtonText);
redirectPremiumVideosButton.classList.add(redirectPremiumVideosButtonState, 'plus-button');
redirectPremiumVideosButton.addEventListener('click', () => {
OPTIONS.redirectPremiumVideos = !OPTIONS.redirectPremiumVideos;
localStorage.setItem('plus_redirectPremiumVideos', OPTIONS.redirectPremiumVideos);
if (OPTIONS.redirectPremiumVideos) {
redirectPremiumVideosButton.classList.replace('plus-button-isOff', 'plus-button-isOn');
} else {
redirectPremiumVideosButton.classList.replace('plus-button-isOn', 'plus-button-isOff');
}
});
durationShortButtonText.textContent = 'Short Videos (< 8 min)';
durationShortButtonText.classList.add('text');
durationShortButton.appendChild(durationShortButtonText);
durationShortButton.classList.add(durationShortButtonState, 'plus-button');
durationShortButton.addEventListener('click', () => {
OPTIONS.durationFilter.min = OPTIONS.durationFilter.min ? 0 : 8;
localStorage.setItem('plus_durationFilter', JSON.stringify(OPTIONS.durationFilter));
if (!OPTIONS.durationFilter.min) {
durationShortButton.classList.replace('plus-button-isOff', 'plus-button-isOn');
filterVideos();
} else {
durationShortButton.classList.replace('plus-button-isOn', 'plus-button-isOff');
filterVideos();
}
});
durationMediumButtonText.textContent = 'Medium Videos (8-20 min)';
durationMediumButtonText.classList.add('text');
durationMediumButton.appendChild(durationMediumButtonText);
durationMediumButton.classList.add(durationMediumButtonState, 'plus-button');
durationMediumButton.addEventListener('click', () => {
OPTIONS.durationFilter.min = OPTIONS.durationFilter.min !== 8 ? 8 : 0;
OPTIONS.durationFilter.max = OPTIONS.durationFilter.max !== 20 ? 20 : 0;
localStorage.setItem('plus_durationFilter', JSON.stringify(OPTIONS.durationFilter));
if (OPTIONS.durationFilter.min === 8 && OPTIONS.durationFilter.max === 20) {
durationMediumButton.classList.replace('plus-button-isOff', 'plus-button-isOn');
filterVideos();
} else {
durationMediumButton.classList.replace('plus-button-isOn', 'plus-button-isOff');
filterVideos();
}
});
largerButton.textContent = "Larger previews";
largerButtonText.classList.add('text');
largerButton.appendChild(largerButtonText);
largerButton.classList.add('plus-button');
largerButton.addEventListener('click', () => {
setRelatedColumns(OPTIONS.relatedColumns - 1)
});
smallerButton.textContent = "Smaller previews";
smallerButtonText.classList.add('text');
smallerButton.appendChild(smallerButtonText);
smallerButton.classList.add('plus-button');
smallerButton.addEventListener('click', () => {
setRelatedColumns(OPTIONS.relatedColumns + 1)
});
/**
* Order option buttons in a container
*/
const buttons = document.createElement('div');
const durationFilters = [];
buttons.classList.add('plus-buttons');
buttons.appendChild(cinemaButton);
buttons.appendChild(scrollButton);
buttons.appendChild(scrollPlaylistsButton);
buttons.appendChild(smallerButton);
buttons.appendChild(largerButton);
buttons.appendChild(verifiedButton);
buttons.appendChild(hdButton);
buttons.appendChild(hideWatchedButton);
buttons.appendChild(redirectToVideosButton);
buttons.appendChild(redirectPremiumVideosButton);
buttons.appendChild(playlistBarButton);
/**
* Generate buttons for filtering by duration. Buttons are created based on
* `OPTIONS.durationPresets`, an array of objects containing max and min duration in minutes,
* and a label (like "Short Videos").
*/
OPTIONS.durationPresets.forEach(preset => {
const button = document.createElement('a');
const buttonText = document.createElement('span');
const buttonState = getButtonState(OPTIONS.durationFilter.min === preset.min &&
OPTIONS.durationFilter.max === preset.max);
buttonText.textContent = `${preset.label} (${preset.min}-${preset.max} mins)`;
buttonText.classList.add('text');
button.appendChild(buttonText);
button.classList.add(buttonState, 'plus-button');
durationFilters.push({
button,
preset
});
});
/**
* We needed access to all buttons, their state, and the duration values, to be able to switch
* all the buttons to off state before we apply the newly selected filters. For simplicity and
* sanity, only one duration range can be selected at a time.
*/
durationFilters.forEach(({
button,
preset
}) => {
buttons.appendChild(button);
button.addEventListener('click', () => {
durationFilters.forEach(filter => filter.button.classList.replace('plus-button-isOn', 'plus-button-isOff'));
OPTIONS.durationFilter.min = OPTIONS.durationFilter.min === preset.min ? 0 : preset.min;
OPTIONS.durationFilter.max = OPTIONS.durationFilter.max === preset.max ? 0 : preset.max;
localStorage.setItem('plus_durationFilter', JSON.stringify(OPTIONS.durationFilter));
if (OPTIONS.durationFilter.min === preset.min &&
OPTIONS.durationFilter.max === preset.max) {
button.classList.replace('plus-button-isOff', 'plus-button-isOn');
filterVideos();
} else {
button.classList.replace('plus-button-isOn', 'plus-button-isOff');
filterVideos();
}
});
});
document.body.appendChild(buttons); // Button container ready and added to page
/**
* Observe for DOM mutations, such as loading more videos.
*/
const observer = new MutationObserver(function(mutations) {
mutations.forEach(function(mutation) {
if (!!mutation.target.className) {
// Filter videos when loading more
if (mutation.addedNodes.length) {
filterVideos();
showTitles();
}
// Always wide player
if (!!mutation.target.id.match(/\bplayer\b/)) {
mutation.target.className = "wide";
return;
}
if (!!mutation.target.id.match(/main-container/) && !!mutation.previousSibling && !!mutation.previousSibling.id && !!mutation.previousSibling.id.match(/rightColVideoPage/)) {
mutation.previousSibling.className = "wide";
return;
}
// Update wide player button / HTML5 only
if (!!mutation.target.className.match(/mhp1138_front/)) {
mutation.target.childNodes.forEach(function(node) {
if (!!node.className.match(/mhp1138_cinema/)) {
node.className = "mhp1138_cinema mhp1138_cinemaState";
return;
}
});
return;
}
// Center the video
if (!!mutation.target.className.match(/playerFlvContainer/)) {
mutation.addedNodes.forEach(function(element) {
if (!!element && element.id === "pb_template") {
var node = document.createElement("div");
node.className = "mhp1138_playerStateIcon";
node.setAttribute("style", "opacity: 1");
node.innerHTML =
"<div class='mhp1138_play' style='display: block'>" +
" <div class='mhp1138_icon mhp1138_icon-play'></div>" +
"</div>" +
"<div class='mhp1138_background'></div>";
element.appendChild(node);
return;
}
});
}
return;
}
});
});
observer.observe(document, {
childList: true,
subtree: true
});
/**
* General UI related functions
*/
/**
* Clicking a video on a playlist page opens it without the playlist at the
* top if the option is enabled.
*/
function updatePlaylistLinks() {
if (OPTIONS.openWithoutPlaylist) {
document.querySelectorAll('#videoPlaylist li a').forEach(link => {
link.href = link.href.replace('pkey', 'nopkey');
});
} else {
document.querySelectorAll('#videoPlaylist li a').forEach(link => {
link.href = link.href.replace('nopkey', 'pkey');
});
}
}
/**
* Allow scrolling the page when mouse hovers playlists in "add to", by
* cloning the playlist scroll container to remove the listeners that
* `preventDefault()`.
*/
function fixScrollContainer(container) {
if (container) {
container.parentNode.replaceChild(container.cloneNode(true), container);
}
}
/**
* Video thumbnail box related functions
*/
/**
* Checks if video box links to a video made by a verified member
*/
function videoIsVerified(box) {
return box.querySelector('.own-video-thumbnail');
}
/**
* Checks if video box links to a HD video
*/
function videoIsHd(box) {
return box.querySelector('.hd-thumbnail');
}
/**
* Checks if the video box has a "watched" label on it (the video has
* already been viewed)
*/
function videoIsWatched(box) {
return box.querySelector('.watchedVideoText');
}
/**
* Checks if video box links to a video that is within the selected duration
* range, if one has been selected in options.
*/
function videoIsWithinDuration(box) {
// Parse integer minutes from video duration text