Forums before death by AOL, social media and spammers... "We can't have nice things"
|    alt.philosophy    |    Didn't Freud have sex with his mother?    |    170,348 messages    |
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
|    Message 169,084 of 170,348    |
|    oldernow to All    |
|    The joy of Lagrange browser MIME hooks    |
|    12 Apr 24 23:00:12    |
   
   From: oldernow@dev.null   
      
   There are times when I'm browsing Gemini endpoints, but   
   don't want to see links I've already visited.   
      
   Lagrange provides a means to add user-programmed "hooks"   
   that are called whenever it processes a page of a given   
   MIME type (e.g. "text/gemini").   
      
   (Personally, I'd rather be able to invoke a hook as needed   
   via a keybinding. But creating workarounds are one of the   
   things I live for, so.)   
      
   Here's a Lua hook I came up with   
   ("show-only-unvisited-links.lua"):   
      
   ------------------------------------------------------------   
   #! /usr/bin/env lua   
   local home = os.getenv('HOME')   
   local handle = io.open(home ..   
    '/lagrange-show-only-unvisited-links')   
   if handle then   
    handle:close()   
   else   
    os.exit()   
   end   
   local request_url = os.getenv('REQUEST_URL')   
   local visited = {}   
   local handle = io.open(home ..   
    '/.config/lagrange/visited.2.txt')   
   for line in handle:lines() do   
    local url = string.match(line, '(gemini://.-)$')   
    if url then   
    visited[url] = true   
    end   
   end   
   handle:close()   
   io.stdout:write('20 text/gemini; lang=en\r\n')   
   for line in io.stdin:lines() do   
    local url,title = string.match(line,   
    '^=> (gemini://.-)%s(.*)')   
    if url then   
    if not visited[url] then   
    io.stdout:write('=> ' .. url .. ' '   
    .. title .. '\n')   
    end   
    else   
    io.stdout:write(line .. '\n')   
    end   
   end   
   ------------------------------------------------------------   
      
   Since Lagrange will run the hook for "text/gemini"   
   documents every time it processes such a document,   
   The lynchpin on whether or not to perform the   
   transformation is the existence/non-existence of a   
   $HOME/lagrange-show-only-unvisited-links file. I created   
   a pair of scripts to create/remove said file:   
      
   only-unvisited:   
   ------------------------------------------------------------   
   touch $HOME/lagrange-show-only-unvisited-links   
   ------------------------------------------------------------   
      
   visited-too:   
   ------------------------------------------------------------   
   rm -f $HOME/lagrange-show-only-unvisited-links   
   ------------------------------------------------------------   
      
   So usage overall goes like this:   
      
   - run one or the other of those scripts (or do nothing   
    and be happy with the existing state from before)   
      
   - visit Gemini pages in Lagrange   
      
   - should he opposite effect be desired, run the appropriate   
    script, and refresh the current Gemini page   
      
   Nothing to it!   
      
   Oh, more more detail. The following placed in the Lagrange   
   "mimehooks.txt" configuration file is what ties the Lua   
   hook into the Lagrange hook engine:   
      
   ------------------------------------------------------------   
   Show only unvisited links   
   text/gemini   
   /usr/bin/lua;/home/xxxxxxx/.config/lagrange/show-only-unvisited-links.lua   
   ------------------------------------------------------------   
      
   --   
   oldernow   
   xyz001 at nym.hush.com   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   
|
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
(c) 1994, bbs@darkrealms.ca