Clean Up URL
Accepts
Text, Rich Text and URLs
COMMENT
Clean Up URL
v1.0 2022-08-21
https://routinehub.co/shortcut/12855/
This Shortcut cleans up URLs, removing tracking data and other useless attributes.
When copying URLs from social platforms or search engines, those sites often include extra data in them to track users and where they got those addresses. This will remove all of the “query” or “search” params. In simpler terms, everything after the ‘?’ in the URL will be removed, including said punctuation.
The only exception is the video ID in YouTube URLs. More exceptions may be added later.
Be careful when initially using this Shortcut, as YMMV. It may do too much or too little for you.
Change Log
v1.0 2022-08-21
Initial release.
SCRIPTING
Get type of
Shortcut Input

Type
SCRIPTING
If
Type
is
URL
VARIABLES
Get
Shortcut Input
SCRIPTING
Otherwise
SCRIPTING

Provided Input
SCRIPTING
End If

If Result
SCRIPTING
Get type of
If Result

Type
SCRIPTING
If
Type
is
URL
DOCUMENTS
Replace
'
with
\'
in
If Result

Updated Text
SCRIPTING
Otherwise
SCRIPTING
Show
Provided input is not a valid URL.
SCRIPTING
Exit shortcut with
Result
SCRIPTING
End If

If Result
TEXT
<!doctype html>
<title>script</title>
<div id="output"></div>
<script>
const cleanUpUrl = urlStr => {
const url = new URL(urlStr)
const { searchParams: params } = url
const keep = []
switch (true) {
case /(.+\.)?youtube\.com$/.test(url.hostname):
keep.push('v')
break
}
for (const key of params.keys()) {
if (keep.includes(key)) continue
params.delete(key)
}
return url.toString()
}
document.getElementById('output').innerHTML = cleanUpUrl('
Updated Text
')
</script>

Text
SCRIPTING
Mode
Text
with base64

Base64 Encoded
URL
data:text/html;base64,
Base64 Encoded

URL
SAFARI
Get contents of web page at
URL

Contents of Web Page
DOCUMENTS
Get text from
Contents of Web Page

Text
SCRIPTING
If
WFInput?
is not
<value>
SHARING
Copy
Text
to clipboard
SCRIPTING
Show
Text
SCRIPTING
End If

If Result
MISSING
output Under Construction
Showcuts