Greasy Fork is available in English.
Seamlessly bypass YouTube's age restriction and skip ads. Self-updates for future compatibility! 🚀
当前为
// ==UserScript==
// @name Ultimate YouTube Age Restriction Bypass with Ad Skipper
// @description Seamlessly bypass YouTube's age restriction and skip ads. Self-updates for future compatibility! 🚀
// @version 6.0.0
// @namespace https://github.com/zerodytrash/Simple-YouTube-Age-Restriction-Bypass/
// @license MIT
// @match https://www.youtube.com/*
// @match https://www.youtube-nocookie.com/*
// @grant GM_xmlhttpRequest
// @grant GM_setValue
// @grant GM_getValue
// @grant GM_notification
// @grant GM_addStyle
// @run-at document-start
// @compatible chrome
// @compatible firefox
// @compatible edge
// ==/UserScript==
(function () {
'use strict';
/**
* Configuration for the script
*/
const CONFIG = {
ENABLE_NOTIFICATIONS: true, // Show notifications for script events
ENABLE_AUTO_AD_SKIP: true, // Automatically skip ads
DEFAULT_VIDEO_QUALITY: '1080p', // Default playback quality
CHECK_FOR_UPDATES_INTERVAL: 86400000, // Check for updates every 24 hours (in milliseconds)
SCRIPT_UPDATE_URL: 'https://raw.githubusercontent.com/zerodytrash/Simple-YouTube-Age-Restriction-Bypass/main/bypass.user.js',
PLAYABILITY_STATUSES_TO_UNLOCK: ['AGE_VERIFICATION_REQUIRED', 'CONTENT_WARNING']
};
const logger = {
log: (...messages) => console.log('[YouTube Bypass]', ...messages),
error: (...messages) => console.error('[YouTube Bypass]', ...messages),
warn: (...messages) => console.warn('[YouTube Bypass]', ...messages)
};
/**
* Show notifications if enabled
*/
function showNotification(message, duration = 5000) {
if (!CONFIG.ENABLE_NOTIFICATIONS) return;
GM_notification({
text: message,
title: 'YouTube Bypass',
timeout: duration / 1000
});
}
/**
* Automatically skip YouTube ads
*/
function autoSkipAds() {
if (!CONFIG.ENABLE_AUTO_AD_SKIP) return;
const observer = new MutationObserver(() => {
// Detect skip button or ad overlays
const skipButton = document.querySelector('.ytp-ad-skip-button') ||
document.querySelector('.ytp-ad-overlay-close-button');
if (skipButton) {
skipButton.click();
logger.log('Ad skipped.');
showNotification('Ad skipped!');
}
});
// Observe DOM changes on the player
observer.observe(document.body, { childList: true, subtree: true });
}
/**
* Modify YouTube API responses to unlock videos
*/
function interceptPlayerRequests() {
const originalOpen = XMLHttpRequest.prototype.open;
XMLHttpRequest.prototype.open = function (method, url, ...args) {
if (url.includes('/youtubei/v1/player')) {
this.addEventListener('readystatechange', function () {
if (this.readyState === 4 && this.status === 200) {
try {
const response = JSON.parse(this.responseText);
if (CONFIG.PLAYABILITY_STATUSES_TO_UNLOCK.includes(response?.playabilityStatus?.status)) {
logger.log('Unlocking restricted video...');
showNotification('Unlocking restricted video...');
response.playabilityStatus.status = 'OK'; // Unlock
this.responseText = JSON.stringify(response);
}
} catch (err) {
logger.error('Failed to process API response:', err);
}
}
});
}
originalOpen.call(this, method, url, ...args);
};
}
/**
* Self-updating mechanism to fetch and apply latest script
*/
function checkForUpdates() {
const lastUpdateCheck = GM_getValue('lastUpdateCheck', 0);
const now = Date.now();
if (now - lastUpdateCheck < CONFIG.CHECK_FOR_UPDATES_INTERVAL) {
return; // Skip if update was recently checked
}
GM_setValue('lastUpdateCheck', now);
GM_xmlhttpRequest({
method: 'GET',
url: CONFIG.SCRIPT_UPDATE_URL,
onload(response) {
if (response.status === 200 && response.responseText.includes('// ==UserScript==')) {
const latestScript = response.responseText;
const currentVersion = GM_info.script.version;
const latestVersion = latestScript.match(/@version\s+([\d.]+)/)[1];
if (latestVersion !== currentVersion) {
logger.log(`Updating to version ${latestVersion}`);
GM_setValue('latestScript', latestScript);
// Apply the update
GM_notification({
text: 'A new version is available. Please reload the page to apply the update.',
title: 'YouTube Bypass Update',
onclick: () => location.reload()
});
} else {
logger.log('Script is up to date.');
}
} else {
logger.error('Failed to fetch latest script version.');
}
},
onerror() {
logger.error('Error while checking for updates.');
}
});
}
/**
* Apply the latest script if available
*/
function applyLatestScript() {
const latestScript = GM_getValue('latestScript', null);
if (latestScript) {
const scriptBlob = new Blob([latestScript], { type: 'application/javascript' });
const scriptURL = URL.createObjectURL(scriptBlob);
const scriptTag = document.createElement('script');
scriptTag.src = scriptURL;
document.head.appendChild(scriptTag);
logger.log('Applied latest script version.');
}
}
/**
* Initialize the script
*/
function initialize() {
logger.log('Initializing YouTube Bypass script...');
applyLatestScript();
interceptPlayerRequests();
autoSkipAds();
checkForUpdates();
logger.log('Initialization complete.');
}
initialize();
})();