Skip to content

Instantly share code, notes, and snippets.

@Leftium
Last active March 20, 2024 16:05
Show Gist options
  • Save Leftium/5e1e31dcab4d747d4d9be721bcf53dea to your computer and use it in GitHub Desktop.
Save Leftium/5e1e31dcab4d747d4d9be721bcf53dea to your computer and use it in GitHub Desktop.
Toggle Bookmarklet
url = new URL location
{host, searchParams} = url
params =
summary: searchParams.get 'summary'
url: searchParams.get 'url'
# Not summary
if host isnt 'kagi.com'
# Go to summary
newUrl = "https://kagi.com/summarizer?summary=summary&url=#{location.href}"
else
# Not summary=takeaway
if params.summary is 'summary'
# Go to key moments
url.searchParams.set 'summary', 'takeaway'
newUrl = url
else
# Key moments
# Go to original url
newUrl = params.url
location.href = newUrl
switch location.host
when 'news.ycombinator.com'
location.href = location.href.replace /.*item\?id=/, '//hw.leftium.com/#/item/'
when 'hn.leftium.com', 'hw.leftium.com'
location.href = location.href.replace /.*\//, '//news.ycombinator.com/item?id='
when 'kagi.com'
url = location.href
url = url.replace 'kagi.com', 'google.com'
window.open url, '_blank'
when 'www.google.com'
url = location.href
url = url.replace 'www.google.com', 'kagi.com'
window.open url, '_blank'
when 'mail.google.com'
url = location.href
if url.includes '-label%3Asub'
location.href = 'https://mail.google.com/mail/u/0/?zx=kxekeso7ocxx#label/Sub'
else
location.href = 'https://mail.google.com/mail/u/0/?zx=kxekeso7ocxx#search/-label%3Asub'
when 'docs.google.com'
location.href= "//g.leftium.com?u=#{location.href}"
when 'g.leftium.com'
location.href = decodeURIComponent(location.href.replace /.*u=/, '')
@Leftium
Copy link
Author

Leftium commented Mar 20, 2024

How to use:

  1. Modify as desired.
  2. Compile CoffeeScript to JavaScript at https://coffeescript.org/#try
  3. Generate bookmarklet with tool like: https://caiorss.github.io/bookmarklet-maker/
  4. Add (drag) to browser bookmarks bar.

@Leftium
Copy link
Author

Leftium commented Mar 20, 2024

Tip: mail.google.com toggles between important and unimportant emails, as tagged by this simple method: https://blog.leftium.com/2023/11/automatic-inbox-cleanup-with-two-simple.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment