-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmd.js
executable file
·72 lines (61 loc) · 1.57 KB
/
md.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// set confirmation
var con = false;
// Set title
var tit = undefined;
var loc = undefined;
// Start by suggesting to add selected test
var select = window.getSelection().toString();
if (select) {
if (confirm("Use '" + select + "' as a title ? ")) {
tit = select;
}
}
// If still no title, try h1
if (tit === undefined) {
var titleq = document.querySelector("h1");
if (titleq && confirm("Use '" + titleq.innerText + "' as a title ? ")) {
tit = titleq.innerText;
}
}
// If still no title, try frist h2
if (tit === undefined) {
var titleq = document.querySelector("h2");
if (titleq && confirm("Use '" + titleq.innerText + "' as a title ? ")) {
tit = titleq.innerText;
}
}
// If still no title, prompt
if (tit === undefined) {
tit = prompt("Enter the title manually:");
}
// Suggest location with query params
var select = window.location.href.split('?')[0]
if (select) {
if (confirm("Use '" + select + "' as a url ? ")) {
loc = select;
}
}
// If not confirmed, try without split
var select = window.location.href
if (loc === undefined) {
if (confirm("Use '" + select + "' as a url ? ")) {
loc = select;
}
}
// If still no loc, prompt
if (loc === undefined) {
loc = prompt("Enter the url manually:");
}
liste = "";
if (confirm("Create a list entry?")) {
liste = "+ ";
}
var md = liste + "[" + tit + "](" + loc + ")";
if (confirm("Copy to clipboard?")) {
chrome.runtime.sendMessage({ md }, function(response) {
console.log(response);
});
alert("Copied!");
} else {
alert(md);
};