sci-hub improvements to alfred and hammerspoon

pull/2/head
Alpha Chen 2 years ago
parent e1dcd06999
commit f22bff9c4a

@ -52,29 +52,30 @@
;; mdls -name kMDItemCFBundleIdentifier -r SomeApp.app ;; mdls -name kMDItemCFBundleIdentifier -r SomeApp.app
;; fnlfmt: skip ;; fnlfmt: skip
(local matchers {".*[.]zoom.us/j/%d+" :us.zoom.xos (local bundle-ids {:firefox :org.mozilla.firefoxdeveloperedition
; ".*[.]webex.com/" :com.webex.meetingmanager :safari :com.apple.Safari
".*[.]discnw.org/" :com.apple.Safari :zoom :us.zoom.xos})
:squareup.com/ :com.apple.Safari})
(fn handle [url orig-url]
(fn bundleIDForURL [url] (let [open-with (fn [app]
(var bundleID nil) (partial #(hs.urlevent.openURLWithBundle $2 $1)
(each [key value (pairs matchers) :until bundleID] (. bundle-ids app)))
(if (string.find url (.. "^https://" key)) open-url #((open-with $1) url)]
(set bundleID value))) (if (string.find url "^https://.*[.]zoom.us/j/%d+") (open-url :zoom)
(or bundleID :org.mozilla.firefoxdeveloperedition)) (string.find url "^https://.*[.]discnw.org/") (open-url :safari)
(string.find url "^https://squareup.com/") (open-url :safari)
(string.find orig-url "^https://doi.org/")
((open-with :firefox) (.. "https://sci-hub.st/" orig-url))
(open-url :firefox))))
(set hs.urlevent.httpCallback (set hs.urlevent.httpCallback
(fn [scheme host params url] (fn [scheme host params url]
(let [run #(: (io.popen (.. $1 " \"" $2 "\"")) :read :*a) (let [run #(: (io.popen (.. $1 " \"" $2 "\"")) :read :*a)
de-utm (partial run "~/.dotfiles/bin/de-utm") de-utm (partial run "~/.dotfiles/bin/de-utm")
redirect (partial run "curl -Ls -o /dev/null -w %{url_effective}") redirect (partial run "curl -Ls -o /dev/null -w %{url_effective}")
final-url (->> url orig-url (de-utm url)
(de-utm) redirected (de-utm (redirect orig-url))]
(redirect) (handle redirected orig-url))))
(de-utm))
bundleID (bundleIDForURL final-url)]
(hs.urlevent.openURLWithBundle final-url bundleID))))
;;; Spoons ;;; Spoons
@ -97,3 +98,4 @@
(: (hs.notify.new {:title :Hammerspoon (: (hs.notify.new {:title :Hammerspoon
:informativeText "Config loaded" :informativeText "Config loaded"
:withdrawAfter 2}) :send) :withdrawAfter 2}) :send)

@ -19,19 +19,6 @@
<key>utf8</key> <key>utf8</key>
<true/> <true/>
</dict> </dict>
<key>44474AB2-A23A-4D3C-AB64-0DFE164ED23A</key>
<dict>
<key>enabled</key>
<true/>
<key>keyword</key>
<string>sh</string>
<key>text</key>
<string>Open '{query}' in Sci-Hub</string>
<key>url</key>
<string>https://sci-hub.st/{query}</string>
<key>utf8</key>
<true/>
</dict>
<key>491B807D-42B3-4CB4-861F-2ADF20727F53</key> <key>491B807D-42B3-4CB4-861F-2ADF20727F53</key>
<dict> <dict>
<key>enabled</key> <key>enabled</key>

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>keyword</key>
<string>yt</string>
</dict>
</plist>

