-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconsole_script
More file actions
79 lines (65 loc) · 3.09 KB
/
console_script
File metadata and controls
79 lines (65 loc) · 3.09 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
// === Part 1: Prevent videos from pausing when switching tabs ===
// Override the document.hidden property
Object.defineProperty(document, 'hidden', {
get: function() {
return false; // Always return false to indicate the tab is visible
}
});
// Override the document.visibilityState property
Object.defineProperty(document, 'visibilityState', {
get: function() {
return 'visible'; // Always return 'visible' to indicate the tab is visible
}
});
// Trigger a fake visibilitychange event to ensure Instagram updates its state
const event = new Event('visibilitychange');
document.dispatchEvent(event);
console.log('Instagram tab visibility detection overridden. Videos should no longer pause when switching tabs.');
// === Part 2: Add a custom seek bar to Instagram videos ===
function addSeekBarToVideos() {
// Select all video elements on the page
const videos = document.querySelectorAll('video');
videos.forEach(video => {
// Check if the video already has a seek bar
if (video.parentElement.querySelector('.custom-seek-bar')) return;
// Create a container for the seek bar
const seekBarContainer = document.createElement('div');
seekBarContainer.style.position = 'absolute';
seekBarContainer.style.bottom = '10px';
seekBarContainer.style.left = '10px';
seekBarContainer.style.right = '10px';
seekBarContainer.style.height = '5px';
seekBarContainer.style.backgroundColor = 'rgba(0, 0, 0, 0.5)';
seekBarContainer.style.borderRadius = '5px';
seekBarContainer.style.cursor = 'pointer';
seekBarContainer.classList.add('custom-seek-bar');
// Create the progress bar
const progressBar = document.createElement('div');
progressBar.style.height = '100%';
progressBar.style.backgroundColor = '#0095f6';
progressBar.style.borderRadius = '5px';
progressBar.style.width = '0%';
// Append the progress bar to the container
seekBarContainer.appendChild(progressBar);
// Append the seek bar container to the video's parent element
video.parentElement.style.position = 'relative';
video.parentElement.appendChild(seekBarContainer);
// Update the progress bar as the video plays
video.addEventListener('timeupdate', () => {
const progress = (video.currentTime / video.duration) * 100;
progressBar.style.width = `${progress}%`;
});
// Allow clicking on the seek bar to jump to a specific time
seekBarContainer.addEventListener('click', (e) => {
const rect = seekBarContainer.getBoundingClientRect();
const clickPosition = (e.clientX - rect.left) / rect.width;
video.currentTime = clickPosition * video.duration;
});
});
}
// Run the function initially
addSeekBarToVideos();
// Observe the DOM for new videos (e.g., when scrolling)
const observer = new MutationObserver(addSeekBarToVideos);
observer.observe(document.body, { childList: true, subtree: true });
console.log('Custom seek bar added to Instagram videos.');