Sharing links between devices using ntfy and Greasemonkey

There are many use cases where I want to share the links with other devices from a Desktop. One specific use case is solved by read-later setup I have. It's the case where I want to read something later, preferably in offline mode. The content also gets archived. The other important usecase is that I want to share the link for quick access on a different machine, like a link to the Metabase dashboard or a link to the plantuml diagram, etc. This is where ntfy and Greasemonkey work very well. I have a userscript that pickups up the current document URL and title and posts it to ntfy topic. Below is the script if you want to use.

Make sure to replace {{ntfy_url}} with real ntfy endpoint. Also the {{authorization}} with real authorization key, which infact is btoa("username:password"). The topic I am using here is called sharing.

// ==UserScript==
// @name              ntfy
// @author            Thejesh GN
// @description       ntfy script
// @version           0.1
// @grant GM_addStyle
// @grant GM.xmlHttpRequest
// @grant GM.registerMenuCommand
// @grant GM.notification
// @icon https://lib.thejeshgn.com/lib_files/emoji_png/bell.png
// ==/UserScript==


function ntfy_me(){
  GM.notification("Start", "ntfy");   
  var d = {"topic": "sharing", "tags":["link"], "priority": 3, "message": document.title};
  d["actions"] = [{ "action": "view", "label": "Open Link", "url": window.location.href }];
  GM.xmlHttpRequest({
      method: "POST",
      headers: {
                  "Content-type": "application/json; charset=UTF-8",
                  "Authorization":"Basic {{authorization}}"
      },
      data: JSON.stringify(d),
      url: "{{ntfy_url}}",
      onload: function(response) {
        GM.notification(response.responseText, "ntfy");          
      }
  });
}


GM.registerMenuCommand("ntfy", ntfy_me, "n");



You can read this blog using RSS Feed. But if you are the person who loves getting emails, then you can join my readers by signing up.

Join 2,243 other subscribers

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.