-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathbookmarklet.js
64 lines (48 loc) · 1.72 KB
/
bookmarklet.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
(function(){
// Retrieve all highlights in the text
let highlightsList = document.getElementsByClassName('highlight');
let annotationIDList = [];
let clipsTextList = [];
for(i = 0; i < highlightsList.length; i++){
let annotationID = highlightsList[i].attributes['annotation_id'].nodeValue;
let clipText = highlightsList[i].lastChild.nodeValue.replace(/^\s+|\s+$/g, "");
if(!annotationIDList.includes(annotationID)){
annotationIDList.push(annotationID);
clipsTextList.push(clipText);
} else {
let index = annotationIDList.lastIndexOf(annotationID);
clipsTextList[index] = clipsTextList[index].concat(' '+clipText).split("\n").join(" ");
}
}
// Retrieve article metadata : Title, Original URL, Author
let title = document.title.replace("Pocket - ", "");
let originalURL = document.getElementById('reader.external-link.view-original');
if (typeof(originalURL) !== 'undefined'){
originalURL = originalURL.href;
} else {
originalURL = ""
}
let author = null;
try{
author = document.querySelector('header>h1+div div span').innerText;
} catch (e) {
author = "";
}
// Custom Formatting Output
for(i = 0; i < clipsTextList.length; i++){
clipsTextList[i] = clipsTextList[i].replace(/^\s+|\s+$/g, "");
}
let clips = clipsTextList.join("\n \t");
let content = `[${title}](${originalURL}) - [[Pocket2Roam]]
Written by:: ${author}
Pocket URL : ${location.href}
Summary::
[[Quotes]]
${clips}`
const tempTA = document.createElement("textarea");
document.body.appendChild(tempTA);
tempTA.value = content;
tempTA.select();
document.execCommand("copy");
alert("Highlights and metadata have been copied to the clipboard");
})()