gotify-firefox

Send push notifications to your Gotify server from Firefox
git clone git://fossdaily.xyz/gotify-firefox
Log | Files | Refs | README | LICENSE

background.js (1593B)


      1 "use strict";
      2 
      3 gotify.getCurrentTabUrl = function (info, tab, callback, done) {
      4   var queryInfo = {
      5     active: true,
      6     currentWindow: true,
      7   };
      8 
      9   browser.tabs.query(queryInfo, function (tabs) {
     10     var tab = tabs[0];
     11     var object = gotify.buildMessageObject(tab.title, tab.url);
     12     callback(object, done);
     13   });
     14 };
     15 
     16 gotify.buildMenu = function () {
     17   browser.menus.create({
     18     title: "Send this page",
     19     contexts: ["page"],
     20     onclick: function (info, tab) {
     21       gotify.getCurrentTabUrl(info, tab, gotify.postMessage, function (
     22         message
     23       ) {
     24         gotify.log("Done!");
     25       });
     26     },
     27   });
     28 
     29   browser.menus.create({
     30     title: "Send selected text",
     31     contexts: ["selection"],
     32     onclick: function (text) {
     33       var message = text.selectionText;
     34       var object = gotify.buildMessageObject("Selected text", message);
     35       gotify.postMessage(object, function () {
     36         gotify.log("Done!");
     37       });
     38     },
     39   });
     40 
     41   browser.menus.create({
     42     title: "Send image URL",
     43     contexts: ["image"],
     44     onclick: function (image) {
     45       var message = image.srcUrl;
     46       var object = gotify.buildMessageObject("Image URL", message);
     47       gotify.postMessage(object, function () {
     48         gotify.log("Done!");
     49       });
     50     },
     51   });
     52 
     53   browser.menus.create({
     54     title: "Send link",
     55     contexts: ["link"],
     56     onclick: function (link) {
     57       var message = link.linkUrl;
     58       var object = gotify.buildMessageObject("Link URL", message);
     59       gotify.postMessage(object, function () {
     60         gotify.log("Done!");
     61       });
     62     },
     63   });
     64 };
     65 
     66 gotify.buildMenu();