GitHub Notification Right Click to Repo Page

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

  1. // ==UserScript==
  2. // @name GitHub Notification Right Click to Repo Page
  3. // @namespace http://clear.studio/
  4. // @version 0.3
  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. lis.forEach(li => {
  18. if(!li.dataset.directlyHome){
  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. li.dataset.directlyHome = "true"
  29. //li.style.color = 'red'
  30. }
  31. });
  32. }
  33.  
  34. //rightClickOpenRepo();
  35.  
  36. const observe = ()=>{
  37. const callback = function (mutationsList, observer) {
  38. rightClickOpenRepo();
  39. };
  40. const observer = new MutationObserver(callback);
  41. const observedNode = document.body;
  42. const config = { attributes: true, childList: true,subtree: true };
  43. observer.observe(observedNode, config);
  44. //observer.disconnect();
  45. }
  46. observe();
  47. })();