GitHub My Issues

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

当前为 2022-07-06 提交的版本,查看 最新版本

  1. "use strict";
  2.  
  3. // ==UserScript==
  4. // @name GitHub My Issues
  5. // @description Add a contextual link to issues you've contributed to on GitHub
  6. // @author chocolateboy
  7. // @copyright chocolateboy
  8. // @version 1.3.0
  9. // @namespace https://github.com/chocolateboy/userscripts
  10. // @license GPL
  11. // @include https://github.com/
  12. // @include https://github.com/*
  13. // @require https://cdn.jsdelivr.net/npm/cash-dom@8.1.1/dist/cash.min.js
  14. // @grant GM_log
  15. // ==/UserScript==
  16.  
  17. // NOTE This file is generated from src/github-my-issues.user.ts and should not be edited directly.
  18.  
  19. (() => {
  20. // src/github-my-issues.user.ts
  21. // @license GPL
  22. var ID = "my-issues";
  23. var ISSUES = '[aria-label="Global"] a[href="/issues"]';
  24. var MY_ISSUES = "My Issues";
  25. var PAGE_REPO = "octolytics-dimension-repository_nwo";
  26. var PJAX_REPO = '[data-pjax="#js-repo-pjax-container"]';
  27. var SELF = "user-login";
  28. var USER = "profile:username";
  29. function meta(name, key = "name") {
  30. const quotedName = JSON.stringify(name);
  31. return $(`meta[${key}=${quotedName}]`).attr("content");
  32. }
  33. function run() {
  34. $(`#${ID}`).remove();
  35. const self = meta(SELF);
  36. if (!self) {
  37. return;
  38. }
  39. const $issues = $(ISSUES);
  40. if ($issues.length !== 1) {
  41. return;
  42. }
  43. let subqueries = [`involves:${self}`, "sort:updated-desc"];
  44. let prop, path = "/issues";
  45. if (prop = meta(PAGE_REPO)) {
  46. path = `/${prop}/issues`;
  47. } else if (prop = $(PJAX_REPO).attr("href")) {
  48. path = `${prop}/issues`;
  49. } else if (prop = meta(USER, "property")) {
  50. if (prop === self) {
  51. subqueries = [`user:${prop}`, "is:open", "archived:false", ...subqueries];
  52. } else {
  53. subqueries = [`user:${prop}`, ...subqueries];
  54. }
  55. }
  56. const query = subqueries.join("+");
  57. const href = `${path}?q=${escape(query)}`;
  58. const $link = $issues.clone().attr({ href, "data-hotkey": "g I", id: ID }).text(MY_ISSUES);
  59. $issues.after($link);
  60. }
  61. $(document).on("turbo:load", run);
  62. })();