Github Pages Linker

Add a link to Github Pages (gh-pages) when available.

当前为 2019-04-24 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @id Github_Pages_Linker@https://github.com/jerone/UserScripts
  3. // @name Github Pages Linker
  4. // @namespace https://github.com/jerone/UserScripts/
  5. // @description Add a link to Github Pages (gh-pages) when available.
  6. // @author jerone
  7. // @copyright 2014+, jerone (http://jeroenvanwarmerdam.nl)
  8. // @license CC-BY-NC-SA-4.0; https://creativecommons.org/licenses/by-nc-sa/4.0/legalcode
  9. // @license GPL-3.0-or-later; http://www.gnu.org/licenses/gpl-3.0.txt
  10. // @homepage https://github.com/jerone/UserScripts/tree/master/Github_Pages_Linker
  11. // @homepageURL https://github.com/jerone/UserScripts/tree/master/Github_Pages_Linker
  12. // @supportURL https://github.com/jerone/UserScripts/issues
  13. // @contributionURL https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=VCYMHWQ7ZMBKW
  14. // @icon https://github.githubassets.com/pinned-octocat.svg
  15. // @version 1.2.3
  16. // @grant none
  17. // @run-at document-end
  18. // @include https://github.com/*
  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 addLink() {
  31. if(document.getElementById("GithubPagesLinker")) {
  32. return;
  33. }
  34.  
  35. var meta = document.querySelector(".repository-meta");
  36. if (!meta) {
  37. return;
  38. }
  39.  
  40. var branch = document.querySelector(".js-navigation-open[data-name='gh-pages']");
  41. if (!branch) {
  42. return;
  43. }
  44.  
  45. var tree = branch.getAttribute("href").split("/"); // `/{user}/{repo}/tree/gh-pages`;
  46. var url = String.format("https://{0}.github.io/{1}/", tree[1], tree[2]);
  47.  
  48. var div = document.createElement("div");
  49. div.id = "GithubPagesLinker";
  50. div.style.margin = "-10px 0px 10px";
  51. meta.parentNode.insertBefore(div, meta.nextSibling);
  52.  
  53. var img = document.createElement("img");
  54. img.setAttribute("src", "https://assets-cdn.github.com/images/icons/emoji/octocat.png");
  55. img.setAttribute("align", "absmiddle");
  56. img.classList.add("emoji");
  57. img.style.height = "16px";
  58. img.style.width = "16px";
  59. div.appendChild(img);
  60.  
  61. div.appendChild(document.createTextNode(" "));
  62.  
  63. var a = document.createElement("a");
  64. a.setAttribute("href", "https://pages.github.com");
  65. a.setAttribute("title", "More info about gh-pages...");
  66. a.style.color = "inherit";
  67. a.appendChild(document.createTextNode("Github Pages"));
  68. div.appendChild(a);
  69.  
  70. div.appendChild(document.createTextNode(": "));
  71.  
  72. var aa = document.createElement("a");
  73. aa.setAttribute("href", url);
  74. aa.appendChild(document.createTextNode(url));
  75. div.appendChild(aa);
  76. }
  77.  
  78. // Init;
  79. addLink();
  80.  
  81. // On pjax;
  82. document.addEventListener('pjax:end', addLink);
  83.  
  84. })();

QingJ © 2025

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