Github notion task id detector

Detect notion task id from default name by git branch

  1. // ==UserScript==
  2. // @name Github notion task id detector
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.2
  5. // @description Detect notion task id from default name by git branch
  6. // @author Yes
  7. // @match https://github.com/*
  8. // @icon https://www.google.com/s2/favicons?sz=64&domain=github.com
  9. // @grant none
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14.  
  15. function getPrTitleEl() {
  16. return document.getElementById('pull_request_title')
  17. }
  18.  
  19. setInterval(function() {
  20. const prTitle = getPrTitleEl()
  21.  
  22. if (!prTitle) return
  23.  
  24. const prTitleText = prTitle.value
  25.  
  26. const match = prTitleText.match(/(Tas \d+?) (.*)/i)
  27. if (match) {
  28. let notionId = match[1].split(' ')
  29.  
  30. notionId = `[${notionId[0].toUpperCase()}-${notionId[1]}]`
  31.  
  32. prTitle.value = `${notionId} ${match[2]}`
  33. }
  34. }, 1000);
  35.  
  36. setInterval(function() {
  37. const prTitleHeader = document.getElementById('pull_request_title_header')
  38.  
  39. if (!prTitleHeader) return
  40.  
  41. if (prTitleHeader.querySelector('.add-prefix-btn')) return
  42.  
  43. const branch = document.getElementById('head-ref-selector')?.querySelector('.css-truncate')?.innerText
  44.  
  45. if (!branch) return
  46.  
  47. const match = branch.match(/tas-(\d+?)-/i)
  48.  
  49. if (match) {
  50. const addPrefixBtn = document.createElement("button");
  51. const prefix = `[TAS-${match[1]}]`
  52. addPrefixBtn.innerText = `Add ${prefix}`
  53. addPrefixBtn.setAttribute('type', 'button')
  54. addPrefixBtn.classList.value = 'add-prefix-btn Button Button--secondary Button--small'
  55. addPrefixBtn.style.marginLeft = '10px'
  56. addPrefixBtn.addEventListener('click', () => {
  57. const el = getPrTitleEl()
  58. el.value = `${prefix} ${el.value}`
  59. })
  60. prTitleHeader.appendChild(addPrefixBtn)
  61. }
  62. }, 1000);
  63. })();