-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathorg-protocol-github-repo.user.js
34 lines (28 loc) · 1.03 KB
/
org-protocol-github-repo.user.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// ==UserScript==
// @name org-protocol-github-repo
// @description Insert Emacs links for files on github
// @author Raimon Grau Cusco <raimonster@gmail.com>
// @include https://github.com/*
// @version 0.1.0
// @grant none
// @license LGPL http://www.gnu.org/licenses/lgpl.html
// ==/UserScript==
var insertAfter = function(e,i){
if(e.nextSibling){
e.parentNode.insertBefore(i,e.nextSibling);
} else {
e.parentNode.appendChild(i);
}
};
var url = document.URL;
var project = document.URL.match(/github.com\/([^/]+\/[^/]+)/)[1];
var repoTitle = document.querySelectorAll("get-repo");
var mydiv = document.createElement("div");
mydiv.classList = "d-none d-md-flex ml-2";
var cloneLink = document.createElement("a");
cloneLink.classList = "btn btn-primary";
cloneLink.appendChild(document.createTextNode("Clone"));
cloneLink.href = "org-protocol://github-clone://" + project;
mydiv.appendChild(cloneLink);
var title = repoTitle[0].parentNode;
insertAfter(title, mydiv);