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.0
  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. // @run-at document-start
  15. // @inject-into auto
  16. // ==/UserScript==
  17.  
  18. // XXX note: the unused grant is a workaround for a Greasemonkey bug:
  19. // https://github.com/greasemonkey/greasemonkey/issues/1614
  20.  
  21. const ID = 'my-issues'
  22. const meta = (name, key = 'name') => $(`meta[${key}=${JSON.stringify(name)}]`).attr('content')
  23.  
  24. function main (type) {
  25. const self = meta('user-login')
  26. const $issues = $('[aria-label="Global"] a[href="/issues"]')
  27.  
  28. // if we're here via a pjax load, there may be an existing "My Issues" link
  29. // from a previous page load: remove it
  30. $(`#${ID}`).remove()
  31.  
  32. // console.warn(`XXX page (${type}):`, location.href)
  33.  
  34. if (self && $issues.length === 1) {
  35. let path = '/issues', query = `involves:${self}`, prop
  36.  
  37. if (prop = meta('octolytics-dimension-repository_nwo')) { // user/repo
  38. path = `/${prop}/issues`
  39. } else if (prop = $('[data-pjax="#js-repo-pjax-container"]').attr('href')?.slice(1)) {
  40. path = `/${prop}/issues`
  41. } else if (prop = meta('profile:username', 'property')) { // user
  42. query = [`user:${prop}`, query].join('+')
  43. }
  44.  
  45. const href = `${path}?q=${escape(query)}`
  46. const $link = $issues.clone()
  47. .attr({ href, 'data-hotkey': 'g I', id: ID })
  48. .text('My Issues')
  49.  
  50. $issues.after($link)
  51. }
  52. }
  53.  
  54. // navigation between pages on GitHub is a mixture of full page requests and
  55. // partial requests (pjax [1]). we detect the latter by detecting the
  56. // modification of the page's TITLE element.
  57. //
  58. // in the pjax case we need to take care not to keep adding "My Issues"
  59. // links.
  60. //
  61. // [1] https://github.com/defunkt/jquery-pjax
  62.  
  63. main('page')
  64. $('html > head > title').onText(() => main('pjax'), true /* multi */)

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址