Github Pull Request From Link

Make pull request branches linkable

当前为 2018-09-27 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Github Pull Request From Link
  3. // @namespace https://github.com/jerone/UserScripts/
  4. // @description Make pull request branches linkable
  5. // @author jerone
  6. // @copyright 2014+, jerone (http://jeroenvanwarmerdam.nl)
  7. // @license CC-BY-NC-SA-4.0; https://creativecommons.org/licenses/by-nc-sa/4.0/legalcode
  8. // @license GPL-3.0-or-later; http://www.gnu.org/licenses/gpl-3.0.txt
  9. // @homepage https://github.com/jerone/UserScripts/tree/master/Github_Pull_Request_From
  10. // @homepageURL https://github.com/jerone/UserScripts/tree/master/Github_Pull_Request_From
  11. // @supportURL https://github.com/jerone/UserScripts/issues
  12. // @contributionURL https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=VCYMHWQ7ZMBKW
  13. // @icon https://assets-cdn.github.com/pinned-octocat.svg
  14. // @version 19
  15. // @grant none
  16. // @include https://github.com/*/*
  17. // @exclude https://github.com/*/*.diff
  18. // @exclude https://github.com/*/*.patch
  19. // ==/UserScript==
  20.  
  21. (function() {
  22.  
  23. String.format = function(string) {
  24. var args = Array.prototype.slice.call(arguments, 1, arguments.length);
  25. return string.replace(/{(\d+)}/g, function(match, number) {
  26. return typeof args[number] !== "undefined" ? args[number] : match;
  27. });
  28. };
  29.  
  30. function init() {
  31. var repo = document.querySelector('.repohead-details-container h1 [itemprop="name"]').textContent,
  32. author = document.querySelector('.repohead-details-container h1 [itemprop="author"]').textContent;
  33. Array.prototype.filter.call(document.querySelectorAll("span.commit-ref"), function(treeSpan) {
  34. return !treeSpan.querySelector(".unknown-repo");
  35. }).forEach(function(treeSpan) {
  36. var treeUser = treeSpan.querySelector('.user');
  37. var treeParts = treeSpan.querySelectorAll('.css-truncate-target');
  38. var treeLink = document.createElement("a");
  39. Array.prototype.forEach.call(treeParts, function(part) {
  40. part.style.display = "inline";
  41. });
  42. treeLink.setAttribute("href", String.format("/{0}/{1}/tree/{2}",
  43. treeUser ? treeUser.textContent : author, // user
  44. repo, // repository
  45. escape(treeParts[treeParts.length - 1].textContent))); // branch
  46. treeLink.innerHTML = treeSpan.innerHTML;
  47. treeSpan.innerHTML = "";
  48. treeSpan.appendChild(treeLink);
  49. });
  50. }
  51.  
  52. // Page load.
  53. init();
  54.  
  55. // On pjax.
  56. document.addEventListener('pjax:end', init);
  57.  
  58. })();

QingJ © 2025

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