From 5dc61fa742f1f355bbecc85cd987f3b69bc056c8 Mon Sep 17 00:00:00 2001 From: TheBrokenRail Date: Sun, 20 Mar 2022 00:39:47 -0400 Subject: [PATCH] Some Polish --- manifest.json | 6 ++-- src/content.js | 3 ++ src/page.js | 82 +++++++++++++++++++++++++++++++++++++++++--------- 3 files changed, 75 insertions(+), 16 deletions(-) diff --git a/manifest.json b/manifest.json index 1c9a5de..42f6c20 100644 --- a/manifest.json +++ b/manifest.json @@ -1,8 +1,10 @@ { - "description": "This browser extension forces DisneyNOW to use their higher-resolution video stream by imitating the Android app. (It also blocks DisneyNOW ads.)", "manifest_version": 2, "name": "Force High-Resolution DisneyNOW", - "version": "1.0", + "author": "TheBrokenRail", + "version": "1.1", + "description": "This browser extension forces DisneyNOW to use their higher-resolution video stream by imitating the Android app. (It also blocks DisneyNOW ads.)", + "homepage_url": "https://gitea.thebrokenrail.com/TheBrokenRail/force-high-resolution-disneynow", "content_scripts": [ { "matches": ["*://disneynow.com/*"], diff --git a/src/content.js b/src/content.js index 76ea564..5ade343 100644 --- a/src/content.js +++ b/src/content.js @@ -1,3 +1,6 @@ +'use strict'; + +// Load Extension const script = document.createElement('SCRIPT'); script.src = chrome.runtime.getURL('src/page.js'); script.type = 'text/javascript'; diff --git a/src/page.js b/src/page.js index 729d558..4e5125f 100644 --- a/src/page.js +++ b/src/page.js @@ -1,15 +1,22 @@ '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) +const DEVICE_ID = '031_04'; // Found in the APK as the resource @string/device_id. (Default: "001") +const BRAND_ID = '011'; // Selected from the function mapBrandCode(), which is found in embed.min.js (a script loaded by the website). (Default: "004") + +// Lock the reported app name and version to a known working value. (The reported app name and version can determine the video stream format.) +const APP_NAME = 'webplayer-dc'; +const APP_VERSION = '1.2.7.49'; + +// Target File +const TARGET_FILE = 'playmanifest_secure.json'; // 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'); + this._isTargetUrl = (new URL(url)).pathname.endsWith('/' + TARGET_FILE); // Call Original Method oldOpen.call(this, method, url, ...args); @@ -19,34 +26,81 @@ Object.defineProperty(XMLHttpRequest.prototype, 'open', { writable: false }); +// Patch XMLHttpRequest.setRequestHeader +const oldSetRequestHeader = XMLHttpRequest.prototype.setRequestHeader; +Object.defineProperty(XMLHttpRequest.prototype, 'setRequestHeader', { + value: function (name, value) { + // Lock App Version + if (this._isTargetUrl && name.toLowerCase() === 'appversion') { + value = APP_VERSION; + } + + // Call Original Method + oldSetRequestHeader.call(this, name, value); + }, + enumerable: false, + configurable: false, + writable: false +}); + +// Add resolution info to video player. +function addResolutionInfo(player) { + // Create (or find existing)

element. + const id = '__disneynow_resolution_info__'; + let p = document.getElementById(id); + if (!p) { + // Create + const p = document.createElement('P'); + p.id = id; + + // Add

element to DOM. + player.parentElement.insertBefore(p, player); + } + + // Set initial resolution text. + function setResolutionText(resolution) { + p.innerText = `Video Quality: ${resolution}`; + } + setResolutionText('N/A'); + + // Hook into