Skip to content

Instantly share code, notes, and snippets.

@tianheg
Forked from codemicro/readingListBookmarklet.js
Last active September 9, 2022 03:28
Show Gist options
  • Select an option

  • Save tianheg/6635a0f7bd633a1cf02194e6aa2e68f6 to your computer and use it in GitHub Desktop.

Select an option

Save tianheg/6635a0f7bd633a1cf02194e6aa2e68f6 to your computer and use it in GitHub Desktop.

Revisions

  1. tianheg revised this gist Sep 9, 2022. 1 changed file with 57 additions and 51 deletions.
    108 changes: 57 additions & 51 deletions readingListBookmarklet.js
    Original file line number Diff line number Diff line change
    @@ -1,65 +1,71 @@
    javascript:(() => {
    const requestURL = "https://gh.tianheg.xyz/readingList/save";
    const token = ""; // Personal Access Token
    javascript: (() => {
    const requestURL = 'https://gh.tianheg.xyz/readingList/save';
    const token = ''; // Personal Access Token

    const pageTitle = document.title;
    const pageURL = window.location.href;
    let metaImage = "";
    let metaDescription = "";
    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];
    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;
    }
    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 === undefined) {
    continue;
    }

    if (metaName === propName) {
    return y.attributes.content.value;
    }
    }
    return undefined;
    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;
    }
    }
    {
    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;
    }
    {
    const img = getMetaValue('og:image');
    if (img !== undefined) {
    metaImage = img;
    }
    }

    console.log("BOOKMARKET PRESSED:", pageTitle, pageURL, metaDescription, metaImage);
    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);
    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;
    window.location.href = url;
    })();
  2. tianheg revised this gist Sep 9, 2022. No changes.
  3. tianheg revised this gist Sep 9, 2022. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion readingListBookmarklet.js
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    javascript:(() => {
    const requestURL = "https://gh.tianheg.xyz/readingList/save";
    const token = "dfgkjlhsdfgkljghklhj";
    const token = ""; // Personal Access Token

    const pageTitle = document.title;
    const pageURL = window.location.href;
  4. tianheg revised this gist Sep 9, 2022. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion readingListBookmarklet.js
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,5 @@
    javascript:(() => {
    const requestURL = "http://127.0.0.1:8080/api/readingList";
    const requestURL = "https://gh.tianheg.xyz/readingList/save";
    const token = "dfgkjlhsdfgkljghklhj";

    const pageTitle = document.title;
  5. @codemicro codemicro created this gist Sep 8, 2022.
    65 changes: 65 additions & 0 deletions readingListBookmarklet.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,65 @@
    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;
    })();