Created
August 16, 2022 20:54
-
-
Save andrewvmail/e2846da4529ca153548a5f3b8dc6ba9e to your computer and use it in GitHub Desktop.
load-cordova.ts
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
console.log("[ loadCordova ] script loaded"); | |
// VERY HIGH CHANCE OF REGRESSION IN HERE | |
// IF VENDOR CHANGES USER-AGENT STRING | |
const userAgent = window.navigator.userAgent.toLowerCase(); | |
const safari = /safari/.test(userAgent); | |
const applewebkit = /applewebkit/.test(userAgent); | |
const mobileDescriptor = /mobile/.test(userAgent); | |
const ios = /iphone|ipod|ipad/.test(userAgent); | |
const ipadOs = applewebkit && mobileDescriptor; | |
const androidWebview = userAgent.includes("wv"); | |
function loadCordova() { | |
console.log("[ loadCordova ] loadCordova() start "); | |
var head = document.getElementsByTagName("head")[0]; | |
var js = document.createElement("script"); | |
js.type = "text/javascript"; | |
js.src = "cordova.js"; | |
head.appendChild(js); | |
console.log("[ loadCordova ] loadCordova() end"); | |
} | |
if (ios || ipadOs || androidWebview) { | |
loadCordova(); | |
} else { | |
console.log("[ loadCordova ] on a desktop browser, do nothing"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment