Created
October 22, 2023 20:59
-
-
Save Sajidur78/ccee2be36a23b4935cf654330d7e20e2 to your computer and use it in GitHub Desktop.
iOS scriptable action to open a website in app
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
// Variables used by Scriptable. | |
// These must be at the very top of the file. Do not edit. | |
// icon-color: blue; icon-glyph: link; share-sheet-inputs: url; | |
const url = args.urls[0] | |
var scheme = ""; | |
var host = ""; | |
var path = ""; | |
var pos = 0; | |
var schemePos = url.indexOf(':'); | |
if (schemePos != -1) | |
{ | |
pos = schemePos; | |
scheme = url.substring(0, schemePos); | |
} | |
if (url.startsWith("://", pos)) | |
{ | |
pos += 3; | |
} | |
else if (url.startsWith("//", pos) || url.startsWith("\\\\", pos)) | |
{ | |
pos += 2; | |
} | |
for (var i = pos; i < url.length; i++) | |
{ | |
if (url[i] == '/' || url[i] == '\\') | |
{ | |
host = url.substring(pos, i); | |
pos = i + 1; | |
break; | |
} | |
} | |
path = url.substring(pos); | |
var hostParts = host.split('.').reverse(); | |
var name = ""; | |
if (hostParts.length == 1) | |
{ | |
name = hostParts[0]; | |
} | |
else | |
{ | |
name = hostParts[1]; | |
} | |
var launchUrl = name + "://" + host + "/" + path | |
Safari.open(launchUrl) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment