Github Pull Request From Link

Make pull request branches linkable

当前为 2015-09-11 提交的版本,查看 最新版本

  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 15
  13. // @grant none
  14. // @include https://github.com/*/*
  15. // ==/UserScript==
  16. /* global unsafeWindow */
  17.  
  18. (function(unsafeWindow) {
  19.  
  20. String.format = function(string) {
  21. var args = Array.prototype.slice.call(arguments, 1, arguments.length);
  22. return string.replace(/{(\d+)}/g, function(match, number) {
  23. return typeof args[number] !== "undefined" ? args[number] : match;
  24. });
  25. };
  26.  
  27. function init() {
  28. var repo = document.querySelector(".entry-title a[data-pjax]").textContent,
  29. author = document.querySelector('.entry-title .author').textContent;
  30. Array.prototype.filter.call(document.querySelectorAll("span.commit-ref"), function(treeSpan) {
  31. return !treeSpan.querySelector(".unknown-repo");
  32. }).forEach(function(treeSpan) {
  33. var treeUser = treeSpan.querySelector('.user');
  34. var treeParts = treeSpan.querySelectorAll('.css-truncate-target');
  35. var treeLink = document.createElement("a");
  36. treeLink.setAttribute("href", String.format("https://github.com/{0}/{1}/tree/{2}",
  37. treeUser ? treeUser.textContent : author, // user;
  38. repo, // repository;
  39. escape(treeParts[treeParts.length - 1].textContent))); // branch;
  40. treeLink.innerHTML = treeSpan.innerHTML;
  41. treeSpan.innerHTML = "";
  42. treeSpan.appendChild(treeLink);
  43. });
  44. }
  45.  
  46. // Page load;
  47. console.log('GithubPullRequestFromLink', 'page load');
  48. init();
  49.  
  50. // On pjax;
  51. unsafeWindow.$(document).on("pjax:end", function() {
  52. console.log('GithubPullRequestFromLink', 'pjax');
  53. init();
  54. });
  55.  
  56. })(typeof unsafeWindow !== "undefined" ? unsafeWindow : window);

QingJ © 2025

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