-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathbookmarklet.js
66 lines (56 loc) · 1.92 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
65
66
// TO USE: Replace the value of `token` with your value for `WEBSITE_READINGLIST_TOKEN`, then minify this script and set it as a bookmark.
javascript:(() => {
const requestURL = "http://127.0.0.1:8080/api/readingList";
const token = "dfgkjlhsdfgkljghklhj";
const pageTitle = document.title;
const pageURL = window.location.href;
let metaImage = "";
let metaDescription = "";
function getMetaValue(propName) {
const x = document.getElementsByTagName("meta");
for (let i = 0; i < x.length; i++) {
const y = x[i];
let metaName;
if (y.attributes.property !== undefined) {
metaName = y.attributes.property.value;
}
if (y.attributes.name !== undefined) {
metaName = y.attributes.name.value;
}
if (metaName === undefined) {
continue;
}
if (metaName === propName) {
return y.attributes.content.value;
}
}
return undefined;
}
{
let desc = getMetaValue("og:description");
if (desc !== undefined) {
metaDescription = desc;
} else {
desc = getMetaValue("description");
if (desc !== undefined) {
metaDescription = desc;
}
}
}
{
const img = getMetaValue("og:image");
if (img !== undefined) {
metaImage = img;
}
}
console.log("BOOKMARKET PRESSED:", pageTitle, pageURL, metaDescription, metaImage);
const url = new URL(requestURL);
const searchParams = url.searchParams;
searchParams.set("title", pageTitle);
searchParams.set("url", pageURL);
searchParams.set("description", metaDescription);
searchParams.set("image", metaImage);
searchParams.set("nexturl", pageURL);
searchParams.set("token", token);
window.location.href = url;
})();