|
14 | 14 | // @supportURL https://github.com/jerone/UserScripts/issues |
15 | 15 | // @contributionURL https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=VCYMHWQ7ZMBKW |
16 | 16 | // @icon https://github.githubassets.com/pinned-octocat.svg |
17 | | -// @version 1.2.3 |
| 17 | +// @version 1.2.4 |
18 | 18 | // @grant none |
19 | 19 | // @run-at document-end |
20 | 20 | // @include https://github.com/* |
|
28 | 28 | return typeof args[number] !== "undefined" ? args[number] : match; |
29 | 29 | }); |
30 | 30 | }; |
| 31 | + |
| 32 | + var DELAY = 800; |
31 | 33 |
|
32 | | - function addLink() { |
33 | | - if(document.getElementById("GithubPagesLinker")) { |
34 | | - return; |
35 | | - } |
36 | | - |
37 | | - var meta = document.querySelector(".repository-meta"); |
38 | | - if (!meta) { |
39 | | - return; |
40 | | - } |
41 | | - |
42 | | - var branch = document.querySelector(".js-navigation-open[data-name='gh-pages']"); |
43 | | - if (!branch) { |
44 | | - return; |
45 | | - } |
46 | | - |
47 | | - var tree = branch.getAttribute("href").split("/"); // `/{user}/{repo}/tree/gh-pages`; |
48 | | - var url = String.format("https://{0}.github.io/{1}/", tree[1], tree[2]); |
49 | | - |
50 | | - var div = document.createElement("div"); |
51 | | - div.id = "GithubPagesLinker"; |
52 | | - div.style.margin = "-10px 0px 10px"; |
53 | | - meta.parentNode.insertBefore(div, meta.nextSibling); |
54 | | - |
55 | | - var img = document.createElement("img"); |
56 | | - img.setAttribute("src", "https://assets-cdn.github.com/images/icons/emoji/octocat.png"); |
57 | | - img.setAttribute("align", "absmiddle"); |
58 | | - img.classList.add("emoji"); |
59 | | - img.style.height = "16px"; |
60 | | - img.style.width = "16px"; |
61 | | - div.appendChild(img); |
62 | | - |
63 | | - div.appendChild(document.createTextNode(" ")); |
64 | | - |
65 | | - var a = document.createElement("a"); |
66 | | - a.setAttribute("href", "https://pages.github.com"); |
67 | | - a.setAttribute("title", "More info about gh-pages..."); |
68 | | - a.style.color = "inherit"; |
69 | | - a.appendChild(document.createTextNode("Github Pages")); |
70 | | - div.appendChild(a); |
71 | | - |
72 | | - div.appendChild(document.createTextNode(": ")); |
73 | | - |
74 | | - var aa = document.createElement("a"); |
75 | | - aa.setAttribute("href", url); |
76 | | - aa.appendChild(document.createTextNode(url)); |
77 | | - div.appendChild(aa); |
| 34 | + var triggerEventClick = new MouseEvent('click', { |
| 35 | + view: window, |
| 36 | + bubbles: true, |
| 37 | + cancelable: true |
| 38 | + }); |
| 39 | + |
| 40 | + function addLink() { |
| 41 | + if(document.getElementById("GithubPagesLinker")) { |
| 42 | + return; |
| 43 | + } |
| 44 | + |
| 45 | + var meta = document.querySelector('.file-navigation'); |
| 46 | + if (!meta) { |
| 47 | + return; |
| 48 | + } |
| 49 | + |
| 50 | + var closeDropdown = () => { |
| 51 | + document.querySelector('[data-toggle-for="branch-select-menu"]').dispatchEvent(triggerEventClick); |
| 52 | + } |
| 53 | + |
| 54 | + var dropdown = document.querySelector('[data-hotkey="w"]'); |
| 55 | + dropdown.dispatchEvent(triggerEventClick); // open menu to load data |
| 56 | + |
| 57 | + setTimeout(() => { |
| 58 | + var branch = document.querySelector('.SelectMenu-item[href$="/tree/gh-pages"]'); |
| 59 | + if (!branch) { |
| 60 | + closeDropdown(); |
| 61 | + return; |
| 62 | + } |
| 63 | + |
| 64 | + var tree = branch.getAttribute("href").split("/"); // `/{user}/{repo}/tree/gh-pages`; |
| 65 | + var url = String.format("{0}//{1}.github.io/{2}/", tree[0], tree[3], tree[4]); |
| 66 | + |
| 67 | + var div = document.createElement("div"); |
| 68 | + div.id = "GithubPagesLinker"; |
| 69 | + div.style.margin = "-10px 0px 10px"; |
| 70 | + meta.parentNode.insertBefore(div, meta.nextSibling); |
| 71 | + |
| 72 | + var img = document.createElement("img"); |
| 73 | + img.setAttribute("src", "https://github.githubassets.com/images/icons/emoji/octocat.png"); |
| 74 | + img.setAttribute("align", "absmiddle"); |
| 75 | + img.classList.add("emoji"); |
| 76 | + img.style.height = "16px"; |
| 77 | + img.style.width = "16px"; |
| 78 | + div.appendChild(img); |
| 79 | + |
| 80 | + div.appendChild(document.createTextNode(" ")); |
| 81 | + |
| 82 | + var a = document.createElement("a"); |
| 83 | + a.setAttribute("href", "{https}://pages.github.com"); |
| 84 | + a.setAttribute("title", "More info about gh-pages..."); |
| 85 | + a.style.color = "inherit"; |
| 86 | + a.appendChild(document.createTextNode("Github Pages")); |
| 87 | + div.appendChild(a); |
| 88 | + |
| 89 | + div.appendChild(document.createTextNode(": ")); |
| 90 | + |
| 91 | + var aa = document.createElement("a"); |
| 92 | + aa.setAttribute("href", url); |
| 93 | + aa.appendChild(document.createTextNode(url)); |
| 94 | + div.appendChild(aa); |
| 95 | + |
| 96 | + closeDropdown(); |
| 97 | + |
| 98 | + }, DELAY); |
78 | 99 | } |
79 | 100 |
|
80 | 101 | // Init; |
81 | 102 | addLink(); |
82 | 103 |
|
83 | 104 | // On pjax; |
84 | | - document.addEventListener('pjax:end', addLink); |
| 105 | + document.addEventListener('pjax:end', addLink); |
85 | 106 |
|
86 | 107 | })(); |
0 commit comments