[
  {
    "path": "LICENSE",
    "content": "The MIT License (MIT)\n\nCopyright (c) 2014 Hampus Ohlsson\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n\n"
  },
  {
    "path": "README.md",
    "content": "browser-deeplink\n================\n\n**‼️  Not maintained** - *Use at own risk*   \n\nRedirect your website users to your native Android and/or iOS app. If the user does not have the app, they are redirected to the corresponding app store page. \n\nSuch functionality is very common for apps like YouTube, Spotify etc. But it is not default functionality in mobile browsers today, and unnecessarily hard to implement. This plugin uses a workaround with a hidden `iframe` and `setTimeout()`.\n\nHow to use\n-\n\n### 1. Include browser-deeplink on your site.\n\n```html\n<script src=\"browser-deeplink.js\" type=\"text/javascript\"></script>\n```\n\nor\n\n```js\nrequire(\"./browser-deeplink\");\n```\n\n### 2. Provide your app details\n```js\ndeeplink.setup({\n    iOS: {\n        appName: \"myapp\",\n        appId: \"123456789\",\n    },\n    android: {\n        appId: \"com.myapp.android\"\n    }\n});\n```\n\nThis will create the following fallback app store links:\n\n**iOS:** `itms-apps://itunes.apple.com/app/myapp/id123456789?mt=8`    \n**Android:** `https://play.google.com/store/apps/details?id=com.myapp.android`\n\n#### Options\n\nOptionally, you can specify a `iOS.storeUrl` or `android.storeUrl` to override the fallback redirect.\n```js\ndeeplink.setup({\n    iOS: {\n        storeUrl: \"http://...\",\n    }\n});\n```\n\nYou can also skip the app store fallback altogether if you want by specifying `fallback: false`\n```js\ndeeplink.setup({\n    fallback: false\n});\n```\n\nIn case you want to register your android app on your http(s) links directly you can disable deeplinking for android  by specifying `androidDisabled: true`\n```js\ndeeplink.setup({\n    androidDisabled: true\n});\n```\n\n### 3. Open your deeplinks!\n```js\nwindow.onload = function() {\n    deeplink.open(\"myapp://object/xyz\");\n}\n```\n\n# License\nThis library is released under the MIT licence.\n"
  },
  {
    "path": "browser-deeplink.js",
    "content": "/**\n * browser-deeplink v0.1\n *\n * Author: Hampus Ohlsson, Nov 2014\n * GitHub: http://github.com/hampusohlsson/browser-deeplink\n *\n * MIT License\n */\n \n(function (root, factory) {\n    if ( typeof define === 'function' && define.amd ) {\n        define(\"deeplink\", factory(root));\n    } else if ( typeof exports === 'object' ) {\n        module.exports = factory(root);\n    } else {\n        root[\"deeplink\"] = factory(root);\n    }\n})(window || this, function(root) {\n \n    \"use strict\"\n\n    /**\n     * Cannot run without DOM or user-agent\n     */\n    if (!root.document || !root.navigator) {\n        return;\n    }\n\n    /**\n     * Set up scope variables and settings\n     */\n    var timeout;\n    var settings = {};\n    var defaults = {\n        iOS: {},\n        android: {},\n        androidDisabled: false,\n        fallback: true,\n        fallbackToWeb: false,\n        delay: 1000,\n        delta: 500\n    }\n\n    /**\n     * Merge defaults with user options\n     * @private\n     * @param {Object} defaults Default settings\n     * @param {Object} options User options\n     * @returns {Object} Merged values of defaults and options\n     */\n    var extend = function(defaults, options) {\n        var extended = {};\n        for(var key in defaults) {\n            extended[key] = defaults[key];\n        };\n        for(var key in options) {\n            extended[key] = options[key];\n        };\n        return extended;\n    };\n\n    /**\n     * Generate the app store link for iOS / Apple app store\n     *\n     * @private\n     * @returns {String} App store itms-apps:// link \n     */\n    var getStoreURLiOS = function() {\n        var baseurl = \"itms-apps://itunes.apple.com/app/\";\n        var name = settings.iOS.appName;\n        var id = settings.iOS.appId; \n        return (id && name) ? (baseurl + name + \"/id\" + id + \"?mt=8\") : null;\n    }\n\n    /**\n     * Generate the app store link for Google Play\n     *\n     * @private\n     * @returns {String} Play store https:// link\n     */\n    var getStoreURLAndroid = function() {\n        var baseurl = \"market://details?id=\";\n        var id = settings.android.appId;\n        return id ? (baseurl + id) : null;        \n    }\n\n    /**\n     * Get app store link, depending on the current platform\n     *\n     * @private\n     * @returns {String} url\n     */\n    var getStoreLink = function() {\n        var linkmap = {\n            \"ios\": settings.iOS.storeUrl || getStoreURLiOS(),\n            \"android\": settings.android.storeUrl || getStoreURLAndroid()\n        }\n\n        return linkmap[settings.platform];\n    }\n\n    /**\n     * Get web fallback link, depending on the current platform\n     * If none is set, default to current url\n     *\n     * @private\n     * @returns {String} url\n     */\n    var getWebLink = function() {\n        var linkmap = {\n            \"ios\": settings.iOS.fallbackWebUrl || location.href,\n            \"android\": settings.android.fallbackWebUrl || location.href\n        }\n\n        return linkmap[settings.platform];\n    }\n\n    /**\n     * Check if the user-agent is Android\n     *\n     * @private\n     * @returns {Boolean} true/false\n     */\n    var isAndroid = function() {\n        return navigator.userAgent.match('Android');\n    }\n\n    /**\n     * Check if the user-agent is iPad/iPhone/iPod\n     *\n     * @private\n     * @returns {Boolean} true/false\n     */\n    var isIOS = function() {\n        return navigator.userAgent.match('iPad') || \n               navigator.userAgent.match('iPhone') || \n               navigator.userAgent.match('iPod');\n    }\n\n    /**\n     * Check if the user is on mobile\n     *\n     * @private\n     * @returns {Boolean} true/false\n     */\n    var isMobile = function() {\n        return isAndroid() || isIOS();\n    }\n\n    /**\n     * Timeout function that tries to open the fallback link.\n     * The fallback link is either the storeUrl for the platofrm\n     * or the fallbackWebUrl for the current platform.\n     * The time delta comparision is to prevent the app store\n     * link from opening at a later point in time. E.g. if the \n     * user has your app installed, opens it, and then returns \n     * to their browser later on.\n     *\n     * @private\n     * @param {Integer} Timestamp when trying to open deeplink\n     * @returns {Function} Function to be executed by setTimeout\n     */\n    var openFallback = function(ts) {\n        return function() {\n            var link = (settings.fallbackToWeb) ?  getWebLink() : getStoreLink();\n            var wait = settings.delay + settings.delta;\n            if (typeof link === \"string\" && (Date.now() - ts) < wait) {\n                window.location.href = link;\n            }\n        }\n    }\n\n    /**\n     * The setup() function needs to be run before deeplinking can work,\n     * as you have to provide the iOS and/or Android settings for your app.\n     *\n     * @public\n     * @param {object} setup options\n     */\n    var setup = function(options) {\n        settings = extend(defaults, options);\n\n        if (isAndroid()) settings.platform = \"android\";\n        if (isIOS()) settings.platform = \"ios\";\n    }\n\n    /**\n     * Tries to open your app URI through a hidden iframe.\n     *\n     * @public\n     * @param {String} Deeplink URI\n     * @return {Boolean} true, if you're on a mobile device and the link was opened\n     */\n    var open = function(uri) {\n        if (!isMobile()) {\n            return false;\n        }\n\n        if (isAndroid() && settings.androidDisabled) {\n            return;\n        }\n\n        if (isAndroid() && !navigator.userAgent.match(/Firefox/)) {\n            var matches = uri.match(/([^:]+):\\/\\/(.+)$/i);\n            uri = \"intent://\" + matches[2] + \"#Intent;scheme=\" + matches[1];\n            uri += \";package=\" + settings.android.appId + \";end\";\n        }\n\n        if (settings.fallback|| settings.fallbackToWeb) {\n            timeout = setTimeout(openFallback(Date.now()), settings.delay);\n        }\n        \n        var iframe = document.createElement(\"iframe\");\n        iframe.onload = function() {\n            clearTimeout(timeout);\n            iframe.parentNode.removeChild(iframe);\n            window.location.href = uri;\n        };\n\n        iframe.src = uri;\n        iframe.setAttribute(\"style\", \"display:none;\");\n        document.body.appendChild(iframe);\n        \n        return true;\n    }\n\n    // Public API\n    return {\n        setup: setup,\n        open: open\n    };\n\n});\n"
  },
  {
    "path": "example.html",
    "content": "<!doctype html>\n<html>\n<head>\n    <meta name=\"viewport\" content=\"initial-scale=1, maximum-scale=1\">\n    <script src=\"browser-deeplink.js\" type=\"text/javascript\"></script>\n    <script type=\"text/javascript\">\n\n    deeplink.setup({\n        iOS: {\n            appId: \"284882215\",\n            appName: \"facebook\",\n        },\n        android: {\n            appId: \"com.facebook.katana\"\n        }\n    });\n\n    function clickHandler(uri) {\n        deeplink.open(uri);\n        return false;\n    }\n\n    </script>\n    <style>\n    *, *:before, *:after {\n        box-sizing: border-box;\n    }\n    a {\n        font-family: monospace;\n        display: block;\n        width: 100%;\n        margin: 10px 0;\n        padding: 25px;\n        background: #060;\n        color:#fff;\n        text-align: center;\n        font-size: 20px;\n    }\n    </style>\n</head>\n<body>\n    <a href=\"#\" data-uri=\"fb://profile\" onclick=\"clickHandler(this.dataset.uri)\">open fb://profile</a>\n</body>\n</html>"
  },
  {
    "path": "package.json",
    "content": "{\n  \"name\": \"browser-deeplink\",\n  \"version\": \"1.0.1\",\n  \"description\": \"Redirect mobile website users to your native iOS and/or Android app \",\n  \"main\": \"browser-deeplink.js\",\n  \"scripts\": {\n    \"test\": \"echo \\\"Error: no test specified\\\" && exit 1\"\n  },\n  \"repository\": {\n    \"type\": \"git\",\n    \"url\": \"https://github.com/hampusohlsson/browser-deeplink\"\n  },\n  \"author\": \"Hampus Ohlsson\",\n  \"license\": \"MIT\",\n  \"bugs\": {\n    \"url\": \"https://github.com/hampusohlsson/browser-deeplink/issues\"\n  },\n  \"homepage\": \"https://github.com/hampusohlsson/browser-deeplink\"\n}\n"
  }
]