Last active
May 1, 2023 17:11
-
-
Save Burry/7f6c2caa9cf645ca511ffefd697b3126 to your computer and use it in GitHub Desktop.
Intercepts all links to Plex in Organizr and redirects to the Plex app on an iOS device
This file contains 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
// Intercepts all links to Plex in Organizr and redirects to the Plex app on an | |
// iOS device. Plex for Android apparently does not support such URL schemes, and I | |
// can't find any alternative Android solution, so this script is iOS-only. | |
// Add to Organizr Settings > Customize > Appearance > Custom JavaScript. | |
//////////////////////////////////////////////////////////////////////////////////// | |
// Credit to https://forums.plex.tv/t/deep-links/205583 for finding Plex deep links | |
// Use Bowser to check if we're on iOS | |
var plexiOSCheck = bowser.osname === 'iOS'; | |
// Override function tabActions() to intercept clicks on an Organizr tab named | |
// "Plex" and call the "plex://" URL scheme to open the Plex iOS app | |
function tabActions(event, name, type) { | |
$('.splash-screen').removeClass('in').addClass('hidden'); | |
if (event.ctrlKey) | |
popTab(cleanClass(name), type); | |
else if (event.altKey) | |
console.log('alt key'); | |
else if (event.shiftKey) | |
reloadTab(cleanClass(name), type); | |
else if (plexiOSCheck && name === 'Plex') | |
window.location = 'plex://'; | |
else | |
switchTab(cleanClass(name), type); | |
} | |
// Overrides the existing jQuery event listener for .openTab, gets the associated | |
// URL, uses regex to test & parse the URL into Plex's iOS URL scheme format if it | |
// contains the string "plex", and if it does then the function opens the new URL | |
plexiOSCheck && $(document).off('click', '.openTab').on('click', '.openTab', function() { | |
var url = $(this).attr('data-url'), | |
regex = /.*plex.*server\/(.+)\/.*\?key=([^&]+)/, | |
metadata = regex.exec(url); | |
if (metadata) window.location = 'plex://preplay/?metadataKey=' + metadata[2] | |
+ '&metadataType=1&server=' + metadata[1]; | |
$.magnificPopup.close(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment