Created
April 5, 2025 23:34
-
-
Save ParkWardRR/8b52be7084fc0a55a5c8a9db97789070 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Plex Redirect Script | |
// @namespace https://example.com/ | |
// @version 1.0 | |
// @description Automatically redirects users from the Plex homepage (www.plex.tv) to the Plex web app (app.plex.tv). | |
// @author Your Name | |
// @match https://www.plex.tv/* | |
// @grant none | |
// ==/UserScript== | |
/* | |
* This script is designed to automatically redirect users from the Plex homepage | |
* (https://www.plex.tv/) to the Plex web app (https://app.plex.tv/desktop/#!/). | |
* It works with any userscript manager, such as Violentmonkey, Tampermonkey, or Greasemonkey. | |
*/ | |
(function() { | |
'use strict'; // Enforces strict mode for better error handling and cleaner code. | |
/* | |
* Define the target URL that you want users to be redirected to. | |
* In this case, it's the Plex web app. | |
*/ | |
const targetURL = "https://app.plex.tv/desktop/#!/"; | |
/* | |
* window.location.replace() is used to redirect the browser to a new URL. | |
* This method ensures that the current page is replaced in the browser's history, | |
* so users cannot hit "Back" to return to the original page. | |
* | |
* If you want users to retain their ability to go back, use window.location.href instead. | |
*/ | |
try { | |
// Attempting the redirection | |
console.log(`[INFO] Redirecting from ${window.location.href} to ${targetURL}`); | |
window.location.replace(targetURL); | |
} catch (error) { | |
// Catch any errors that occur during redirection and log them for debugging purposes. | |
console.error(`[ERROR] Failed to redirect: ${error.message}`); | |
} | |
/* | |
* Additional Notes: | |
* - The @match directive above ensures this script only runs on URLs matching https://www.plex.tv/*. | |
* If you want broader matching, you can use wildcards or regular expressions. | |
* - The 'use strict' directive helps catch common coding errors and prevents unsafe actions. | |
*/ | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment