Skip to content

Instantly share code, notes, and snippets.

@zanshin
Forked from codemicro/readingListBookmarklet.js
Last active September 10, 2022 16:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zanshin/dd424594a5c67085e601d0e5d454e8ba to your computer and use it in GitHub Desktop.
Save zanshin/dd424594a5c67085e601d0e5d454e8ba to your computer and use it in GitHub Desktop.
javascript:(() => {
const requestURL = "https://zanshin.github.io/save";
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;
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment