Skip to content

Instantly share code, notes, and snippets.

@OKsign
Created May 19, 2018 14:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save OKsign/23c68a3f5257c018c418321dd6f19423 to your computer and use it in GitHub Desktop.
Save OKsign/23c68a3f5257c018c418321dd6f19423 to your computer and use it in GitHub Desktop.
-- clean copied link
delay 0.5
set copT to the clipboard
-- google.
if copT contains "google." then
try
set AppleScript's text item delimiters to {"url="}
set Clean1 to text item 2 of copT
set AppleScript's text item delimiters to {"&usg="}
set Clean2 to text item 1 of Clean1
-- search and replace - Clean2
set prevTIDs to AppleScript's text item delimiters
set AppleScript's text item delimiters to the "%3A" -- search
set the item_list to every text item of Clean2 -- original text
delay 0.04
set AppleScript's text item delimiters to the ":" -- replace
set Clean3 to the item_list as string
set AppleScript's text item delimiters to prevTIDs
-- search and replace - Clean3
set prevTIDs to AppleScript's text item delimiters
set AppleScript's text item delimiters to the "%2F%2F" -- search
set the item_list to every text item of Clean3 -- original text
delay 0.04
set AppleScript's text item delimiters to the "//" -- replace
set Clean4 to the item_list as string
set AppleScript's text item delimiters to prevTIDs
-- search and replace - Clean4
set prevTIDs to AppleScript's text item delimiters
set AppleScript's text item delimiters to the "%2F" -- search
set the item_list to every text item of Clean4 -- original text
delay 0.04
set AppleScript's text item delimiters to the "/" -- replace
set Clean5 to the item_list as string
set AppleScript's text item delimiters to prevTIDs
-- end clean
-- if
if Clean5 contains "%3F" then
set prevTIDs to AppleScript's text item delimiters
set AppleScript's text item delimiters to the "%3F" -- search
set the item_list to every text item of Clean5 -- original text
delay 0.04
set AppleScript's text item delimiters to the "?" -- replace
set Clean5 to the item_list as string
set AppleScript's text item delimiters to prevTIDs
end if
if Clean5 contains "%3D" then
set prevTIDs to AppleScript's text item delimiters
set AppleScript's text item delimiters to the "%3D" -- search
set the item_list to every text item of Clean5 -- original text
delay 0.04
set AppleScript's text item delimiters to the "=" -- replace
set Clean5 to the item_list as string
set AppleScript's text item delimiters to prevTIDs
end if
if Clean5 contains "%26" then
set prevTIDs to AppleScript's text item delimiters
set AppleScript's text item delimiters to the "%26" -- search
set the item_list to every text item of Clean5 -- original text
delay 0.04
set AppleScript's text item delimiters to the "&" -- replace
set Clean5 to the item_list as string
set AppleScript's text item delimiters to prevTIDs
end if
-- end if
delay 0.2
set the clipboard to Clean5
delay 1
tell application "System Events"
display notification "Done!" with title "Script 8.1"
end tell
return
end try
end if -- copT contains "google."
if copT contains "amazon." then
try
set AppleScript's text item delimiters to {"ref="}
set Clean1 to text item 1 of copT
delay 0.2
set the clipboard to Clean1
delay 1
tell application "System Events"
display notification "Done!" with title "Script 8.1"
end tell
return
end try
end if -- copT contains "google."
if copT contains "?utm_" then
try
set AppleScript's text item delimiters to {"?utm_"}
set Clean1 to text item 1 of copT
delay 0.2
set the clipboard to Clean1
delay 1
tell application "System Events"
display notification "Done!" with title "Script 8.1"
end tell
return
end try
end if -- copT contains "?utm_"
if copT contains "addons.mozilla" then
try
set AppleScript's text item delimiters to {"?src="}
set Clean1 to text item 1 of copT
delay 0.2
set the clipboard to Clean1
delay 1
tell application "System Events"
display notification "Done!" with title "Script 8.1"
end tell
return
end try
end if -- copT contains "addons.mozilla"
if copT contains "youtube." then
try
if copT contains "feature=youtu.be&" then
set AppleScript's text item delimiters to {"feature=youtu.be&"}
set Clean1 to text item 1 of copT & text item 2 of copT
delay 0.2
set the clipboard to Clean1
delay 1
tell application "System Events"
display notification "Done!" with title "Script 8.1"
end tell
return
end if
if copT contains "&app=desktop" then
set AppleScript's text item delimiters to {"&app=desktop"}
set Clean1 to text item 1 of copT
delay 0.2
set the clipboard to Clean1
delay 1
tell application "System Events"
display notification "Done!" with title "Script 8.1"
end tell
return
end if
end try
end if -- copT contains "youtube."
if copT contains "ebay." then
try
if copT contains "?hash=" then
set AppleScript's text item delimiters to {"?hash="}
set Clean1 to text item 1 of copT
delay 0.2
set the clipboard to Clean1
delay 1
tell application "System Events"
display notification "Done!" with title "Script 8.1"
end tell
return
end if
if copT contains "?_trkparms" then
set AppleScript's text item delimiters to {"?_trkparms"}
set Clean1 to text item 1 of copT
delay 0.2
set the clipboard to Clean1
delay 1
tell application "System Events"
display notification "Done!" with title "Script 8.1"
end tell
return
end if
-- sponsor link (tested on sneakers)
if copT does not contain "https://www." then
if copT contains "mecs%22%3A%22" then
set AppleScript's text item delimiters to {"mecs%22%3A%22"}
set first12c to (characters 1 thru 12 of text item 2 of copT)
set prevTIDs to AppleScript's text item delimiters
set AppleScript's text item delimiters to the ", " -- search
set the item_list to every text item of first12c -- original text
delay 0.04
set AppleScript's text item delimiters to the "" -- replace
set first12c to the item_list as string
set AppleScript's text item delimiters to prevTIDs
set Clean1 to "https://www.ebay.com/itm/" & first12c
delay 0.2
set the clipboard to Clean1
delay 1
tell application "System Events"
display notification "Done!" with title "Script 8.1"
end tell
return
end if
end if
end try
end if -- copT contains "ebay."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment