Last active
February 27, 2023 18:20
-
-
Save sudarshann/ab3fdb922d3d068cfda6fc466e22c647 to your computer and use it in GitHub Desktop.
Revisions
-
sudarshann revised this gist
Jul 22, 2021 . 1 changed file with 31 additions and 14 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -39,31 +39,48 @@ var facebookLinks = function () { var detectFBPageName = { getName: function (pageUrl) { try { if(!pageUrl.includes('facebook.com')){ return false; } var url = new URL(pageUrl); var urlParts = url.pathname.split('/'); var name = urlParts.pop(); if(name){ return name; } else { return urlParts.pop(); } } catch (ex) { return false; } return false; } }; if (detectOs.isAndroid() || detectOs.isIos() ) { jQuery('a').each(function () { var pageID = detectFBPageName.getName(jQuery(this).attr('href')); if (!pageID) { return; } var currentUrl = jQuery(this).attr('href'); if (detectOs.isAndroid()) { jQuery(this).attr('href', 'intent://page/' + pageID + '#Intent;scheme=fb;package=com.facebook.katana;S.browser_fallback_url='+ encodeURIComponent(currentUrl) +';end'); } else if (detectOs.isIos()) { jQuery(this).attr('href', 'fb://profile/' + pageID); } else { jQuery(this).attr('href', currentUrl.replace('web.', '')); } }); } }; jQuery(document).ready(function () { facebookLinks(); }); -
sudarshann revised this gist
Jul 20, 2021 . 1 changed file with 63 additions and 59 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,65 +1,69 @@ var facebookLinks = function () { var detectOs = { getUserAgent: function () { return navigator.userAgent; }, getPlatform: function () { return navigator.platform; }, isIos: function () { return /iPhone|iPad|iPod/.test(detectOs.getPlatform()); }, isAndroid: function () { return /Android/.test(detectOs.getUserAgent()); }, isBlackBerry: function () { return /BlackBerry/.test(detectOs.getPlatform()); }, isMac: function () { return /Mac/.test(detectOs.getPlatform()); }, isWindows: function () { return /Win/.test(detectOs.getPlatform()); }, isLinux: function () { return /Linux/.test(detectOs.getPlatform()) && !detectOs.isAndroid(); }, get: function () { 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: function (pageUrl) { try { var url = new URL(pageUrl); return url.pathname.split('/').pop(); } catch (ex) { return false; } return false; } }; jQuery('.fab.fa-facebook-f, .fab.fa-facebook').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); } }); }; jQuery(document).ready(function () { facebookLinks(); }); -
sudarshann created this gist
Jul 20, 2021 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,65 @@ 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); } }) });