Skip to content

Instantly share code, notes, and snippets.

@andreaganduglia
Created November 10, 2022 10:34
Show Gist options
  • Save andreaganduglia/210da738c28fc871144284ebb0923be0 to your computer and use it in GitHub Desktop.
Save andreaganduglia/210da738c28fc871144284ebb0923be0 to your computer and use it in GitHub Desktop.
A Tampermonkey script to watch Disney+ on Linux
// ==UserScript==
// @name DisneyPlus on Ubuntu
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Set custom navigator.userAgent
// @author Andrea Ganduglia - Based on https://gist.github.com/moehlone/bed7dd6cb38fc55bd640
// @match https://www.disneyplus.com/*
// @grant none
// ==/UserScript==
(function() {
'use strict';
var customUserAgent = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:97.0) Gecko/20100101 Firefox/97.0';
/**
* Creates a read/writable property which returns a function set for write/set (assignment)
* and read/get access on a variable
*
* @param {Any} value initial value of the property
*/
function createProperty(value) {
var _value = value;
/**
* Overwrite getter.
*
* @returns {Any} The Value.
* @private
*/
function _get() {
return _value;
}
/**
* Overwrite setter.
*
* @param {Any} v Sets the value.
* @private
*/
function _set(v) {
_value = v;
}
return {
"get": _get,
"set": _set
};
};
/**
* Creates or replaces a read-write-property in a given scope object, especially for non-writable properties.
* This also works for built-in host objects (non-DOM objects), e.g. navigator.
* Optional an initial value can be passed, otherwise the current value of the object-property will be set.
*
* @param {Object} objBase e.g. window
* @param {String} objScopeName e.g. "navigator"
* @param {String} propName e.g. "userAgent"
* @param {Any} initValue (optional) e.g. window.navigator.userAgent
*/
function makePropertyWritable(objBase, objScopeName, propName, initValue) {
var newProp,
initObj;
if (objBase && objScopeName in objBase && propName in objBase[objScopeName]) {
if(typeof initValue === "undefined") {
initValue = objBase[objScopeName][propName];
}
newProp = createProperty(initValue);
try {
Object.defineProperty(objBase[objScopeName], propName, newProp);
} catch (e) {
initObj = {};
initObj[propName] = newProp;
try {
objBase[objScopeName] = Object.create(objBase[objScopeName], initObj);
} catch(e) {
// Workaround, but necessary to overwrite native host objects
}
}
}
};
makePropertyWritable(window, "navigator", "userAgent");
window.navigator.userAgent = customUserAgent;
console.log(window.navigator.userAgent);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment