From 4b950cdeefb69c1709d28648c574f68ec3d6c980 Mon Sep 17 00:00:00 2001 From: Brett Terpstra Date: Sat, 19 Jun 2021 14:05:44 -0500 Subject: [PATCH] Update to LinkCleaner, add config option --- LinkCleaner.popclipext/Config.plist | 13 +++++++++++++ LinkCleaner.popclipext/README.md | 6 ++++-- LinkCleaner.popclipext/script.rb | 23 +++-------------------- 3 files changed, 20 insertions(+), 22 deletions(-) diff --git a/LinkCleaner.popclipext/Config.plist b/LinkCleaner.popclipext/Config.plist index 3c24240..8de9373 100755 --- a/LinkCleaner.popclipext/Config.plist +++ b/LinkCleaner.popclipext/Config.plist @@ -19,6 +19,19 @@ paste-result + Options + + + Option Identifier + gaonly + Option Type + boolean + Option Default Value + true + Option Label + GA Only + + Credits Name diff --git a/LinkCleaner.popclipext/README.md b/LinkCleaner.popclipext/README.md index 32c09e5..9afcbec 100644 --- a/LinkCleaner.popclipext/README.md +++ b/LinkCleaner.popclipext/README.md @@ -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 diff --git a/LinkCleaner.popclipext/script.rb b/LinkCleaner.popclipext/script.rb index e5469b9..95d16f4 100755 --- a/LinkCleaner.popclipext/script.rb +++ b/LinkCleaner.popclipext/script.rb @@ -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 @@ -45,30 +46,12 @@ def clean_queries begin o = [] input.gsub!(/((?:(?:http|https):\/\/)?[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&:\/~\+#\(\)_]*[\w\-\@^=%&\/~\+#\(\)])?)/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