Skip to content

Commit

Permalink
Release v2.5.10
Browse files Browse the repository at this point in the history
  • Loading branch information
drunkwinter authored and github-actions[bot] committed Aug 4, 2024
1 parent d2cbcc0 commit 5f72ebf
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 49 deletions.
97 changes: 51 additions & 46 deletions dist/Simple-YouTube-Age-Restriction-Bypass.user.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// @description:fr Regardez des vidéos YouTube avec des restrictions d'âge sans vous inscrire et sans confirmer votre âge 😎
// @description:it Guarda i video con restrizioni di età su YouTube senza login e senza verifica dell'età 😎
// @icon https://github.com/zerodytrash/Simple-YouTube-Age-Restriction-Bypass/raw/v2.5.4/src/extension/icon/icon_64.png
// @version 2.5.9
// @version 2.5.10
// @author Zerody (https://github.com/zerodytrash)
// @namespace https://github.com/zerodytrash/Simple-YouTube-Age-Restriction-Bypass/
// @supportURL https://github.com/zerodytrash/Simple-YouTube-Age-Restriction-Bypass/issues
Expand Down Expand Up @@ -119,6 +119,18 @@
}
}

// WORKAROUND: TypeError: Failed to set the 'innerHTML' property on 'Element': This document requires 'TrustedHTML' assignment.
if (window.trustedTypes && trustedTypes.createPolicy) {
if (!trustedTypes.defaultPolicy) {
const passThroughFn = (x) => x;
trustedTypes.createPolicy('default', {
createHTML: passThroughFn,
createScriptURL: passThroughFn,
createScript: passThroughFn,
});
}
}

