-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathminishare.js
25 lines (23 loc) · 921 Bytes
/
minishare.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
// Minishare extension, https://github.com/GiovanniSalmeri/yellow-minishare
"use strict";
document.addEventListener("DOMContentLoaded", function() {
var minishares = document.getElementsByClassName("minishare");
Array.from(minishares).forEach(function(minishare) {
var links = minishare.getElementsByTagName("a");
Array.from(links).forEach(function(link){
if ("prompt" in link.dataset) {
link.addEventListener("click", makeCustomUrl);
}
});
});
function makeCustomUrl(e) {
var promptLabel = e.target.dataset.prompt;
var instance = prompt(promptLabel);
if (instance===null || instance.trim()==="") {
e.preventDefault();
} else {
instance = instance.trim().replace(/^https?:\/\//, "");
e.target.href = e.target.href.replace("___instance___", instance);
}
}
});