Github Pull Request From Link

Make pull request branches linkable

当前为 2017-01-07 提交的版本,查看 最新版本

  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 GNU GPLv3
  8. // @homepage https://github.com/jerone/UserScripts/tree/master/Github_Pull_Request_From
  9. // @homepageURL https://github.com/jerone/UserScripts/tree/master/Github_Pull_Request_From
  10. // @supportURL https://github.com/jerone/UserScripts/issues
  11. // @contributionURL https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=VCYMHWQ7ZMBKW
  12. // @version 17
  13. // @grant none
  14. // @include https://github.com/*/*
  15. // ==/UserScript==
  16.  
  17. (function() {
  18.  
  19. String.format = function(string) {
  20. var args = Array.prototype.slice.call(arguments, 1, arguments.length);
  21. return string.replace(/{(\d+)}/g, function(match, number) {
  22. return typeof args[number] !== "undefined" ? args[number] : match;
  23. });
  24. };
  25.  
  26. function init() {
  27. var repo = document.querySelector('.repohead-details-container h1 [itemprop="name"]').textContent,
  28. author = document.querySelector('.repohead-details-container h1 [itemprop="author"]').textContent;
  29. Array.prototype.filter.call(document.querySelectorAll("span.commit-ref"), function(treeSpan) {
  30. return !treeSpan.querySelector(".unknown-repo");
  31. }).forEach(function(treeSpan) {
  32. var treeUser = treeSpan.querySelector('.user');
  33. var treeParts = treeSpan.querySelectorAll('.css-truncate-target');
  34. var treeLink = document.createElement("a");
  35. Array.prototype.forEach.call(treeParts, function(part) {
  36. part.style.display = "inline";
  37. });
  38. treeLink.setAttribute("href", String.format("/{0}/{1}/tree/{2}",
  39. treeUser ? treeUser.textContent : author, // user;
  40. repo, // repository;
  41. escape(treeParts[treeParts.length - 1].textContent))); // branch;
  42. treeLink.innerHTML = treeSpan.innerHTML;
  43. treeSpan.innerHTML = "";
  44. treeSpan.appendChild(treeLink);
  45. });
  46. }
  47.  
  48. // Page load;
  49. init();
  50.  
  51. // On pjax;
  52. document.addEventListener('pjax:end', init);
  53.  
  54. })();

QingJ © 2025

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