-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbblf-enhancer.js
More file actions
330 lines (307 loc) · 13.6 KB
/
bblf-enhancer.js
File metadata and controls
330 lines (307 loc) · 13.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
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
// ==UserScript==
// @name BBLF Enhancer
// @namespace http://tampermonkey.net/
// @version 1.34
// @description Monitor for issues on the live feed page, reloading or starting video when necessary. Can autoload quad cam, add hotkeys, show video scrubber, and remap fullscreen button to only show video.
// @author liquid8d
// @match https://www.paramountplus.com/shows/big_brother/live_feed/stream/
// @icon https://www.google.com/s2/favicons?sz=64&domain=paramountplus.com
// @grant GM_log
// ==/UserScript==
/*
v 1.34 (2025)
- fix audio pan to split channels properly
- hookwebaudio only to primary video in case it interferes with thumbs (thumbs have no audio anyways)
v 1.33 (2025)
- added left/right audio balance hotkeys
v 1.32 (2025)
- thumbs fix - hotkey cam switch shouldn't get stuck on thumbs
- player quality is now checked (i.e quality fix will apply when clicking thumbs)
v 1.31 (2025)
- add qualityFix option for those who were quality limited
v 1.3
- now need to click start button to use (this forces user interaction with the page to ensure js executes)
- add removeControls (hides P+ video controls and enables scrubber on video)
v 1.2
- add extendedWatch
*/
(function() {
'use strict';
const hotkeys = [
{ key: 1, action: function() { switchCam(1) } },
{ key: 2, action: function() { switchCam(2) } },
{ key: 3, action: function() { switchCam(3) } },
{ key: 4, action: function() { switchCam(4) } },
{ key: 5, action: function() { switchCam(5) } },
{ key: 'q', action: function() { adjustChannel('left') } },
{ key: 'w', action: function() { adjustChannel('none') } },
{ key: 'e', action: function() { adjustChannel('right') } }
]
// force allow up to 1080p resolution
const qualityFix = true
const preferredQuality = '1080p' // one of 1080p, 720p, 540p, 360p, 288p, 216p
// force switch to quad cam on page load
const autoQuadCam = true
// remove P+ video controls and show built-in video controls allowing scrubbing
const removeControls = true
// hide chat and video thumbs on fullscreen
const fullscreenVideoOnly = true
// reload the page when an error is encountered
const reloadOnError = true
// keep watching if still watching is shown
const extendedWatch = true
// enable hotkeys
const enableHotkeys = true
// autostart video when page is loaded
const forcePlay = true
// delay before reloading the page on an error (secs * ms)
const reloadDelay = 1 * 1000
// frequency to check player status (secs * ms)
const monitorInterval = 3 * 1000
// max attempts to retry on failures before giving up
const retryMaxAttempts = 10
// reset the 'retry' attempts in the script, if it is no longer working
const resetScript = false
// DO NOT MODIFY AFTER HERE
// current camera (only modified to verify quad cam switch)
var camNum = 1
// current attempts, will fail after retryMaxAttemps reached
var attempts = 0
// whether the fullscreen button has been remapped
var fsButtonMapped = false
// whether the P+ player controls have been removed
var controlsRemoved = false
// whether quality fix has been added
var qualityFixed = false
// audio control variables
const audioCtx = new (window.AudioContext)();
let domNodes = [];
let audioNodes = [];
let dir = 'none';
if (localStorage.getItem('bblf_video_monitor_attempts')) attempts = (resetScript) ? 0 : parseInt(localStorage.getItem('bblf_video_monitor_attempts'))
// NOTE: you might try just running startup instead of injectStartButton, there is a freezeup for me
// startup()
injectStartButton()
function injectStartButton() {
var startEl = document.createElement('input')
startEl.id = 'bblf-enhance'
startEl.type = 'button'
startEl.value = 'Start BBLF Enhancer'
startEl.style = 'position: relative; left: calc(50% - 80px); width: 160px; height: 48px; z-index: 99999; cursor: pointer;'
startEl.addEventListener('click', startup)
var mcplayerEl = document.getElementById('mcplayer')
mcplayerEl.parentNode.insertBefore(startEl, mcplayerEl.nextSibling)
mcplayerEl.appendChild(startEl)
log('waiting for user to click start button')
}
function startup() {
log('starting bblf enhancer')
// remove start button
const startEl = document.getElementById('bblf-enhance')
if (startEl) startEl.parentNode.removeChild(startEl)
// enable hotkeys
if (enableHotkeys) {
document.onkeydown = function(e) {
for (var i = 0; i < hotkeys.length; i++) {
const hotkey = hotkeys[i].key.toString()
if (e.key === hotkey || e.code === hotkey) hotkeys[i].action()
}
}
}
// start watching video
setInterval(() => {
checkVideo();
}, monitorInterval);
}
function updateQualities() {
const video = document.querySelectorAll('video')[1]
const player = video.player
const playback = video.player.getAdapter('playback')
if (player && playback && player.qualityCategory != preferredQuality || !qualityFixed) {
playback.maxHeight = 1080
playback.maxBitrate = 5000000
playback.refreshQualities()
player.qualityCategory = preferredQuality
qualityFixed = true
}
audioCtx.resume();
}
function checkVideo() {
if (fullscreenVideoOnly && !fsButtonMapped) {
log('remapping fullscreen button')
// remaps the fullscreen button to only fullscreen video skin
const el = document.querySelector('button.btn-fullscreen')
if (el) {
el.onclick = function() {
if (document.fullscreenElement) {
document.exitFullscreen()
} else {
const player = document.querySelector('.aa-player-skin')
player.requestFullscreen()
}
}
fsButtonMapped = true
} else {
warn('can not remap fullscreen button, missing element')
}
}
if (extendedWatch) {
const countdownButton = document.querySelector('.stream-countdown-button')
if (countdownButton) {
log('found stream-countdown-button, clicking')
countdownButton.click()
}
// watch for still watching element and restart
const stillWatchingEl = document.querySelector('.timeout-panel-button-container')
if (stillWatchingEl) {
log('found timeout button, clicking')
stillWatchingEl.click()
}
}
if (attempts >= retryMaxAttempts) {
warn('gave up, max attempts reached. Increase "maxAttempts" or set "resetScript" to true, then manually reload the page.')
return
}
// check for smart tag error
var errorEl = document.querySelector('.smart-tag-error-panel-content')
if (errorEl) {
warn('smart tag error found')
if (reloadOnError) {
// reload the page
attempts += 1
localStorage.setItem('bblf_video_monitor_attempts', attempts)
setTimeout(function() { window.location.reload() }, reloadDelay)
}
} else {
var startPanelEl = document.querySelector('.start-panel.show')
if (startPanelEl) {
warn('start panel is showing, click to start video.')
var clickEl = document.querySelector('.start-panel-click-overlay')
clickEl.click()
} else {
var videoEl = document.querySelector('.aa-player-skin .player-wrapper video')
if (videoEl) {
addNode(videoEl)
if (videoEl.paused) {
if (forcePlay) {
// attempt to unpause video
info('video is available and paused, trying to force play (manual user intervention may be required)')
const el = document.getElementById('mcplayer')
el.click()
attempts += 1
localStorage.setItem('bblf_video_monitor_attempts', attempts)
} else {
// video is ok, but user doesn't want to forcePlay it
info('video is available and paused, "forcePlay" is not enabled')
}
} else {
if (autoQuadCam && camNum == 1) {
log('switching to quad cam')
switchCam(5)
camNum = 5
} else {
log('video is ready and playing.')
if (qualityFix) updateQualities()
if (removeControls && !controlsRemoved) {
log('removing P+ controls')
controlsRemoved = true
// remove the player elements
const playerEls = ['.controls-backplane', '.controls-manager', '.top-menu-backplane']
for (var i = 0; i < playerEls.length; i++) {
var el = document.querySelector(playerEls[i])
el.parentNode.removeChild(el)
}
// enable built-in video controls allowing scrubbing
}
if (controlsRemoved) videoEl.controls = true
}
}
attempts = 0
localStorage.setItem('bblf_video_monitor_attempts', 0)
} else {
// missing video element, something else is wrong here
warn('unable to find an error or the video element, you might need to manually reload the page')
}
}
}
}
function switchCam(num) {
if (document.activeElement) document.activeElement.blur()
const el = document.querySelector('.multi-cam-plugin-thumb-player-container .index-item[data-camid="' + num + '"]')
if (el) {
el.click()
qualityFixed = false
} else {
warn('could not find camera element ' + num + ', unable to change')
}
}
function addNode(node) {
if (!domNodes.includes(node)) {
domNodes.push(node);
log('DOM node added to list');
hookUpWebAudio(node);
adjustChannel('none');
log('hooked up web audio node');
}
}
function hookUpWebAudio(node) {
let audioNode = {};
audioNode.source = audioCtx.createMediaElementSource(node);
audioNode.merger = audioCtx.createChannelMerger(2);
audioNode.splitter = audioCtx.createChannelSplitter(2);
audioNode.source.connect(audioNode.splitter, 0, 0);
audioNode.gainLeft = audioCtx.createGain();
audioNode.gainRight = audioCtx.createGain();
audioNode.source.connect(audioNode.splitter, 0, 0);
audioNode.merger.connect(audioCtx.destination, 0, 0);
audioNode.gainLeft.gain.value = 1;
audioNode.gainRight.gain.value = 1;
//audioNode.splitter.connect(audioNode.gainLeft, 0);
//audioNode.splitter.connect(audioNode.gainRight, 1);
//audioNode.gainLeft.connect(audioCtx.destination, 0);
//audioNode.gainRight.connect(audioCtx.destination, 0);
audioNodes.push(audioNode);
}
function adjustChannel(dir) {
audioNodes.forEach((audioNode) => {
if (dir === 'none') {
audioNode.gainLeft.disconnect();
audioNode.gainRight.disconnect();
audioNode.splitter.disconnect();
audioNode.gainLeft.connect(audioNode.merger, 0, 0);
audioNode.gainRight.connect(audioNode.merger, 0, 1);
audioNode.splitter.connect(audioNode.gainLeft, 0);
audioNode.splitter.connect(audioNode.gainRight, 1);
audioNode.gainLeft.gain.value = 1;
audioNode.gainRight.gain.value = 1;
log('audio balance reset');
} else if (dir === 'left') {
audioNode.gainLeft.disconnect();
audioNode.gainRight.disconnect();
audioNode.splitter.disconnect();
audioNode.gainLeft.connect(audioNode.merger, 0, 0);
audioNode.gainRight.connect(audioNode.merger, 0, 1);
audioNode.splitter.connect(audioNode.gainLeft, 0);
audioNode.splitter.connect(audioNode.gainRight, 0);
audioNode.gainLeft.gain.value = 1;
audioNode.gainRight.gain.value = 1;
log('audio balance left');
} else {
audioNode.gainLeft.disconnect();
audioNode.gainRight.disconnect();
audioNode.splitter.disconnect();
audioNode.gainLeft.connect(audioNode.merger, 0, 0);
audioNode.gainRight.connect(audioNode.merger, 0, 1);
audioNode.splitter.connect(audioNode.gainLeft, 1);
audioNode.splitter.connect(audioNode.gainRight, 1);
audioNode.gainLeft.gain.value = 1;
audioNode.gainRight.gain.value = 1;
log('audio balance right');
}
});
}
function log(msg) { console.log('BBLF Enhancer: (' + attempts + ') ' + msg) }
function warn(msg) { console.warn('BBLF Enhancer: (' + attempts + ') ' + msg) }
function error(msg) { console.error('BBLF Enhancer: (' + attempts + ') ' + msg) }
function info(msg) { console.info('BBLF Enhancer: (' + attempts + ') ' + msg) }
})();