@ -0,0 +1,177 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>bundleid</key>
<string>dev.kejadlen.sci-hub</string>
<key>connections</key>
<dict>
<key>2F37680A-B350-467A-BD23-806AEC9F3004</key>
<array>
<dict>
<key>destinationuid</key>
<string>F526679F-2346-4831-B920-A085F4E9B7E0</string>
<key>modifiers</key>
<integer>0</integer>
<key>modifiersubtext</key>
<string></string>
<key>vitoclose</key>
<false/>
</dict>
</array>
<key>99B99B9B-2CEE-4B07-85DC-40BE5C4B03DC</key>
<array>
<dict>
<key>destinationuid</key>
<string>2F37680A-B350-467A-BD23-806AEC9F3004</string>
<key>modifiers</key>
<integer>0</integer>
<key>modifiersubtext</key>
<string></string>
<key>vitoclose</key>
<false/>
</dict>
</array>
<key>F526679F-2346-4831-B920-A085F4E9B7E0</key>
<array>
<dict>
<key>destinationuid</key>
<string>E803BE34-15CD-42A3-B13A-59C2C773ECA6</string>
<key>modifiers</key>
<integer>0</integer>
<key>modifiersubtext</key>
<string></string>
<key>vitoclose</key>
<false/>
</dict>
</array>
</dict>
<key>createdby</key>
<string>Alpha Chen</string>
<key>description</key>
<string>Open URL in Sci-Hub</string>
<key>disabled</key>
<false/>
<key>name</key>
<string>Sci-Hub</string>
<key>objects</key>
<array>
<dict>
<key>config</key>
<dict>
<key>browser</key>
<string></string>
<key>skipqueryencode</key>
<true/>
<key>skipvarencode</key>
<true/>
<key>spaces</key>
<string></string>
<key>url</key>
<string>https://sci-hub.st/{query}</string>
</dict>
<key>type</key>
<string>alfred.workflow.action.openurl</string>
<key>uid</key>
<string>E803BE34-15CD-42A3-B13A-59C2C773ECA6</string>
<key>version</key>
<integer>1</integer>
</dict>
<dict>
<key>config</key>
<dict>
<key>argumenttype</key>
<integer>1</integer>
<key>keyword</key>
<string>sh</string>
<key>subtext</key>
<string></string>
<key>text</key>
<string>Open in Sci-Hub</string>
<key>withspace</key>
<true/>
</dict>
<key>type</key>
<string>alfred.workflow.input.keyword</string>
<key>uid</key>
<string>99B99B9B-2CEE-4B07-85DC-40BE5C4B03DC</string>
<key>version</key>
<integer>1</integer>
</dict>
<dict>
<key>config</key>
<dict>
<key>matchmode</key>
<integer>2</integer>
<key>matchstring</key>
<string></string>
<key>replacestring</key>
<string>{var:clipboard}</string>
</dict>
<key>type</key>
<string>alfred.workflow.utility.replace</string>
<key>uid</key>
<string>F526679F-2346-4831-B920-A085F4E9B7E0</string>
<key>version</key>
<integer>2</integer>
</dict>
<dict>
<key>config</key>
<dict>
<key>argument</key>
<string>{query}</string>
<key>passthroughargument</key>
<true/>
<key>variables</key>
<dict>
<key>clipboard</key>
<string>{clipboard}</string>
</dict>
</dict>
<key>type</key>
<string>alfred.workflow.utility.argument</string>
<key>uid</key>
<string>2F37680A-B350-467A-BD23-806AEC9F3004</string>
<key>version</key>
<integer>1</integer>
</dict>
</array>
<key>readme</key>
<string></string>
<key>uidata</key>
<dict>
<key>2F37680A-B350-467A-BD23-806AEC9F3004</key>
<dict>
<key>xpos</key>
<real>285</real>
<key>ypos</key>
<real>90</real>
</dict>
<key>99B99B9B-2CEE-4B07-85DC-40BE5C4B03DC</key>
<dict>
<key>xpos</key>
<real>55</real>
<key>ypos</key>
<real>60</real>
</dict>
<key>E803BE34-15CD-42A3-B13A-59C2C773ECA6</key>
<dict>
<key>xpos</key>
<real>585</real>
<key>ypos</key>
<real>60</real>
</dict>
<key>F526679F-2346-4831-B920-A085F4E9B7E0</key>
<dict>
<key>xpos</key>
<real>435</real>
<key>ypos</key>
<real>90</real>
</dict>
</dict>
<key>userconfigurationconfig</key>
<array/>
<key>webaddress</key>
<string></string>
</dict>
</plist>
Loading…
Cancel
Save