var detectOs = { getUserAgent: () => { return navigator.userAgent; }, getPlatform: () => { return navigator.platform; }, isIos: () => { return /iPhone|iPad|iPod/.test(detectOs.getPlatform()); }, isAndroid: () => { return /Android/.test(detectOs.getUserAgent()); }, isBlackBerry: () => { return /BlackBerry/.test(detectOs.getPlatform()); }, isMac: () => { return /Mac/.test(detectOs.getPlatform()); }, isWindows: () => { return /Win/.test(detectOs.getPlatform()); }, isLinux: () => { return /Linux/.test(detectOs.getPlatform()) && !detectOs.isAndroid(); }, get: () => { if (detectOs.isIos()) return 'iOS'; if (detectOs.isAndroid()) return 'Android'; if (detectOs.isBlackBerry()) return 'BlackBerry'; if (detectOs.isMac()) return 'Mac'; if (detectOs.isWindows()) return 'Windows'; if (detectOs.isLinux()) return 'Linux'; return 'Unknown'; } } var detectFBPageName = { getName: (pageUrl) => { try{ var url = new URL(pageUrl); return url.pathname.split("/").pop() } catch(ex){ console.log(ex); return false; } return false; } } jQuery(document).ready(function(){ jQuery(".fab.fa-facebook-f").closest("a").each(function(){ var pageID = detectFBPageName.getName(jQuery(this).attr("href")); if(!pageID){ return; } if(detectOs.isAndroid()){ jQuery(this).attr("href", "fb://page/" + pageID); } else if (detectOs.isIos()){ jQuery(this).attr("href", "fb://profile/" + pageID); } }) });