GitHub My Issues

Add a link to issues you've contributed to on GitHub

目前为 2020-09-23 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name GitHub My Issues
  3. // @description Add a link to issues you've contributed to on GitHub
  4. // @author chocolateboy
  5. // @copyright chocolateboy
  6. // @version 0.1.1
  7. // @namespace https://github.com/chocolateboy/userscripts
  8. // @license GPL: http://www.gnu.org/copyleft/gpl.html
  9. // @include https://github.com/
  10. // @include https://github.com/*
  11. // @require https://code.jquery.com/jquery-3.5.1.slim.min.js
  12. // @require https://cdn.jsdelivr.net/gh/eclecto/jQuery-onMutate@79bbb2b8caccabfc9b9ade046fe63f15f593fef6/src/jquery.onmutate.min.js
  13. // @grant GM_log
  14. // @inject-into auto
  15. // ==/UserScript==
  16.  
  17. // XXX note: the unused grant is a workaround for a Greasemonkey bug:
  18. // https://github.com/greasemonkey/greasemonkey/issues/1614
  19.  
  20. const ID = 'my-issues'
  21. const meta = (name, key = 'name') => $(`meta[${key}=${JSON.stringify(name)}]`).attr('content')
  22.  
  23. function main (type) {
  24. const self = meta('user-login')
  25. const $issues = $('[aria-label="Global"] a[href="/issues"]')
  26.  
  27. // if we're here via a pjax load, there may be an existing "My Issues" link
  28. // from a previous page load: remove it
  29. $(`#${ID}`).remove()
  30.  
  31. // console.log(`XXX page (${type}):`, location.href)
  32.  
  33. if (self && $issues.length === 1) {
  34. let path = '/issues', query = `involves:${self}`, prop
  35.  
  36. if (prop = meta('octolytics-dimension-repository_nwo')) { // user/repo
  37. path = `/${prop}/issues`
  38. } else if (prop = $('[data-pjax="#js-repo-pjax-container"]').attr('href')) {
  39. path = `${prop}/issues`
  40. } else if (prop = meta('profile:username', 'property')) { // user
  41. query = [`user:${prop}`, query].join('+')
  42. }
  43.  
  44. const href = `${path}?q=${escape(query)}`
  45. const $link = $issues.clone()
  46. .attr({ href, 'data-hotkey': 'g I', id: ID })
  47. .text('My Issues')
  48.  
  49. $issues.after($link)
  50. }
  51. }
  52.  
  53. // navigation between pages on GitHub is a mixture of full page requests and
  54. // partial requests (pjax [1]). we detect the latter by detecting the
  55. // modification of the page's TITLE element.
  56. //
  57. // in the pjax case we need to take care not to keep adding "My Issues"
  58. // links.
  59. //
  60. // [1] https://github.com/defunkt/jquery-pjax
  61.  
  62. main('page')
  63. $('html > head > title').onText(() => main('pjax'), true /* multi */)