Skip to content

Commit

Permalink
Update to LinkCleaner, add config option
Browse files Browse the repository at this point in the history
  • Loading branch information
ttscoff committed Jun 19, 2021
1 parent 2e3b3fd commit 4b950cd
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 22 deletions.
13 changes: 13 additions & 0 deletions LinkCleaner.popclipext/Config.plist
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,19 @@
<string>paste-result</string>
</dict>
</array>
<key>Options</key>
<array>
<dict>
<key>Option Identifier</key>
<string>gaonly</string>
<key>Option Type</key>
<string>boolean</string>
<key>Option Default Value</key>
<string>true</string>
<key>Option Label</key>
<string>GA Only</string>
</dict>
</array>
<key>Credits</key>
<array>
<key>Name</key>
Expand Down
6 changes: 4 additions & 2 deletions LinkCleaner.popclipext/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ LinkCleaner

PopClip extension to lengthen and clean URLs.

Option: clean all query strings (default: only clean Google UTM strings)
Use extension settings to determine whether it strips Google Analytics strings only, or _all_ query strings.

Option: force clean all query strings, ignore settings
Command: Output just the resulting URL(s)
Command-Option: Output just URL(s) with query strings stripped
Command-Option: Output just URL(s) with all query strings stripped
23 changes: 3 additions & 20 deletions LinkCleaner.popclipext/script.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@


unless debug
strip_all_queries = ENV['POPCLIP_OPTION_GAONLY'].to_i == 0
orig_input = ENV['POPCLIP_TEXT'].dup
else
orig_input = "Brought to you by http://bit.ly/1hQ92Iz and http://brettterpstra.com"
strip_all_queries = true
orig_input = "Brought to you by http://bit.ly/1hQ92Iz and http://brettterpstra.com, https://clutchpoints.com/clippers-news-rajon-rondo-speaks-out-after-clippers-debut-vs-lakers/?fbclid=IwAR3epED82RKaRTrmL4X_uBCoVjU6mmFxFhZcAXshKwMzm17RuAT_oxxteiE"
end

input = orig_input.dup

strip_all_queries = false
only_links = false

case ENV['POPCLIP_MODIFIER_FLAGS'].to_i
Expand All @@ -45,30 +46,12 @@ def clean_queries
begin
o = []
input.gsub!(/((?:(?:http|https):\/\/)?[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&amp;:\/~\+#\(\)_]*[\w\-\@^=%&amp;\/~\+#\(\)])?)/mi) {|url|
if url =~ /https?:\/\/[\da-z]+\.[a-z]{2}\/[A-Za-z0-9]+/
res = Net::HTTP.get(URI.parse("http://api.longurl.org/v2/expand?format=xml&url=#{CGI.escape(url)}"))
doc = REXML::Document.new(res.strip)
url = doc.elements["response/long-url"].text
end
url = url.clean_google
url = url.clean_queries if strip_all_queries || debug
o.push(url)
url
}

# urls.each {|url|
# if url.length == 3 && url.join("") !~ /^[\d\.]+$/

# url = url[0]

# if url =~ /\)/ && url !~ /\(/
# url = url.sub(/\).*?$/,'')
# end

# target = url =~ /^http/ ? url : "http://#{url}"
# o += target + "\n"
# end
# }
if only_links
puts o.join("\n")
else
Expand Down

0 comments on commit 4b950cd

Please sign in to comment.