MrLufus
MrLufus

Reputation: 71

How To - Open Instagram YouTube Links in App instead of Instagram Browser (Using YOURLS URL Shortener)

I've successfully setup a URL Shortener Service Using "YOURLS". And now wanna use it to not only shorten Links, moreover I want so solve the Instagram Issue, where the App is Opening External YouTube Links in the Instagram Browser instead of the YouTube App.

The Idea behind this is, that the user is already logged in on the YouTube App instead of the Instagram Browser and can easily like and subscribe.

For Solving this issue I know we have to trigger the Instagram App into a state, knowing it has to open up the YouTube App.

In this Case I've already found a working solution as code.

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title></title>
    </head>
    <body>
        <script type="text/javascript">
            window.onload = function() {
                // fallback link in case user doesn't have the app or opens link on desktop
                var fallback = "link here",
                // app to direct to youtube application, last part of link can be;
                // video: watch?v=your_id
                // channel: channel/your_id
                app = "vnd.youtube://last part of link here";

                if( /Android|iPhone|iPad|iPod/i.test(navigator.userAgent) ) {
                    window.location = app;
                    window.setTimeout(function() {
                        // couldn't open app, open fallback url
                        window.location = fallback;
                    }, 25);
                } else {
                    // open url because device doesn't support youtube app
                    window.location = fallback;
                }

                function killPopup() {
                    window.removeEventListener('pagehide', killPopup);
                }

                window.addEventListener('pagehide', killPopup);
            };
        </script>
    </body>
</html>

Source: https://justinbieshaar.com/how-to-make-a-youtube-deeplink/

Does Anyone of you know how to translate this Function into a Plugin or a Codefile to run it with YOURLS.

The only approach I already thought about, was using Regular Expressions with this Plugin, but I'm not techy enough to understand how to implement it so far.

Help Appreciated :)

Upvotes: 0

Views: 451

Answers (0)

Related Questions