force-high-resolution-disne.../src/page.js

59 lines
1.8 KiB
JavaScript

'use strict';
// Constants
const DEVICE_ID = '031_04'; // Found in the APK as @string/device_id
const BRAND_ID = '011'; // Selected from the function mapBrandCode(), which is found in embed.min.js (a script loaded by the website)
// Patch XMLHttpRequest.open
const oldOpen = XMLHttpRequest.prototype.open;
Object.defineProperty(XMLHttpRequest.prototype, 'open', {
value: function (method, url, ...args) {
// Flag
this._isTargetUrl = (new URL(url)).pathname.endsWith('/playmanifest_secure.json');
// Call Original Method
oldOpen.call(this, method, url, ...args);
},
enumerable: false,
configurable: false,
writable: false
});
// Patch XMLHttpRequest.send
const oldSend = XMLHttpRequest.prototype.send;
Object.defineProperty(XMLHttpRequest.prototype, 'send', {
value: function (body, ...args) {
// Check
if (body && this._isTargetUrl) {
// Parse Request Body
const params = new URLSearchParams(body);
// Pretend to be an Android device
if (params.has('device')) {
params.set('device', DEVICE_ID);
}
// Switch brand to one without ads
if (params.has('brand')) {
params.set('brand', BRAND_ID);
}
// Apply Patch
body = params.toString();
// Verify
this.addEventListener("load", function () {
const obj = JSON.parse(this.responseText);
const assetUrl = new URL(obj.video.assets.asset[0].value);
console.log('Video Stream URL: ' + assetUrl);
});
}
// Call Original Method
oldSend.call(this, body, ...args);
},
enumerable: false,
configurable: false,
writable: false
});