Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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;
})();
@jamesmstone
Copy link

jamesmstone commented Sep 8, 2022

you may be interested, I created this file hosted by github here https://read.jamesst.one/save

so I can use your bookmarklet with no server
ie just setting:

const requestURL = "https://read.jamesst.one/save ";

with my PAT

@codemicro
Copy link
Author

codemicro commented Sep 8, 2022

@jamesmstone
Copy link

jamesmstone commented Sep 8, 2022

ahh good catch - thanks

@ycouble
Copy link

ycouble commented Sep 14, 2022

Hey ! Thanks a lot to both of you for sharing !
I did build on both your codes, and added the possibility to add a rating to a reading, which I use through a folder of bookmarklets
Capture d’écran 2022-09-14 à 10 53 15

Code is here for those interested : https://github.com/ycouble/readingList

@codemicro
Copy link
Author

codemicro commented Sep 14, 2022

That's a super cool extension to it, thanks for sharing!

@jamesmstone
Copy link

jamesmstone commented Sep 14, 2022

the power of open source! 💪

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment