-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontent.js
More file actions
159 lines (137 loc) · 5.39 KB
/
content.js
File metadata and controls
159 lines (137 loc) · 5.39 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
let isEnabled = true;
let isHandlingAd = false;
let lastMainVideoTime = 0;
let adStuckTimer = null;
let bannerSessionCount = 0;
let preAdTime = null;
chrome.storage.local.get(['isEnabled'], (data) => { isEnabled = data.isEnabled !== false; });
chrome.storage.onChanged.addListener((changes) => { if (changes.isEnabled) isEnabled = changes.isEnabled.newValue; });
const createBlackoutOverlay = () => {
let overlay = document.getElementById('premium-ad-blackout');
if (!overlay) {
overlay = document.createElement('div');
overlay.id = 'premium-ad-blackout';
overlay.style.cssText = `
position: absolute; top: 0; left: 0; width: 100%; height: 100%;
background: #000; z-index: 999999; display: none; align-items: center;
justify-content: center; color: #4facfe; font-family: sans-serif;
flex-direction: column; pointer-events: none;
`;
overlay.innerHTML = `
<div style="font-size: 28px; font-weight: 900; letter-spacing: 1px; text-transform: uppercase;">Turbo Mode Active</div>
<div id="turbo-status" style="font-size: 14px; color: #aaa; margin-top: 8px;">Skipping Interruption...</div>
`;
const player = document.querySelector('.html5-video-player');
if (player) player.appendChild(overlay);
}
return overlay;
};
// --- SLAYER: Small Ads, Companion Banners, Promoted Tiles ---
const killSponsoredAds = () => {
if (!isEnabled) return;
let removedCount = 0;
// Every possible selector for small/side/banner ads
const selectors = [
'ytd-ad-slot-renderer',
'#player-ads',
'ytd-promoted-video-renderer',
'#masthead-ad',
'#panels:has(ytd-ads-engagement-panel-content-renderer)',
'.ytd-companion-slot-renderer',
'ytd-action-companion-ad-renderer',
'ytd-banner-promo-renderer'
];
selectors.forEach(s => {
document.querySelectorAll(s).forEach(el => {
el.remove();
removedCount++;
});
});
document.querySelectorAll('ytd-rich-item-renderer, ytd-compact-video-renderer').forEach(item => {
// If it has the 'Sponsored' badge inside it
if (item.querySelector('.badge-shape-wiz__text') && item.innerText.includes('Sponsored')) {
item.remove();
removedCount++;
}
});
// Save to GUI if we destroyed banners
if (removedCount > 0) {
chrome.storage.local.get(['bannersBlocked'], (data) => {
let current = parseInt(data.bannersBlocked) || 0;
chrome.storage.local.set({ bannersBlocked: current + removedCount });
});
}
};
// --- MAIN ENGINE: Video Ads + Refresh ---
const turboSkip = () => {
if (!isEnabled) return;
const video = document.querySelector('video');
const adShowing = document.querySelector('.ad-showing, .ad-interrupting');
const skipBtn = document.querySelector('.ytp-ad-skip-button, .ytp-skip-ad-button, .ytp-ad-skip-button-modern');
const overlay = createBlackoutOverlay();
// 1. TRACK MAIN VIDEO TIME
if (video && !adShowing) {
if (!isNaN(video.currentTime) && video.currentTime > 0) {
lastMainVideoTime = video.currentTime;
}
adStuckTimer = null; // Reset refresh timer
}
// 2. IF AD IS PLAYING
if (adShowing && video) {
if (overlay) overlay.style.display = 'flex';
if (!adStuckTimer) adStuckTimer = Date.now();
// Capture the pre-ad time only once (so we can resume correctly)
if (preAdTime === null) {
preAdTime = Math.floor(lastMainVideoTime) || Math.floor(video.currentTime) || 0;
}
// -- 5-SECOND REFRESH & RESUME GUARANTEE --
if (Date.now() - adStuckTimer > 5000) {
const turboStatusEl = document.getElementById('turbo-status');
if (turboStatusEl) turboStatusEl.innerText = "Ad bypassed. Resuming video...";
const url = new URL(window.location.href);
// Use numeric seconds without the trailing 's' to be more compatible
url.searchParams.set('t', String(preAdTime || 0));
// Use replace() so we don't mess up the back button history
window.location.replace(url.toString());
return;
}
// -- TELEPORT LOGIC --
video.muted = true;
video.playbackRate = 16.0;
let duration = parseInt(video.duration);
if (!isNaN(duration) && duration > 0) {
// Jump near the end so the player considers the ad finished
try { video.currentTime = Math.max(0, duration - 0.1); } catch (e) { /* some players block setting time */ }
}
if (skipBtn) skipBtn.click();
// -- STRICT NUMBER MATH FOR GUI STATS --
if (!isHandlingAd) {
isHandlingAd = true;
let adDurationToSave = (!isNaN(duration) && duration > 0 && duration < 3600) ? duration : 15;
chrome.storage.local.get(['adsSkipped', 'timeSaved'], (data) => {
let currentAds = parseInt(data.adsSkipped) || 0;
let currentTime = parseInt(data.timeSaved) || 0;
chrome.storage.local.set({
adsSkipped: currentAds + 1,
timeSaved: currentTime + adDurationToSave
});
});
}
} else {
// 3. CLEANUP AFTER AD
if (isHandlingAd) {
isHandlingAd = false;
if (video) video.playbackRate = 1.0;
if (overlay) overlay.style.display = 'none';
const statusText = document.getElementById('turbo-status');
if (statusText) statusText.innerText = "Skipping Interruption...";
// restore audio
try { if (video) video.muted = false; } catch (e) {}
// reset captured pre-ad time
preAdTime = null;
}
}
};
// Loop timers
setInterval(turboSkip, 250);
setInterval(killSponsoredAds, 1000);