function createElement(tagName, options) {
const node = document.createElement(tagName);
options && Object.assign(node, options);
Expand Down Expand Up @@ -169,8 +181,7 @@
function getSignatureTimestamp() {
return (
getYtcfgValue('STS')
|| (() => {
var _document$querySelect;
|| ((_document$querySelect) => {
// STS is missing on embedded player. Retrieve from player base script as fallback...
const playerBaseJsPath = (_document$querySelect = document.querySelector('script[src*="/base.js"]')) === null || _document$querySelect === void 0
? void 0
Expand Down Expand Up @@ -236,7 +247,7 @@
}
}, 100);

if (timeout) {
{
setTimeout(() => {
clearInterval(checkDomInterval);
deferred.reject();
Expand All @@ -246,22 +257,6 @@
return deferred;
}

function parseRelativeUrl(url) {
if (typeof url !== 'string') {
return null;
}

if (url.indexOf('/') === 0) {
url = window.location.origin + url;
}

try {
return url.indexOf('https://') === 0 ? new window.URL(url) : null;
} catch {
return null;
}
}

function isWatchNextObject(parsedData) {
var _parsedData$currentVi;
if (
Expand Down Expand Up @@ -490,40 +485,52 @@

window.Request = new Proxy(window.Request, {
construct(target, args) {
const [url, options] = args;
let [url, options] = args;
try {
const parsedUrl = parseRelativeUrl(url);
const modifiedUrl = onRequestCreate(parsedUrl, options);

if (modifiedUrl) {
args[0] = modifiedUrl.toString();
if (typeof url === 'string') {
if (url.indexOf('/') === 0) {
url = window.location.origin + url;
}

if (url.indexOf('https://') !== -1) {
const modifiedUrl = onRequestCreate(url, options);

if (modifiedUrl) {
args[0] = modifiedUrl;
}
}
}
} catch (err) {
error(err, `Failed to intercept Request()`);
}

return Reflect.construct(...arguments);
return Reflect.construct(target, args);
},
});
}

function attach(onXhrOpenCalled) {
XMLHttpRequest.prototype.open = function(method, url) {
XMLHttpRequest.prototype.open = function(...args) {
let [method, url] = args;
try {
let parsedUrl = parseRelativeUrl(url);
if (typeof url === 'string') {
if (url.indexOf('/') === 0) {
url = window.location.origin + url;
}

if (parsedUrl) {
const modifiedUrl = onXhrOpenCalled(method, parsedUrl, this);
if (url.indexOf('https://') !== -1) {
const modifiedUrl = onXhrOpenCalled(method, url, this);

if (modifiedUrl) {
arguments[1] = modifiedUrl.toString();
if (modifiedUrl) {
args[1] = modifiedUrl;
}
}
}
} catch (err) {
error(err, `Failed to intercept XMLHttpRequest.open()`);
}

nativeXMLHttpRequestOpen.apply(this, arguments);
nativeXMLHttpRequestOpen.apply(this, args);
};
}

Expand Down Expand Up @@ -811,10 +818,6 @@
const buttonElement = createElement('div', { class: 'button-container', innerHTML: buttonTemplate });
buttonElement.getElementsByClassName('button-text')[0].innerText = text;

if (backgroundColor) {
buttonElement.querySelector(':scope > div').style['background-color'] = backgroundColor;
}

if (typeof onClick === 'function') {
buttonElement.addEventListener('click', onClick);
}
Expand Down Expand Up @@ -1185,17 +1188,18 @@
* - Add "content check ok" flags to request bodys
*/
function handleXhrOpen(method, url, xhr) {
let proxyUrl = unlockGoogleVideo(url);
const url_obj = new URL(url);
let proxyUrl = unlockGoogleVideo(url_obj);
if (proxyUrl) {
// Exclude credentials from XMLHttpRequest
Object.defineProperty(xhr, 'withCredentials', {
set: () => {},
get: () => false,
});
return proxyUrl;
return proxyUrl.toString();
}

if (url.pathname.indexOf('/youtubei/') === 0) {
if (url_obj.pathname.indexOf('/youtubei/') === 0) {
// Store auth headers in storage for further usage.
attach$4(xhr, 'setRequestHeader', ([headerName, headerValue]) => {
if (Config.GOOGLE_AUTH_HEADER_NAMES.includes(headerName)) {
Expand All @@ -1204,7 +1208,7 @@
});
}

if (Config.SKIP_CONTENT_WARNINGS && method === 'POST' && ['/youtubei/v1/player', '/youtubei/v1/next'].includes(url.pathname)) {
if (Config.SKIP_CONTENT_WARNINGS && method === 'POST' && ['/youtubei/v1/player', '/youtubei/v1/next'].includes(url_obj.pathname)) {
// Add content check flags to player and next request (this will skip content warnings)
attach$4(xhr, 'send', (args) => {
if (typeof args[0] === 'string') {
Expand All @@ -1221,16 +1225,17 @@
* - Add "content check ok" flags to request bodys
*/
function handleFetchRequest(url, requestOptions) {
let newGoogleVideoUrl = unlockGoogleVideo(url);
const url_obj = new URL(url);
const newGoogleVideoUrl = unlockGoogleVideo(url_obj);
if (newGoogleVideoUrl) {
// Exclude credentials from Fetch Request
if (requestOptions.credentials) {
requestOptions.credentials = 'omit';
}
return newGoogleVideoUrl;
return newGoogleVideoUrl.toString();
}

if (url.pathname.indexOf('/youtubei/') === 0 && isObject(requestOptions.headers)) {
if (url_obj.pathname.indexOf('/youtubei/') === 0 && isObject(requestOptions.headers)) {
// Store auth headers in authStorage for further usage.
for (let headerName in requestOptions.headers) {
if (Config.GOOGLE_AUTH_HEADER_NAMES.includes(headerName)) {
Expand All @@ -1239,7 +1244,7 @@
}
}

if (Config.SKIP_CONTENT_WARNINGS && ['/youtubei/v1/player', '/youtubei/v1/next'].includes(url.pathname)) {
if (Config.SKIP_CONTENT_WARNINGS && ['/youtubei/v1/player', '/youtubei/v1/next'].includes(url_obj.pathname)) {
// Add content check flags to player and next request (this will skip content warnings)
requestOptions.body = setContentCheckOk(requestOptions.body);
}
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"type": "module",
"name": "simple-youtube-age-restriction-bypass",
"description": "A simple userscript to bypass YouTube's age verification and watch age restricted videos without having to sign in.",
"version": "2.5.9",
"version": "2.5.10",
"repository": {
"type": "git",
"url": "git+https://github.com/zerodytrash/Simple-YouTube-Age-Restriction-Bypass.git"
Expand Down

0 comments on commit 5f72ebf

Please sign in to comment.