GitHub Actions notifications

Enable desktop notifications for GitHub Actions updates

  1. // ==UserScript==
  2. // @match https://github.com/*/*/actions
  3. // @name GitHub Actions notifications
  4. // @description Enable desktop notifications for GitHub Actions updates
  5. // @grant GM_notification
  6. // @version 1.0.2
  7. // @author KaKi87
  8. // @license GPL-3.0-or-later
  9. // @namespace https://git.kaki87.net/KaKi87/userscripts/src/branch/master/GitHubActionsNotifications
  10. // ==/UserScript==
  11.  
  12. const
  13. _username = document.querySelector('img[alt^="@"]').alt.slice(1),
  14. _lastActionStatus = {},
  15. getActions = () => [...document.querySelectorAll('[id^="check_suite"]')].map(el => {
  16. let status;
  17. const
  18. svgClassList = el.querySelector('svg').classList,
  19. titleLink = el.querySelector('a');
  20. if(svgClassList.contains('octicon-check-circle-fill'))
  21. status = 'success';
  22. if(svgClassList.contains('octicon-x-circle-fill'))
  23. status = 'failure';
  24. if(svgClassList.contains('octicon-stop'))
  25. status = 'aborted';
  26. if(svgClassList.contains('anim-rotate'))
  27. status = 'in progress';
  28. if(svgClassList.contains('octicon-dot-fill'))
  29. status = 'idle';
  30. return {
  31. id: parseInt(titleLink.href.split('/').slice(-1)[0]),
  32. title: titleLink.textContent,
  33. status,
  34. author: el.querySelector('a[data-hovercard-type]').textContent
  35. };
  36. });
  37.  
  38. getActions().forEach(action => _lastActionStatus[action.id] = action.status);
  39.  
  40. (new MutationObserver(() => getActions().forEach(action => {
  41. if(_lastActionStatus[action.id] !== action.status && action.author === _username) GM_notification({
  42. title: `GitHub Actions update (${action.id})`,
  43. text: `${action.title}\nStatus : ${action.status}`,
  44. image: 'https://git.kaki87.net/KaKi87/userscripts/raw/branch/master/GitHubActionsNotifications/assets/logo_github.png'
  45. });
  46. _lastActionStatus[action.id] = action.status;
  47. }))).observe(document.querySelector('#partial-actions-workflow-runs'), { childList: true });