GitHub Notification Right Click to Repo Page

Open the repository home page with a right click on the notification item. 右键点击 GitHub 的通知项直接跳转到项目主页。

As of 2022-08-28. See the latest version.

  1. // ==UserScript==
  2. // @name GitHub Notification Right Click to Repo Page
  3. // @namespace http://clear.studio/
  4. // @version 0.2
  5. // @license MIT
  6. // @description Open the repository home page with a right click on the notification item. 右键点击 GitHub 的通知项直接跳转到项目主页。
  7. // @author Kytrun
  8. // @match https://github.com/notifications*
  9. // @icon https://github.com/favicon.ico
  10. // @grant none
  11. // ==/UserScript==
  12.  
  13. (function () {
  14. 'use strict';
  15. const rightClickOpenRepo = () => {
  16. const lis = document.querySelectorAll('li.notifications-list-item');
  17.  
  18. lis.forEach(li => {
  19. const notifiLink = li.querySelector('a.notification-list-item-link').href;
  20. const repoReg = /(https:\/\/github\.com\/[a-zA-Z0-9-]+\/[a-zA-Z0-9-\.]+)\/.+/;
  21. const repoLink = notifiLink.replace(repoReg, '$1');
  22. //console.log(repoLink);
  23. li.addEventListener('contextmenu', function (ev) {
  24. ev.preventDefault();
  25. window.open(repoLink);
  26. return false;
  27. }, false);
  28. });
  29. }
  30.  
  31. rightClickOpenRepo();
  32.  
  33. // SPA reload
  34. window.history.pushState = new Proxy(window.history.pushState, {
  35. apply: (target, thisArg, argArray) => {
  36.  
  37. setTimeout(rightClickOpenRepo, 2000);
  38.  
  39. return target.apply(thisArg, argArray);
  40. },
  41. });
  42. })();