Open notification link to new tab by keyboard for GitHub

Add keyboard shortcuts to open focusing link of GitHub Notifications. 1) v to open link in new tab. 2) Shift+v to open links from same repository in new tabs.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

You will need to install an extension such as Tampermonkey to install this script.

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

// ==UserScript==
// @name         Open notification link to new tab by keyboard for GitHub
// @namespace    http://kyanny.me/
// @version      1.0.0
// @description  Add keyboard shortcuts to open focusing link of GitHub Notifications. 1) v to open link in new tab. 2) Shift+v to open links from same repository in new tabs.
// @author       Kensuke Nagae
// @match        https://github.com/notifications
// @match        https://github.com/notifications/participating
// @match        https://github.com/*/*/notifications*
// @grant        none
// ==/UserScript==

/*
For Firefox, browser.tabs.loadDivertedInBackground to true is useful.
See https://stackoverflow.com/a/1306963/374851
*/

(function() {
  'use strict';

  var logger = {
    info: function(msg) {
      console.log(msg);
    },
    debug: function(msg) {
      // console.debug(msg);
    },
  };

  var findTarget = function(item) {
    logger.debug('find target');
    return item.querySelector('.js-notification-target');
  };

  var openLink = function(target) {
    var link = target.href;
    logger.info('opening ' + link);
    window.open(link, '_blank');
  };

  var markAsRead = function(item) {
    logger.debug('mark as read');
    item.setAttribute('class', item.getAttribute('class') + ' read');
  };

  document.addEventListener('keyup', function(ev) {
    var key = ev.key.toLowerCase();
    var focusingItem = document.querySelector('.navigation-focus');
    if (key === 'v' && !!focusingItem) {
      if (ev.shiftKey === true) { // Shift key is pressed
        var siblings = focusingItem.parentNode.querySelectorAll('.js-notification');
        [].forEach.call(siblings, function(sibling) {
          var target = findTarget(sibling);
          openLink(target);
          markAsRead(sibling);
        });
      } else {
        var target = findTarget(focusingItem);
        openLink(target);
        markAsRead(focusingItem);
      }
    }
  });
})();