Greasy Fork 还支持 简体中文。

GitHub My Issues

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

目前為 2020-11-30 提交的版本,檢視 最新版本

  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 1.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://cdn.jsdelivr.net/npm/cash-dom@8.1.0/dist/cash.min.js
  12. // @grant GM_log
  13. // @inject-into auto
  14. // ==/UserScript==
  15.  
  16. // value of the ID attribute for the "My Issues" link. used to identify an
  17. // existing link so it can be removed on pjax page loads
  18. const ID = 'my-issues'
  19.  
  20. // selector for the "Issues" link which we clone the "My Issues" link from and
  21. // append to
  22. const ISSUES = '[aria-label="Global"] a[href="/issues"]'
  23.  
  24. // text for the "My Issues" link
  25. const MY_ISSUES = 'My Issues'
  26.  
  27. // meta tag selector for the `<user>/<repo>` identifier on full pages
  28. const PAGE_REPO = 'octolytics-dimension-repository_nwo'
  29.  
  30. // meta tag selector for the `/<user>/<repo>` identifier on pjax pages
  31. const PJAX_REPO = '[data-pjax="#js-repo-pjax-container"]'
  32.  
  33. // meta tag selector for the name of the logged-in user
  34. const SELF = 'user-login'
  35.  
  36. // meta tag selector for the username on a profile page
  37. const USER = 'profile:username'
  38.  
  39. // helper function which extracts a value from a meta tag
  40. function meta (name, key = 'name') {
  41. const quotedName = JSON.stringify(name)
  42. return $(`meta[${key}=${quotedName}]`).attr('content')
  43. }
  44.  
  45. // add the "My Issues" link
  46. function run () {
  47. const self = meta(SELF)
  48. const $issues = $(ISSUES)
  49.  
  50. // if we're here via a pjax load, there may be an existing "My Issues" link
  51. // from a previous page load: remove it
  52. $(`#${ID}`).remove()
  53.  
  54. if (self && $issues.length === 1) {
  55. let path = '/issues', query = `involves:${self}`, prop
  56.  
  57. if (prop = meta(PAGE_REPO)) { // user/repo
  58. path = `/${prop}/issues`
  59. } else if (prop = $(PJAX_REPO).attr('href')) { // /user/repo
  60. path = `${prop}/issues`
  61. } else if (prop = meta(USER, 'property')) { // user
  62. if (prop === self) { // own homepage
  63. // user:<self> involves:<self> is:open archived:false
  64. query = [`user:${prop}`, query, 'is:open', 'archived:false']
  65. } else { // other user's homepage
  66. // user:<user> involves:<self>
  67. query = [`user:${prop}`, query]
  68. }
  69.  
  70. query = query.join('+')
  71. }
  72.  
  73. const href = `${path}?q=${escape(query)}`
  74. const $link = $issues.clone()
  75. .attr({ href, 'data-hotkey': 'g I', id: ID })
  76. .text(MY_ISSUES)
  77.  
  78. $issues.after($link)
  79. }
  80. }
  81.  
  82. $(document).on('pjax:end', run) // run on pjax page loads
  83. $(run) // run on full page loads