Skip to content

Instantly share code, notes, and snippets.

@yb66
Last active February 20, 2021 04:24
Show Gist options
  • Save yb66/d39109df620ab1db2a46c943111c31d0 to your computer and use it in GitHub Desktop.
Save yb66/d39109df620ab1db2a46c943111c31d0 to your computer and use it in GitHub Desktop.
# Because I don't like being tracked by Facebook around the web
# This function, which I load via my ~/.zshrc,
# - takes the url on the clipboard (when run)
# - decodes the querystring to find the original link
# - removes the FB id from the resulting query string
# - pops it back onto the clipboard
fb-uri(){
str=${1:-`pbpaste`}
ruby -W0 -ruri -r'rack/utils' -e "print URI(Rack::Utils.parse_query(URI('$str').query)['u']).then{|uri| %Q(#{uri.scheme}://#{uri.host}#{uri.path}#{ (hs = Rack::Utils.parse_query(uri.query).reject{|k,_| k == 'fbclid'}).empty? ? '' : %Q(?#{Rack::Utils.build_query hs}) }) }" | pbcopy
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment