-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgithub-jsdelivr.user.js
More file actions
45 lines (39 loc) · 1.39 KB
/
github-jsdelivr.user.js
File metadata and controls
45 lines (39 loc) · 1.39 KB
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
35
36
37
38
39
40
41
42
43
44
45
// ==UserScript==
// @name Github jsDelivr Quick Link
// @namespace Github
// @author JustSong
// @match https://github.com/justsong-lab/images/*
// @version 0.1.0
// ==/UserScript==
(function () {
"use strict";
window.copyJsDelivrLink = function () {
let href = document.location.href.split("/");
let owner = href[3];
let repo = href[4];
let path = href.slice(7).join("/");
let jsDelivrLink = `https://cdn.jsdelivr.net/gh/${owner}/${repo}/${path}`;
window.copyText(jsDelivrLink);
};
window.copyText = function (text) {
const textArea = document.getElementById("hiddenTextArea");
textArea.textContent = text;
document.body.append(textArea);
textArea.select();
document.execCommand("copy");
};
function main() {
let hiddenTextArea = document.createElement("textarea");
hiddenTextArea.setAttribute("id", "hiddenTextArea");
hiddenTextArea.style.cssText = "height: 0px; width: 0px";
document.body.appendChild(hiddenTextArea);
const btn = `<button class="btn" id="copyJsDelivrBtn">Copy jsDelivr Link</button>`;
document
.querySelector("#blob-more-options-details")
.insertAdjacentHTML("beforeBegin", btn);
document
.getElementById("copyJsDelivrBtn")
.addEventListener("click", window.copyJsDelivrLink);
}
main();
})();