Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save dustinmartin/ec611d8afb9079c058e5dbc927e3072d to your computer and use it in GitHub Desktop.
Save dustinmartin/ec611d8afb9079c058e5dbc927e3072d to your computer and use it in GitHub Desktop.

Revisions

  1. @kepano kepano revised this gist May 5, 2024. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion readme.md
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    By [@kepano](https://www.twitter.com/kepano)

    You can find a demo and more information [on my site](https://stephango.com/obsidian-web-clipper).
    [Visit my website](https://stephango.com/obsidian-web-clipper) to see a demo and find more information about this project.

    ### Installation
    Create a new bookmark in your browser, then copy/paste the minified code below into the URL field.
  2. @kepano kepano revised this gist May 5, 2024. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion readme.md
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    By [@kepano](https://www.twitter.com/kepano)

    You can find a demo and more information [on my site stephango.com](https://stephango.com/obsidian-web-clipper).
    You can find a demo and more information [on my site](https://stephango.com/obsidian-web-clipper).

    ### Installation
    Create a new bookmark in your browser, then copy/paste the minified code below into the URL field.
  3. @kepano kepano revised this gist May 5, 2024. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion readme.md
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    By [@kepano](https://www.twitter.com/kepano)

    You can find a demo and more information about this bookmarklet [on my site](https://stephango.com/obsidian-web-clipper)
    You can find a demo and more information [on my site stephango.com](https://stephango.com/obsidian-web-clipper).

    ### Installation
    Create a new bookmark in your browser, then copy/paste the minified code below into the URL field.
  4. @kepano kepano revised this gist May 5, 2024. 1 changed file with 1 addition and 4 deletions.
    5 changes: 1 addition & 4 deletions readme.md
    Original file line number Diff line number Diff line change
    @@ -1,9 +1,6 @@
    By [@kepano](https://www.twitter.com/kepano)

    🎉 Support my work at [buymeacoffee.com/kepano](https://www.buymeacoffee.com/kepano)

    ### Demo
    You can find a demo of this bookmarklet [on YouTube](https://www.youtube.com/watch?v=Vy1MdjickAI)
    You can find a demo and more information about this bookmarklet [on my site](https://stephango.com/obsidian-web-clipper)

    ### Installation
    Create a new bookmark in your browser, then copy/paste the minified code below into the URL field.
  5. @kepano kepano revised this gist Aug 10, 2023. 2 changed files with 13 additions and 17 deletions.
    28 changes: 12 additions & 16 deletions obsidian-web-clipper.js
    Original file line number Diff line number Diff line change
    @@ -97,24 +97,19 @@ javascript: Promise.all([import('https://unpkg.com/[email protected]?module'), impo

    const today = convertDate(date);

    /* Fetch the meta author */
    var metaAuthorElement = document.querySelector("meta[name='author']");
    var metaAuthor = metaAuthorElement ? metaAuthorElement.getAttribute("content") : "";

    /* Fetch site name as backup */
    var metaSiteNameElement = document.querySelector("meta[property='og:site_name']");
    var siteName = metaSiteNameElement ? metaSiteNameElement.getAttribute("content") : "";

    /* Check if there's an author and add brackets */
    var authorBrackets = "";
    if (byline && byline.trim() !== "") {
    authorBrackets = '"[[' + byline + ']]"';
    } else if (metaAuthor && metaAuthor.trim() !== "") {
    authorBrackets = '"[[' + metaAuthor + ']]"';
    } else if (siteName && siteName.trim() !== "") {
    authorBrackets = '"[[' + siteName + ']]"';
    // Utility function to get meta content by name or property
    function getMetaContent(attr, value) {
    var element = document.querySelector(`meta[${attr}='${value}']`);
    return element ? element.getAttribute("content").trim() : "";
    }

    // Fetch byline, meta author, property author, or site name
    var author = byline || getMetaContent("name", "author") || getMetaContent("property", "author") || getMetaContent("property", "og:site_name");

    // Check if there's an author and add brackets
    var authorBrackets = author ? `"[[${author}]]"` : "";


    /* Try to get published date */
    var timeElement = document.querySelector("time");
    var publishedDate = timeElement ? timeElement.getAttribute("datetime") : "";
    @@ -137,6 +132,7 @@ javascript: Promise.all([import('https://unpkg.com/[email protected]?module'), impo
    /* YAML front matter as tags render cleaner with special chars */
    const fileContent =
    '---\n'
    + 'category: "[[Clippings]]"\n'
    + 'author: ' + authorBrackets + '\n'
    + 'title: "' + title + '"\n'
    + 'source: ' + document.URL + '\n'
    2 changes: 1 addition & 1 deletion obsidian-web-clipper.min.js
    Original file line number Diff line number Diff line change
    @@ -1 +1 @@
    javascript:(function()%7Bjavascript%3A%20Promise.all(%5Bimport('https%3A%2F%2Funpkg.com%2Fturndown%406.0.0%3Fmodule')%2C%20import('https%3A%2F%2Funpkg.com%2F%40tehshrike%2Freadability%400.2.0')%2C%20%5D).then(async%20(%5B%7B%0A%20%20%20%20default%3A%20Turndown%0A%7D%2C%20%7B%0A%20%20%20%20default%3A%20Readability%0A%7D%5D)%20%3D%3E%20%7B%0A%0A%20%20%2F*%20Optional%20vault%20name%20*%2F%0A%20%20const%20vault%20%3D%20%22%22%3B%0A%0A%20%20%2F*%20Optional%20folder%20name%20such%20as%20%22Clippings%2F%22%20*%2F%0A%20%20const%20folder%20%3D%20%22Clippings%2F%22%3B%0A%0A%20%20%2F*%20Optional%20tags%20%20*%2F%0A%20%20let%20tags%20%3D%20%22clippings%22%3B%0A%0A%20%20%2F*%20Parse%20the%20site's%20meta%20keywords%20content%20into%20tags%2C%20if%20present%20*%2F%0A%20%20if%20(document.querySelector('meta%5Bname%3D%22keywords%22%20i%5D'))%20%7B%0A%20%20%20%20%20%20var%20keywords%20%3D%20document.querySelector('meta%5Bname%3D%22keywords%22%20i%5D').getAttribute('content').split('%2C')%3B%0A%0A%20%20%20%20%20%20keywords.forEach(function(keyword)%20%7B%0A%20%20%20%20%20%20%20%20%20%20let%20tag%20%3D%20'%20'%20%2B%20keyword.split('%20').join('')%3B%0A%20%20%20%20%20%20%20%20%20%20tags%20%2B%3D%20tag%3B%0A%20%20%20%20%20%20%7D)%3B%0A%20%20%7D%0A%0A%20%20function%20getSelectionHtml()%20%7B%0A%20%20%20%20var%20html%20%3D%20%22%22%3B%0A%20%20%20%20if%20(typeof%20window.getSelection%20!%3D%20%22undefined%22)%20%7B%0A%20%20%20%20%20%20%20%20var%20sel%20%3D%20window.getSelection()%3B%0A%20%20%20%20%20%20%20%20if%20(sel.rangeCount)%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20var%20container%20%3D%20document.createElement(%22div%22)%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20for%20(var%20i%20%3D%200%2C%20len%20%3D%20sel.rangeCount%3B%20i%20%3C%20len%3B%20%2B%2Bi)%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20container.appendChild(sel.getRangeAt(i).cloneContents())%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%20%20%20%20html%20%3D%20container.innerHTML%3B%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%7D%20else%20if%20(typeof%20document.selection%20!%3D%20%22undefined%22)%20%7B%0A%20%20%20%20%20%20%20%20if%20(document.selection.type%20%3D%3D%20%22Text%22)%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20html%20%3D%20document.selection.createRange().htmlText%3B%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%7D%0A%20%20%20%20return%20html%3B%0A%20%20%7D%0A%0A%20%20const%20selection%20%3D%20getSelectionHtml()%3B%0A%0A%20%20const%20%7B%0A%20%20%20%20%20%20title%2C%0A%20%20%20%20%20%20byline%2C%0A%20%20%20%20%20%20content%0A%20%20%7D%20%3D%20new%20Readability(document.cloneNode(true)).parse()%3B%0A%0A%20%20function%20getFileName(fileName)%20%7B%0A%20%20%20%20var%20userAgent%20%3D%20window.navigator.userAgent%2C%0A%20%20%20%20%20%20%20%20platform%20%3D%20window.navigator.platform%2C%0A%20%20%20%20%20%20%20%20windowsPlatforms%20%3D%20%5B'Win32'%2C%20'Win64'%2C%20'Windows'%2C%20'WinCE'%5D%3B%0A%0A%20%20%20%20if%20(windowsPlatforms.indexOf(platform)%20!%3D%3D%20-1)%20%7B%0A%20%20%20%20%20%20fileName%20%3D%20fileName.replace('%3A'%2C%20'').replace(%2F%5B%2F%5C%5C%3F%25*%7C%22%3C%3E%5D%2Fg%2C%20'-')%3B%0A%20%20%20%20%7D%20else%20%7B%0A%20%20%20%20%20%20fileName%20%3D%20fileName.replace('%3A'%2C%20'').replace(%2F%5C%2F%2Fg%2C%20'-').replace(%2F%5C%5C%2Fg%2C%20'-')%3B%0A%20%20%20%20%7D%0A%20%20%20%20return%20fileName%3B%0A%20%20%7D%0A%20%20const%20fileName%20%3D%20getFileName(title)%3B%0A%0A%20%20if%20(selection)%20%7B%0A%20%20%20%20%20%20var%20markdownify%20%3D%20selection%3B%0A%20%20%7D%20else%20%7B%0A%20%20%20%20%20%20var%20markdownify%20%3D%20content%3B%0A%20%20%7D%0A%0A%20%20if%20(vault)%20%7B%0A%20%20%20%20%20%20var%20vaultName%20%3D%20'%26vault%3D'%20%2B%20encodeURIComponent(%60%24%7Bvault%7D%60)%3B%0A%20%20%7D%20else%20%7B%0A%20%20%20%20%20%20var%20vaultName%20%3D%20''%3B%0A%20%20%7D%0A%0A%20%20const%20markdownBody%20%3D%20new%20Turndown(%7B%0A%20%20%20%20%20%20headingStyle%3A%20'atx'%2C%0A%20%20%20%20%20%20hr%3A%20'---'%2C%0A%20%20%20%20%20%20bulletListMarker%3A%20'-'%2C%0A%20%20%20%20%20%20codeBlockStyle%3A%20'fenced'%2C%0A%20%20%20%20%20%20emDelimiter%3A%20'*'%2C%0A%20%20%7D).turndown(markdownify)%3B%0A%0A%20%20var%20date%20%3D%20new%20Date()%3B%0A%0A%20%20function%20convertDate(date)%20%7B%0A%20%20%20%20var%20yyyy%20%3D%20date.getFullYear().toString()%3B%0A%20%20%20%20var%20mm%20%3D%20(date.getMonth()%2B1).toString()%3B%0A%20%20%20%20var%20dd%20%20%3D%20date.getDate().toString()%3B%0A%20%20%20%20var%20mmChars%20%3D%20mm.split('')%3B%0A%20%20%20%20var%20ddChars%20%3D%20dd.split('')%3B%0A%20%20%20%20return%20yyyy%20%2B%20'-'%20%2B%20(mmChars%5B1%5D%3Fmm%3A%220%22%2BmmChars%5B0%5D)%20%2B%20'-'%20%2B%20(ddChars%5B1%5D%3Fdd%3A%220%22%2BddChars%5B0%5D)%3B%0A%20%20%7D%0A%0A%20%20const%20today%20%3D%20convertDate(date)%3B%0A%0A%20%20%2F*%20Fetch%20the%20meta%20author%20*%2F%0A%20%20var%20metaAuthorElement%20%3D%20document.querySelector(%22meta%5Bname%3D'author'%5D%22)%3B%0A%20%20var%20metaAuthor%20%3D%20metaAuthorElement%20%3F%20metaAuthorElement.getAttribute(%22content%22)%20%3A%20%22%22%3B%0A%0A%20%20%2F*%20Fetch%20site%20name%20as%20backup%20*%2F%0A%20%20var%20metaSiteNameElement%20%3D%20document.querySelector(%22meta%5Bproperty%3D'og%3Asite_name'%5D%22)%3B%0A%20%20var%20siteName%20%3D%20metaSiteNameElement%20%3F%20metaSiteNameElement.getAttribute(%22content%22)%20%3A%20%22%22%3B%0A%0A%20%20%2F*%20Check%20if%20there's%20an%20author%20and%20add%20brackets%20*%2F%0A%20%20var%20authorBrackets%20%3D%20%22%22%3B%0A%20%20if%20(byline%20%26%26%20byline.trim()%20!%3D%3D%20%22%22)%20%7B%0A%20%20%20%20%20%20authorBrackets%20%3D%20'%22%5B%5B'%20%2B%20byline%20%2B%20'%5D%5D%22'%3B%0A%20%20%7D%20else%20if%20(metaAuthor%20%26%26%20metaAuthor.trim()%20!%3D%3D%20%22%22)%20%7B%0A%20%20%20%20%20%20authorBrackets%20%3D%20'%22%5B%5B'%20%2B%20metaAuthor%20%2B%20'%5D%5D%22'%3B%0A%20%20%7D%20else%20if%20(siteName%20%26%26%20siteName.trim()%20!%3D%3D%20%22%22)%20%7B%0A%20%20%20%20%20%20authorBrackets%20%3D%20'%22%5B%5B'%20%2B%20siteName%20%2B%20'%5D%5D%22'%3B%0A%20%20%7D%0A%0A%20%20%2F*%20Try%20to%20get%20published%20date%20*%2F%0A%20%20var%20timeElement%20%3D%20document.querySelector(%22time%22)%3B%0A%20%20var%20publishedDate%20%3D%20timeElement%20%3F%20timeElement.getAttribute(%22datetime%22)%20%3A%20%22%22%3B%0A%0A%20%20if%20(publishedDate%20%26%26%20publishedDate.trim()%20!%3D%3D%20%22%22)%20%7B%0A%20%20%20%20%20%20var%20date%20%3D%20new%20Date(publishedDate)%3B%0A%20%20%20%20%20%20var%20year%20%3D%20date.getFullYear()%3B%0A%20%20%20%20%20%20var%20month%20%3D%20date.getMonth()%20%2B%201%3B%20%2F%2F%20Months%20are%200-based%20in%20JavaScript%0A%20%20%20%20%20%20var%20day%20%3D%20date.getDate()%3B%0A%0A%20%20%20%20%20%20%2F%2F%20Pad%20month%20and%20day%20with%20leading%20zeros%20if%20necessary%0A%20%20%20%20%20%20month%20%3D%20month%20%3C%2010%20%3F%20'0'%20%2B%20month%20%3A%20month%3B%0A%20%20%20%20%20%20day%20%3D%20day%20%3C%2010%20%3F%20'0'%20%2B%20day%20%3A%20day%3B%0A%0A%20%20%20%20%20%20var%20published%20%3D%20year%20%2B%20'-'%20%2B%20month%20%2B%20'-'%20%2B%20day%3B%0A%20%20%7D%20else%20%7B%0A%20%20%20%20%20%20var%20published%20%3D%20''%0A%20%20%7D%0A%0A%20%20%2F*%20YAML%20front%20matter%20as%20tags%20render%20cleaner%20with%20special%20chars%20%20*%2F%0A%20%20const%20fileContent%20%3D%20%0A%20%20%20%20%20%20'---%5Cn'%0A%20%20%20%20%20%20%2B%20'author%3A%20'%20%2B%20authorBrackets%20%2B%20'%5Cn'%0A%20%20%20%20%20%20%2B%20'title%3A%20%22'%20%2B%20title%20%2B%20'%22%5Cn'%0A%20%20%20%20%20%20%2B%20'source%3A%20'%20%2B%20document.URL%20%2B%20'%5Cn'%0A%20%20%20%20%20%20%2B%20'clipped%3A%20'%20%2B%20today%20%2B%20'%5Cn'%0A%20%20%20%20%20%20%2B%20'published%3A%20'%20%2B%20published%20%2B%20'%5Cn'%20%0A%20%20%20%20%20%20%2B%20'topics%3A%20%5Cn'%0A%20%20%20%20%20%20%2B%20'tags%3A%20%5B'%20%2B%20tags%20%2B%20'%5D%5Cn'%0A%20%20%20%20%20%20%2B%20'---%5Cn%5Cn'%0A%20%20%20%20%20%20%2B%20markdownBody%20%3B%0A%0A%20%20%20document.location.href%20%3D%20%22obsidian%3A%2F%2Fnew%3F%22%0A%20%20%20%20%2B%20%22file%3D%22%20%2B%20encodeURIComponent(folder%20%2B%20fileName)%0A%20%20%20%20%2B%20%22%26content%3D%22%20%2B%20encodeURIComponent(fileContent)%0A%20%20%20%20%2B%20vaultName%20%3B%0A%0A%7D)%7D)()%3B
    javascript:(function()%7Bjavascript%3A%20Promise.all(%5Bimport('https%3A%2F%2Funpkg.com%2Fturndown%406.0.0%3Fmodule')%2C%20import('https%3A%2F%2Funpkg.com%2F%40tehshrike%2Freadability%400.2.0')%2C%20%5D).then(async%20(%5B%7B%0A%20%20%20%20default%3A%20Turndown%0A%7D%2C%20%7B%0A%20%20%20%20default%3A%20Readability%0A%7D%5D)%20%3D%3E%20%7B%0A%0A%20%20%2F*%20Optional%20vault%20name%20*%2F%0A%20%20const%20vault%20%3D%20%22%22%3B%0A%0A%20%20%2F*%20Optional%20folder%20name%20such%20as%20%22Clippings%2F%22%20*%2F%0A%20%20const%20folder%20%3D%20%22Clippings%2F%22%3B%0A%0A%20%20%2F*%20Optional%20tags%20%20*%2F%0A%20%20let%20tags%20%3D%20%22clippings%22%3B%0A%0A%20%20%2F*%20Parse%20the%20site's%20meta%20keywords%20content%20into%20tags%2C%20if%20present%20*%2F%0A%20%20if%20(document.querySelector('meta%5Bname%3D%22keywords%22%20i%5D'))%20%7B%0A%20%20%20%20%20%20var%20keywords%20%3D%20document.querySelector('meta%5Bname%3D%22keywords%22%20i%5D').getAttribute('content').split('%2C')%3B%0A%0A%20%20%20%20%20%20keywords.forEach(function(keyword)%20%7B%0A%20%20%20%20%20%20%20%20%20%20let%20tag%20%3D%20'%20'%20%2B%20keyword.split('%20').join('')%3B%0A%20%20%20%20%20%20%20%20%20%20tags%20%2B%3D%20tag%3B%0A%20%20%20%20%20%20%7D)%3B%0A%20%20%7D%0A%0A%20%20function%20getSelectionHtml()%20%7B%0A%20%20%20%20var%20html%20%3D%20%22%22%3B%0A%20%20%20%20if%20(typeof%20window.getSelection%20!%3D%20%22undefined%22)%20%7B%0A%20%20%20%20%20%20%20%20var%20sel%20%3D%20window.getSelection()%3B%0A%20%20%20%20%20%20%20%20if%20(sel.rangeCount)%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20var%20container%20%3D%20document.createElement(%22div%22)%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20for%20(var%20i%20%3D%200%2C%20len%20%3D%20sel.rangeCount%3B%20i%20%3C%20len%3B%20%2B%2Bi)%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20container.appendChild(sel.getRangeAt(i).cloneContents())%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%20%20%20%20html%20%3D%20container.innerHTML%3B%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%7D%20else%20if%20(typeof%20document.selection%20!%3D%20%22undefined%22)%20%7B%0A%20%20%20%20%20%20%20%20if%20(document.selection.type%20%3D%3D%20%22Text%22)%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20html%20%3D%20document.selection.createRange().htmlText%3B%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%7D%0A%20%20%20%20return%20html%3B%0A%20%20%7D%0A%0A%20%20const%20selection%20%3D%20getSelectionHtml()%3B%0A%0A%20%20const%20%7B%0A%20%20%20%20%20%20title%2C%0A%20%20%20%20%20%20byline%2C%0A%20%20%20%20%20%20content%0A%20%20%7D%20%3D%20new%20Readability(document.cloneNode(true)).parse()%3B%0A%0A%20%20function%20getFileName(fileName)%20%7B%0A%20%20%20%20var%20userAgent%20%3D%20window.navigator.userAgent%2C%0A%20%20%20%20%20%20%20%20platform%20%3D%20window.navigator.platform%2C%0A%20%20%20%20%20%20%20%20windowsPlatforms%20%3D%20%5B'Win32'%2C%20'Win64'%2C%20'Windows'%2C%20'WinCE'%5D%3B%0A%0A%20%20%20%20if%20(windowsPlatforms.indexOf(platform)%20!%3D%3D%20-1)%20%7B%0A%20%20%20%20%20%20fileName%20%3D%20fileName.replace('%3A'%2C%20'').replace(%2F%5B%2F%5C%5C%3F%25*%7C%22%3C%3E%5D%2Fg%2C%20'-')%3B%0A%20%20%20%20%7D%20else%20%7B%0A%20%20%20%20%20%20fileName%20%3D%20fileName.replace('%3A'%2C%20'').replace(%2F%5C%2F%2Fg%2C%20'-').replace(%2F%5C%5C%2Fg%2C%20'-')%3B%0A%20%20%20%20%7D%0A%20%20%20%20return%20fileName%3B%0A%20%20%7D%0A%20%20const%20fileName%20%3D%20getFileName(title)%3B%0A%0A%20%20if%20(selection)%20%7B%0A%20%20%20%20%20%20var%20markdownify%20%3D%20selection%3B%0A%20%20%7D%20else%20%7B%0A%20%20%20%20%20%20var%20markdownify%20%3D%20content%3B%0A%20%20%7D%0A%0A%20%20if%20(vault)%20%7B%0A%20%20%20%20%20%20var%20vaultName%20%3D%20'%26vault%3D'%20%2B%20encodeURIComponent(%60%24%7Bvault%7D%60)%3B%0A%20%20%7D%20else%20%7B%0A%20%20%20%20%20%20var%20vaultName%20%3D%20''%3B%0A%20%20%7D%0A%0A%20%20const%20markdownBody%20%3D%20new%20Turndown(%7B%0A%20%20%20%20%20%20headingStyle%3A%20'atx'%2C%0A%20%20%20%20%20%20hr%3A%20'---'%2C%0A%20%20%20%20%20%20bulletListMarker%3A%20'-'%2C%0A%20%20%20%20%20%20codeBlockStyle%3A%20'fenced'%2C%0A%20%20%20%20%20%20emDelimiter%3A%20'*'%2C%0A%20%20%7D).turndown(markdownify)%3B%0A%0A%20%20var%20date%20%3D%20new%20Date()%3B%0A%0A%20%20function%20convertDate(date)%20%7B%0A%20%20%20%20var%20yyyy%20%3D%20date.getFullYear().toString()%3B%0A%20%20%20%20var%20mm%20%3D%20(date.getMonth()%2B1).toString()%3B%0A%20%20%20%20var%20dd%20%20%3D%20date.getDate().toString()%3B%0A%20%20%20%20var%20mmChars%20%3D%20mm.split('')%3B%0A%20%20%20%20var%20ddChars%20%3D%20dd.split('')%3B%0A%20%20%20%20return%20yyyy%20%2B%20'-'%20%2B%20(mmChars%5B1%5D%3Fmm%3A%220%22%2BmmChars%5B0%5D)%20%2B%20'-'%20%2B%20(ddChars%5B1%5D%3Fdd%3A%220%22%2BddChars%5B0%5D)%3B%0A%20%20%7D%0A%0A%20%20const%20today%20%3D%20convertDate(date)%3B%0A%0A%20%20%2F%2F%20Utility%20function%20to%20get%20meta%20content%20by%20name%20or%20property%0A%20%20function%20getMetaContent(attr%2C%20value)%20%7B%0A%20%20%20%20%20%20var%20element%20%3D%20document.querySelector(%60meta%5B%24%7Battr%7D%3D'%24%7Bvalue%7D'%5D%60)%3B%0A%20%20%20%20%20%20return%20element%20%3F%20element.getAttribute(%22content%22).trim()%20%3A%20%22%22%3B%0A%20%20%7D%0A%0A%20%20%2F%2F%20Fetch%20byline%2C%20meta%20author%2C%20property%20author%2C%20or%20site%20name%0A%20%20var%20author%20%3D%20byline%20%7C%7C%20getMetaContent(%22name%22%2C%20%22author%22)%20%7C%7C%20getMetaContent(%22property%22%2C%20%22author%22)%20%7C%7C%20getMetaContent(%22property%22%2C%20%22og%3Asite_name%22)%3B%0A%0A%20%20%2F%2F%20Check%20if%20there's%20an%20author%20and%20add%20brackets%0A%20%20var%20authorBrackets%20%3D%20author%20%3F%20%60%22%5B%5B%24%7Bauthor%7D%5D%5D%22%60%20%3A%20%22%22%3B%0A%0A%0A%20%20%2F*%20Try%20to%20get%20published%20date%20*%2F%0A%20%20var%20timeElement%20%3D%20document.querySelector(%22time%22)%3B%0A%20%20var%20publishedDate%20%3D%20timeElement%20%3F%20timeElement.getAttribute(%22datetime%22)%20%3A%20%22%22%3B%0A%0A%20%20if%20(publishedDate%20%26%26%20publishedDate.trim()%20!%3D%3D%20%22%22)%20%7B%0A%20%20%20%20%20%20var%20date%20%3D%20new%20Date(publishedDate)%3B%0A%20%20%20%20%20%20var%20year%20%3D%20date.getFullYear()%3B%0A%20%20%20%20%20%20var%20month%20%3D%20date.getMonth()%20%2B%201%3B%20%2F%2F%20Months%20are%200-based%20in%20JavaScript%0A%20%20%20%20%20%20var%20day%20%3D%20date.getDate()%3B%0A%0A%20%20%20%20%20%20%2F%2F%20Pad%20month%20and%20day%20with%20leading%20zeros%20if%20necessary%0A%20%20%20%20%20%20month%20%3D%20month%20%3C%2010%20%3F%20'0'%20%2B%20month%20%3A%20month%3B%0A%20%20%20%20%20%20day%20%3D%20day%20%3C%2010%20%3F%20'0'%20%2B%20day%20%3A%20day%3B%0A%0A%20%20%20%20%20%20var%20published%20%3D%20year%20%2B%20'-'%20%2B%20month%20%2B%20'-'%20%2B%20day%3B%0A%20%20%7D%20else%20%7B%0A%20%20%20%20%20%20var%20published%20%3D%20''%0A%20%20%7D%0A%0A%20%20%2F*%20YAML%20front%20matter%20as%20tags%20render%20cleaner%20with%20special%20chars%20%20*%2F%0A%20%20const%20fileContent%20%3D%20%0A%20%20%20%20%20%20'---%5Cn'%0A%20%20%20%20%20%20%2B%20'category%3A%20%22%5B%5BClippings%5D%5D%22%5Cn'%0A%20%20%20%20%20%20%2B%20'author%3A%20'%20%2B%20authorBrackets%20%2B%20'%5Cn'%0A%20%20%20%20%20%20%2B%20'title%3A%20%22'%20%2B%20title%20%2B%20'%22%5Cn'%0A%20%20%20%20%20%20%2B%20'source%3A%20'%20%2B%20document.URL%20%2B%20'%5Cn'%0A%20%20%20%20%20%20%2B%20'clipped%3A%20'%20%2B%20today%20%2B%20'%5Cn'%0A%20%20%20%20%20%20%2B%20'published%3A%20'%20%2B%20published%20%2B%20'%5Cn'%20%0A%20%20%20%20%20%20%2B%20'topics%3A%20%5Cn'%0A%20%20%20%20%20%20%2B%20'tags%3A%20%5B'%20%2B%20tags%20%2B%20'%5D%5Cn'%0A%20%20%20%20%20%20%2B%20'---%5Cn%5Cn'%0A%20%20%20%20%20%20%2B%20markdownBody%20%3B%0A%0A%20%20%20document.location.href%20%3D%20%22obsidian%3A%2F%2Fnew%3F%22%0A%20%20%20%20%2B%20%22file%3D%22%20%2B%20encodeURIComponent(folder%20%2B%20fileName)%0A%20%20%20%20%2B%20%22%26content%3D%22%20%2B%20encodeURIComponent(fileContent)%0A%20%20%20%20%2B%20vaultName%20%3B%0A%0A%7D)%7D)()%3B
  6. @kepano kepano revised this gist Jul 29, 2023. 2 changed files with 7 additions and 16 deletions.
    21 changes: 6 additions & 15 deletions obsidian-web-clipper.js
    Original file line number Diff line number Diff line change
    @@ -8,7 +8,7 @@ javascript: Promise.all([import('https://unpkg.com/[email protected]?module'), impo
    const vault = "";

    /* Optional folder name such as "Clippings/" */
    const folder = "";
    const folder = "Clippings/";

    /* Optional tags */
    let tags = "clippings";
    @@ -142,23 +142,14 @@ javascript: Promise.all([import('https://unpkg.com/[email protected]?module'), impo
    + 'source: ' + document.URL + '\n'
    + 'clipped: ' + today + '\n'
    + 'published: ' + published + '\n'
    + 'topics: \n'
    + 'tags: [' + tags + ']\n'
    + '---\n\n'
    + markdownBody ;

    /* assemble URL, decrementing each time, until it does not exceed the max URL length for this browser, supposedly 2048 but allow for a little error with 2030 */
    contentLength = 2048;
    maxURLLength = 2030;
    decrement = 1;

    do {
    hrefString = 'obsidian://new?'
    + 'file=' + encodeURIComponent(folder + fileName)
    + '&content=' + encodeURIComponent(fileContent.substr(0,contentLength-1))
    + vaultName ;
    contentLength = contentLength - decrement;
    } while (hrefString.length > maxURLLength);

    document.location.href = hrefString;
    document.location.href = "obsidian://new?"
    + "file=" + encodeURIComponent(folder + fileName)
    + "&content=" + encodeURIComponent(fileContent)
    + vaultName ;

    })
    2 changes: 1 addition & 1 deletion obsidian-web-clipper.min.js
    Original file line number Diff line number Diff line change
    @@ -1 +1 @@
    javascript:(function()%7Bjavascript%3A%20Promise.all(%5Bimport('https%3A%2F%2Funpkg.com%2Fturndown%406.0.0%3Fmodule')%2C%20import('https%3A%2F%2Funpkg.com%2F%40tehshrike%2Freadability%400.2.0')%2C%20%5D).then(async%20(%5B%7B%0A%20%20%20%20default%3A%20Turndown%0A%7D%2C%20%7B%0A%20%20%20%20default%3A%20Readability%0A%7D%5D)%20%3D%3E%20%7B%0A%0A%20%20%2F*%20Optional%20vault%20name%20*%2F%0A%20%20const%20vault%20%3D%20%22%22%3B%0A%0A%20%20%2F*%20Optional%20folder%20name%20such%20as%20%22Clippings%2F%22%20*%2F%0A%20%20const%20folder%20%3D%20%22%22%3B%0A%0A%20%20%2F*%20Optional%20tags%20%20*%2F%0A%20%20let%20tags%20%3D%20%22clippings%22%3B%0A%0A%20%20%2F*%20Parse%20the%20site's%20meta%20keywords%20content%20into%20tags%2C%20if%20present%20*%2F%0A%20%20if%20(document.querySelector('meta%5Bname%3D%22keywords%22%20i%5D'))%20%7B%0A%20%20%20%20%20%20var%20keywords%20%3D%20document.querySelector('meta%5Bname%3D%22keywords%22%20i%5D').getAttribute('content').split('%2C')%3B%0A%0A%20%20%20%20%20%20keywords.forEach(function(keyword)%20%7B%0A%20%20%20%20%20%20%20%20%20%20let%20tag%20%3D%20'%20'%20%2B%20keyword.split('%20').join('')%3B%0A%20%20%20%20%20%20%20%20%20%20tags%20%2B%3D%20tag%3B%0A%20%20%20%20%20%20%7D)%3B%0A%20%20%7D%0A%0A%20%20function%20getSelectionHtml()%20%7B%0A%20%20%20%20var%20html%20%3D%20%22%22%3B%0A%20%20%20%20if%20(typeof%20window.getSelection%20!%3D%20%22undefined%22)%20%7B%0A%20%20%20%20%20%20%20%20var%20sel%20%3D%20window.getSelection()%3B%0A%20%20%20%20%20%20%20%20if%20(sel.rangeCount)%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20var%20container%20%3D%20document.createElement(%22div%22)%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20for%20(var%20i%20%3D%200%2C%20len%20%3D%20sel.rangeCount%3B%20i%20%3C%20len%3B%20%2B%2Bi)%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20container.appendChild(sel.getRangeAt(i).cloneContents())%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%20%20%20%20html%20%3D%20container.innerHTML%3B%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%7D%20else%20if%20(typeof%20document.selection%20!%3D%20%22undefined%22)%20%7B%0A%20%20%20%20%20%20%20%20if%20(document.selection.type%20%3D%3D%20%22Text%22)%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20html%20%3D%20document.selection.createRange().htmlText%3B%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%7D%0A%20%20%20%20return%20html%3B%0A%20%20%7D%0A%0A%20%20const%20selection%20%3D%20getSelectionHtml()%3B%0A%0A%20%20const%20%7B%0A%20%20%20%20%20%20title%2C%0A%20%20%20%20%20%20byline%2C%0A%20%20%20%20%20%20content%0A%20%20%7D%20%3D%20new%20Readability(document.cloneNode(true)).parse()%3B%0A%0A%20%20function%20getFileName(fileName)%20%7B%0A%20%20%20%20var%20userAgent%20%3D%20window.navigator.userAgent%2C%0A%20%20%20%20%20%20%20%20platform%20%3D%20window.navigator.platform%2C%0A%20%20%20%20%20%20%20%20windowsPlatforms%20%3D%20%5B'Win32'%2C%20'Win64'%2C%20'Windows'%2C%20'WinCE'%5D%3B%0A%0A%20%20%20%20if%20(windowsPlatforms.indexOf(platform)%20!%3D%3D%20-1)%20%7B%0A%20%20%20%20%20%20fileName%20%3D%20fileName.replace('%3A'%2C%20'').replace(%2F%5B%2F%5C%5C%3F%25*%7C%22%3C%3E%5D%2Fg%2C%20'-')%3B%0A%20%20%20%20%7D%20else%20%7B%0A%20%20%20%20%20%20fileName%20%3D%20fileName.replace('%3A'%2C%20'').replace(%2F%5C%2F%2Fg%2C%20'-').replace(%2F%5C%5C%2Fg%2C%20'-')%3B%0A%20%20%20%20%7D%0A%20%20%20%20return%20fileName%3B%0A%20%20%7D%0A%20%20const%20fileName%20%3D%20getFileName(title)%3B%0A%0A%20%20if%20(selection)%20%7B%0A%20%20%20%20%20%20var%20markdownify%20%3D%20selection%3B%0A%20%20%7D%20else%20%7B%0A%20%20%20%20%20%20var%20markdownify%20%3D%20content%3B%0A%20%20%7D%0A%0A%20%20if%20(vault)%20%7B%0A%20%20%20%20%20%20var%20vaultName%20%3D%20'%26vault%3D'%20%2B%20encodeURIComponent(%60%24%7Bvault%7D%60)%3B%0A%20%20%7D%20else%20%7B%0A%20%20%20%20%20%20var%20vaultName%20%3D%20''%3B%0A%20%20%7D%0A%0A%20%20const%20markdownBody%20%3D%20new%20Turndown(%7B%0A%20%20%20%20%20%20headingStyle%3A%20'atx'%2C%0A%20%20%20%20%20%20hr%3A%20'---'%2C%0A%20%20%20%20%20%20bulletListMarker%3A%20'-'%2C%0A%20%20%20%20%20%20codeBlockStyle%3A%20'fenced'%2C%0A%20%20%20%20%20%20emDelimiter%3A%20'*'%2C%0A%20%20%7D).turndown(markdownify)%3B%0A%0A%20%20var%20date%20%3D%20new%20Date()%3B%0A%0A%20%20function%20convertDate(date)%20%7B%0A%20%20%20%20var%20yyyy%20%3D%20date.getFullYear().toString()%3B%0A%20%20%20%20var%20mm%20%3D%20(date.getMonth()%2B1).toString()%3B%0A%20%20%20%20var%20dd%20%20%3D%20date.getDate().toString()%3B%0A%20%20%20%20var%20mmChars%20%3D%20mm.split('')%3B%0A%20%20%20%20var%20ddChars%20%3D%20dd.split('')%3B%0A%20%20%20%20return%20yyyy%20%2B%20'-'%20%2B%20(mmChars%5B1%5D%3Fmm%3A%220%22%2BmmChars%5B0%5D)%20%2B%20'-'%20%2B%20(ddChars%5B1%5D%3Fdd%3A%220%22%2BddChars%5B0%5D)%3B%0A%20%20%7D%0A%0A%20%20const%20today%20%3D%20convertDate(date)%3B%0A%0A%20%20%2F*%20Fetch%20the%20meta%20author%20*%2F%0A%20%20var%20metaAuthorElement%20%3D%20document.querySelector(%22meta%5Bname%3D'author'%5D%22)%3B%0A%20%20var%20metaAuthor%20%3D%20metaAuthorElement%20%3F%20metaAuthorElement.getAttribute(%22content%22)%20%3A%20%22%22%3B%0A%0A%20%20%2F*%20Fetch%20site%20name%20as%20backup%20*%2F%0A%20%20var%20metaSiteNameElement%20%3D%20document.querySelector(%22meta%5Bproperty%3D'og%3Asite_name'%5D%22)%3B%0A%20%20var%20siteName%20%3D%20metaSiteNameElement%20%3F%20metaSiteNameElement.getAttribute(%22content%22)%20%3A%20%22%22%3B%0A%0A%20%20%2F*%20Check%20if%20there's%20an%20author%20and%20add%20brackets%20*%2F%0A%20%20var%20authorBrackets%20%3D%20%22%22%3B%0A%20%20if%20(byline%20%26%26%20byline.trim()%20!%3D%3D%20%22%22)%20%7B%0A%20%20%20%20%20%20authorBrackets%20%3D%20'%22%5B%5B'%20%2B%20byline%20%2B%20'%5D%5D%22'%3B%0A%20%20%7D%20else%20if%20(metaAuthor%20%26%26%20metaAuthor.trim()%20!%3D%3D%20%22%22)%20%7B%0A%20%20%20%20%20%20authorBrackets%20%3D%20'%22%5B%5B'%20%2B%20metaAuthor%20%2B%20'%5D%5D%22'%3B%0A%20%20%7D%20else%20if%20(siteName%20%26%26%20siteName.trim()%20!%3D%3D%20%22%22)%20%7B%0A%20%20%20%20%20%20authorBrackets%20%3D%20'%22%5B%5B'%20%2B%20siteName%20%2B%20'%5D%5D%22'%3B%0A%20%20%7D%0A%0A%20%20%2F*%20Try%20to%20get%20published%20date%20*%2F%0A%20%20var%20timeElement%20%3D%20document.querySelector(%22time%22)%3B%0A%20%20var%20publishedDate%20%3D%20timeElement%20%3F%20timeElement.getAttribute(%22datetime%22)%20%3A%20%22%22%3B%0A%0A%20%20if%20(publishedDate%20%26%26%20publishedDate.trim()%20!%3D%3D%20%22%22)%20%7B%0A%20%20%20%20%20%20var%20date%20%3D%20new%20Date(publishedDate)%3B%0A%20%20%20%20%20%20var%20year%20%3D%20date.getFullYear()%3B%0A%20%20%20%20%20%20var%20month%20%3D%20date.getMonth()%20%2B%201%3B%20%2F%2F%20Months%20are%200-based%20in%20JavaScript%0A%20%20%20%20%20%20var%20day%20%3D%20date.getDate()%3B%0A%0A%20%20%20%20%20%20%2F%2F%20Pad%20month%20and%20day%20with%20leading%20zeros%20if%20necessary%0A%20%20%20%20%20%20month%20%3D%20month%20%3C%2010%20%3F%20'0'%20%2B%20month%20%3A%20month%3B%0A%20%20%20%20%20%20day%20%3D%20day%20%3C%2010%20%3F%20'0'%20%2B%20day%20%3A%20day%3B%0A%0A%20%20%20%20%20%20var%20published%20%3D%20year%20%2B%20'-'%20%2B%20month%20%2B%20'-'%20%2B%20day%3B%0A%20%20%7D%20else%20%7B%0A%20%20%20%20%20%20var%20published%20%3D%20''%0A%20%20%7D%0A%0A%20%20%2F*%20YAML%20front%20matter%20as%20tags%20render%20cleaner%20with%20special%20chars%20%20*%2F%0A%20%20const%20fileContent%20%3D%20%0A%20%20%20%20%20%20'---%5Cn'%0A%20%20%20%20%20%20%2B%20'author%3A%20'%20%2B%20authorBrackets%20%2B%20'%5Cn'%0A%20%20%20%20%20%20%2B%20'title%3A%20%22'%20%2B%20title%20%2B%20'%22%5Cn'%0A%20%20%20%20%20%20%2B%20'source%3A%20'%20%2B%20document.URL%20%2B%20'%5Cn'%0A%20%20%20%20%20%20%2B%20'clipped%3A%20'%20%2B%20today%20%2B%20'%5Cn'%0A%20%20%20%20%20%20%2B%20'published%3A%20'%20%2B%20published%20%2B%20'%5Cn'%20%0A%20%20%20%20%20%20%2B%20'tags%3A%20%5B'%20%2B%20tags%20%2B%20'%5D%5Cn'%0A%20%20%20%20%20%20%2B%20'---%5Cn%5Cn'%0A%20%20%20%20%20%20%2B%20markdownBody%20%3B%0A%0A%20%20%2F*%20assemble%20URL%2C%20decrementing%20each%20time%2C%20until%20it%20does%20not%20exceed%20the%20max%20URL%20length%20for%20this%20browser%2C%20supposedly%202048%20but%20allow%20for%20a%20little%20error%20with%202030%20*%2F%0A%20%20contentLength%20%3D%202048%3B%0A%20%20maxURLLength%20%3D%202030%3B%0A%20%20decrement%20%3D%201%3B%0A%0A%20%20do%20%7B%0A%20%20hrefString%20%3D%20'obsidian%3A%2F%2Fnew%3F'%0A%20%20%20%20%20%20%2B%20'file%3D'%20%2B%20encodeURIComponent(folder%20%2B%20fileName)%0A%20%20%20%20%20%20%2B%20'%26content%3D'%20%2B%20encodeURIComponent(fileContent.substr(0%2CcontentLength-1))%0A%20%20%20%20%20%20%2B%20vaultName%20%3B%0A%20%20contentLength%20%3D%20contentLength%20-%20decrement%3B%0A%20%20%7D%20while%20(hrefString.length%20%3E%20maxURLLength)%3B%0A%0A%20%20document.location.href%20%3D%20hrefString%3B%0A%0A%7D)%7D)()%3B
    javascript:(function()%7Bjavascript%3A%20Promise.all(%5Bimport('https%3A%2F%2Funpkg.com%2Fturndown%406.0.0%3Fmodule')%2C%20import('https%3A%2F%2Funpkg.com%2F%40tehshrike%2Freadability%400.2.0')%2C%20%5D).then(async%20(%5B%7B%0A%20%20%20%20default%3A%20Turndown%0A%7D%2C%20%7B%0A%20%20%20%20default%3A%20Readability%0A%7D%5D)%20%3D%3E%20%7B%0A%0A%20%20%2F*%20Optional%20vault%20name%20*%2F%0A%20%20const%20vault%20%3D%20%22%22%3B%0A%0A%20%20%2F*%20Optional%20folder%20name%20such%20as%20%22Clippings%2F%22%20*%2F%0A%20%20const%20folder%20%3D%20%22Clippings%2F%22%3B%0A%0A%20%20%2F*%20Optional%20tags%20%20*%2F%0A%20%20let%20tags%20%3D%20%22clippings%22%3B%0A%0A%20%20%2F*%20Parse%20the%20site's%20meta%20keywords%20content%20into%20tags%2C%20if%20present%20*%2F%0A%20%20if%20(document.querySelector('meta%5Bname%3D%22keywords%22%20i%5D'))%20%7B%0A%20%20%20%20%20%20var%20keywords%20%3D%20document.querySelector('meta%5Bname%3D%22keywords%22%20i%5D').getAttribute('content').split('%2C')%3B%0A%0A%20%20%20%20%20%20keywords.forEach(function(keyword)%20%7B%0A%20%20%20%20%20%20%20%20%20%20let%20tag%20%3D%20'%20'%20%2B%20keyword.split('%20').join('')%3B%0A%20%20%20%20%20%20%20%20%20%20tags%20%2B%3D%20tag%3B%0A%20%20%20%20%20%20%7D)%3B%0A%20%20%7D%0A%0A%20%20function%20getSelectionHtml()%20%7B%0A%20%20%20%20var%20html%20%3D%20%22%22%3B%0A%20%20%20%20if%20(typeof%20window.getSelection%20!%3D%20%22undefined%22)%20%7B%0A%20%20%20%20%20%20%20%20var%20sel%20%3D%20window.getSelection()%3B%0A%20%20%20%20%20%20%20%20if%20(sel.rangeCount)%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20var%20container%20%3D%20document.createElement(%22div%22)%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20for%20(var%20i%20%3D%200%2C%20len%20%3D%20sel.rangeCount%3B%20i%20%3C%20len%3B%20%2B%2Bi)%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20container.appendChild(sel.getRangeAt(i).cloneContents())%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%20%20%20%20html%20%3D%20container.innerHTML%3B%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%7D%20else%20if%20(typeof%20document.selection%20!%3D%20%22undefined%22)%20%7B%0A%20%20%20%20%20%20%20%20if%20(document.selection.type%20%3D%3D%20%22Text%22)%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20html%20%3D%20document.selection.createRange().htmlText%3B%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%7D%0A%20%20%20%20return%20html%3B%0A%20%20%7D%0A%0A%20%20const%20selection%20%3D%20getSelectionHtml()%3B%0A%0A%20%20const%20%7B%0A%20%20%20%20%20%20title%2C%0A%20%20%20%20%20%20byline%2C%0A%20%20%20%20%20%20content%0A%20%20%7D%20%3D%20new%20Readability(document.cloneNode(true)).parse()%3B%0A%0A%20%20function%20getFileName(fileName)%20%7B%0A%20%20%20%20var%20userAgent%20%3D%20window.navigator.userAgent%2C%0A%20%20%20%20%20%20%20%20platform%20%3D%20window.navigator.platform%2C%0A%20%20%20%20%20%20%20%20windowsPlatforms%20%3D%20%5B'Win32'%2C%20'Win64'%2C%20'Windows'%2C%20'WinCE'%5D%3B%0A%0A%20%20%20%20if%20(windowsPlatforms.indexOf(platform)%20!%3D%3D%20-1)%20%7B%0A%20%20%20%20%20%20fileName%20%3D%20fileName.replace('%3A'%2C%20'').replace(%2F%5B%2F%5C%5C%3F%25*%7C%22%3C%3E%5D%2Fg%2C%20'-')%3B%0A%20%20%20%20%7D%20else%20%7B%0A%20%20%20%20%20%20fileName%20%3D%20fileName.replace('%3A'%2C%20'').replace(%2F%5C%2F%2Fg%2C%20'-').replace(%2F%5C%5C%2Fg%2C%20'-')%3B%0A%20%20%20%20%7D%0A%20%20%20%20return%20fileName%3B%0A%20%20%7D%0A%20%20const%20fileName%20%3D%20getFileName(title)%3B%0A%0A%20%20if%20(selection)%20%7B%0A%20%20%20%20%20%20var%20markdownify%20%3D%20selection%3B%0A%20%20%7D%20else%20%7B%0A%20%20%20%20%20%20var%20markdownify%20%3D%20content%3B%0A%20%20%7D%0A%0A%20%20if%20(vault)%20%7B%0A%20%20%20%20%20%20var%20vaultName%20%3D%20'%26vault%3D'%20%2B%20encodeURIComponent(%60%24%7Bvault%7D%60)%3B%0A%20%20%7D%20else%20%7B%0A%20%20%20%20%20%20var%20vaultName%20%3D%20''%3B%0A%20%20%7D%0A%0A%20%20const%20markdownBody%20%3D%20new%20Turndown(%7B%0A%20%20%20%20%20%20headingStyle%3A%20'atx'%2C%0A%20%20%20%20%20%20hr%3A%20'---'%2C%0A%20%20%20%20%20%20bulletListMarker%3A%20'-'%2C%0A%20%20%20%20%20%20codeBlockStyle%3A%20'fenced'%2C%0A%20%20%20%20%20%20emDelimiter%3A%20'*'%2C%0A%20%20%7D).turndown(markdownify)%3B%0A%0A%20%20var%20date%20%3D%20new%20Date()%3B%0A%0A%20%20function%20convertDate(date)%20%7B%0A%20%20%20%20var%20yyyy%20%3D%20date.getFullYear().toString()%3B%0A%20%20%20%20var%20mm%20%3D%20(date.getMonth()%2B1).toString()%3B%0A%20%20%20%20var%20dd%20%20%3D%20date.getDate().toString()%3B%0A%20%20%20%20var%20mmChars%20%3D%20mm.split('')%3B%0A%20%20%20%20var%20ddChars%20%3D%20dd.split('')%3B%0A%20%20%20%20return%20yyyy%20%2B%20'-'%20%2B%20(mmChars%5B1%5D%3Fmm%3A%220%22%2BmmChars%5B0%5D)%20%2B%20'-'%20%2B%20(ddChars%5B1%5D%3Fdd%3A%220%22%2BddChars%5B0%5D)%3B%0A%20%20%7D%0A%0A%20%20const%20today%20%3D%20convertDate(date)%3B%0A%0A%20%20%2F*%20Fetch%20the%20meta%20author%20*%2F%0A%20%20var%20metaAuthorElement%20%3D%20document.querySelector(%22meta%5Bname%3D'author'%5D%22)%3B%0A%20%20var%20metaAuthor%20%3D%20metaAuthorElement%20%3F%20metaAuthorElement.getAttribute(%22content%22)%20%3A%20%22%22%3B%0A%0A%20%20%2F*%20Fetch%20site%20name%20as%20backup%20*%2F%0A%20%20var%20metaSiteNameElement%20%3D%20document.querySelector(%22meta%5Bproperty%3D'og%3Asite_name'%5D%22)%3B%0A%20%20var%20siteName%20%3D%20metaSiteNameElement%20%3F%20metaSiteNameElement.getAttribute(%22content%22)%20%3A%20%22%22%3B%0A%0A%20%20%2F*%20Check%20if%20there's%20an%20author%20and%20add%20brackets%20*%2F%0A%20%20var%20authorBrackets%20%3D%20%22%22%3B%0A%20%20if%20(byline%20%26%26%20byline.trim()%20!%3D%3D%20%22%22)%20%7B%0A%20%20%20%20%20%20authorBrackets%20%3D%20'%22%5B%5B'%20%2B%20byline%20%2B%20'%5D%5D%22'%3B%0A%20%20%7D%20else%20if%20(metaAuthor%20%26%26%20metaAuthor.trim()%20!%3D%3D%20%22%22)%20%7B%0A%20%20%20%20%20%20authorBrackets%20%3D%20'%22%5B%5B'%20%2B%20metaAuthor%20%2B%20'%5D%5D%22'%3B%0A%20%20%7D%20else%20if%20(siteName%20%26%26%20siteName.trim()%20!%3D%3D%20%22%22)%20%7B%0A%20%20%20%20%20%20authorBrackets%20%3D%20'%22%5B%5B'%20%2B%20siteName%20%2B%20'%5D%5D%22'%3B%0A%20%20%7D%0A%0A%20%20%2F*%20Try%20to%20get%20published%20date%20*%2F%0A%20%20var%20timeElement%20%3D%20document.querySelector(%22time%22)%3B%0A%20%20var%20publishedDate%20%3D%20timeElement%20%3F%20timeElement.getAttribute(%22datetime%22)%20%3A%20%22%22%3B%0A%0A%20%20if%20(publishedDate%20%26%26%20publishedDate.trim()%20!%3D%3D%20%22%22)%20%7B%0A%20%20%20%20%20%20var%20date%20%3D%20new%20Date(publishedDate)%3B%0A%20%20%20%20%20%20var%20year%20%3D%20date.getFullYear()%3B%0A%20%20%20%20%20%20var%20month%20%3D%20date.getMonth()%20%2B%201%3B%20%2F%2F%20Months%20are%200-based%20in%20JavaScript%0A%20%20%20%20%20%20var%20day%20%3D%20date.getDate()%3B%0A%0A%20%20%20%20%20%20%2F%2F%20Pad%20month%20and%20day%20with%20leading%20zeros%20if%20necessary%0A%20%20%20%20%20%20month%20%3D%20month%20%3C%2010%20%3F%20'0'%20%2B%20month%20%3A%20month%3B%0A%20%20%20%20%20%20day%20%3D%20day%20%3C%2010%20%3F%20'0'%20%2B%20day%20%3A%20day%3B%0A%0A%20%20%20%20%20%20var%20published%20%3D%20year%20%2B%20'-'%20%2B%20month%20%2B%20'-'%20%2B%20day%3B%0A%20%20%7D%20else%20%7B%0A%20%20%20%20%20%20var%20published%20%3D%20''%0A%20%20%7D%0A%0A%20%20%2F*%20YAML%20front%20matter%20as%20tags%20render%20cleaner%20with%20special%20chars%20%20*%2F%0A%20%20const%20fileContent%20%3D%20%0A%20%20%20%20%20%20'---%5Cn'%0A%20%20%20%20%20%20%2B%20'author%3A%20'%20%2B%20authorBrackets%20%2B%20'%5Cn'%0A%20%20%20%20%20%20%2B%20'title%3A%20%22'%20%2B%20title%20%2B%20'%22%5Cn'%0A%20%20%20%20%20%20%2B%20'source%3A%20'%20%2B%20document.URL%20%2B%20'%5Cn'%0A%20%20%20%20%20%20%2B%20'clipped%3A%20'%20%2B%20today%20%2B%20'%5Cn'%0A%20%20%20%20%20%20%2B%20'published%3A%20'%20%2B%20published%20%2B%20'%5Cn'%20%0A%20%20%20%20%20%20%2B%20'topics%3A%20%5Cn'%0A%20%20%20%20%20%20%2B%20'tags%3A%20%5B'%20%2B%20tags%20%2B%20'%5D%5Cn'%0A%20%20%20%20%20%20%2B%20'---%5Cn%5Cn'%0A%20%20%20%20%20%20%2B%20markdownBody%20%3B%0A%0A%20%20%20document.location.href%20%3D%20%22obsidian%3A%2F%2Fnew%3F%22%0A%20%20%20%20%2B%20%22file%3D%22%20%2B%20encodeURIComponent(folder%20%2B%20fileName)%0A%20%20%20%20%2B%20%22%26content%3D%22%20%2B%20encodeURIComponent(fileContent)%0A%20%20%20%20%2B%20vaultName%20%3B%0A%0A%7D)%7D)()%3B
  7. @kepano kepano revised this gist Jul 29, 2023. 2 changed files with 5 additions and 5 deletions.
    8 changes: 4 additions & 4 deletions obsidian-web-clipper.js
    Original file line number Diff line number Diff line change
    @@ -102,17 +102,17 @@ javascript: Promise.all([import('https://unpkg.com/[email protected]?module'), impo
    var metaAuthor = metaAuthorElement ? metaAuthorElement.getAttribute("content") : "";

    /* Fetch site name as backup */
    var metaSiteNameElement = document.querySelector("meta[name='og:site_name']");
    var metaSiteNameElement = document.querySelector("meta[property='og:site_name']");
    var siteName = metaSiteNameElement ? metaSiteNameElement.getAttribute("content") : "";

    /* Check if there's an author and add brackets */
    var authorBrackets = "";
    if (byline && byline.trim() !== "") {
    authorBrackets = '"[[ ' + byline + ' ]]"';
    authorBrackets = '"[[' + byline + ']]"';
    } else if (metaAuthor && metaAuthor.trim() !== "") {
    authorBrackets = '"[[ ' + metaAuthor + ' ]]"';
    authorBrackets = '"[[' + metaAuthor + ']]"';
    } else if (siteName && siteName.trim() !== "") {
    authorBrackets = '"[[ ' + siteName + ' ]]"';
    authorBrackets = '"[[' + siteName + ']]"';
    }

    /* Try to get published date */
    2 changes: 1 addition & 1 deletion obsidian-web-clipper.min.js
    Original file line number Diff line number Diff line change
    @@ -1 +1 @@
    javascript:(function()%7Bjavascript%3A%20Promise.all(%5Bimport('https%3A%2F%2Funpkg.com%2Fturndown%406.0.0%3Fmodule')%2C%20import('https%3A%2F%2Funpkg.com%2F%40tehshrike%2Freadability%400.2.0')%2C%20%5D).then(async%20(%5B%7B%0A%20%20%20%20default%3A%20Turndown%0A%7D%2C%20%7B%0A%20%20%20%20default%3A%20Readability%0A%7D%5D)%20%3D%3E%20%7B%0A%0A%20%20%2F*%20Optional%20vault%20name%20*%2F%0A%20%20const%20vault%20%3D%20%22%22%3B%0A%0A%20%20%2F*%20Optional%20folder%20name%20such%20as%20%22Clippings%2F%22%20*%2F%0A%20%20const%20folder%20%3D%20%22%22%3B%0A%0A%20%20%2F*%20Optional%20tags%20%20*%2F%0A%20%20let%20tags%20%3D%20%22clippings%22%3B%0A%0A%20%20%2F*%20Parse%20the%20site's%20meta%20keywords%20content%20into%20tags%2C%20if%20present%20*%2F%0A%20%20if%20(document.querySelector('meta%5Bname%3D%22keywords%22%20i%5D'))%20%7B%0A%20%20%20%20%20%20var%20keywords%20%3D%20document.querySelector('meta%5Bname%3D%22keywords%22%20i%5D').getAttribute('content').split('%2C')%3B%0A%0A%20%20%20%20%20%20keywords.forEach(function(keyword)%20%7B%0A%20%20%20%20%20%20%20%20%20%20let%20tag%20%3D%20'%20'%20%2B%20keyword.split('%20').join('')%3B%0A%20%20%20%20%20%20%20%20%20%20tags%20%2B%3D%20tag%3B%0A%20%20%20%20%20%20%7D)%3B%0A%20%20%7D%0A%0A%20%20function%20getSelectionHtml()%20%7B%0A%20%20%20%20var%20html%20%3D%20%22%22%3B%0A%20%20%20%20if%20(typeof%20window.getSelection%20!%3D%20%22undefined%22)%20%7B%0A%20%20%20%20%20%20%20%20var%20sel%20%3D%20window.getSelection()%3B%0A%20%20%20%20%20%20%20%20if%20(sel.rangeCount)%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20var%20container%20%3D%20document.createElement(%22div%22)%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20for%20(var%20i%20%3D%200%2C%20len%20%3D%20sel.rangeCount%3B%20i%20%3C%20len%3B%20%2B%2Bi)%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20container.appendChild(sel.getRangeAt(i).cloneContents())%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%20%20%20%20html%20%3D%20container.innerHTML%3B%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%7D%20else%20if%20(typeof%20document.selection%20!%3D%20%22undefined%22)%20%7B%0A%20%20%20%20%20%20%20%20if%20(document.selection.type%20%3D%3D%20%22Text%22)%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20html%20%3D%20document.selection.createRange().htmlText%3B%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%7D%0A%20%20%20%20return%20html%3B%0A%20%20%7D%0A%0A%20%20const%20selection%20%3D%20getSelectionHtml()%3B%0A%0A%20%20const%20%7B%0A%20%20%20%20%20%20title%2C%0A%20%20%20%20%20%20byline%2C%0A%20%20%20%20%20%20content%0A%20%20%7D%20%3D%20new%20Readability(document.cloneNode(true)).parse()%3B%0A%0A%20%20function%20getFileName(fileName)%20%7B%0A%20%20%20%20var%20userAgent%20%3D%20window.navigator.userAgent%2C%0A%20%20%20%20%20%20%20%20platform%20%3D%20window.navigator.platform%2C%0A%20%20%20%20%20%20%20%20windowsPlatforms%20%3D%20%5B'Win32'%2C%20'Win64'%2C%20'Windows'%2C%20'WinCE'%5D%3B%0A%0A%20%20%20%20if%20(windowsPlatforms.indexOf(platform)%20!%3D%3D%20-1)%20%7B%0A%20%20%20%20%20%20fileName%20%3D%20fileName.replace('%3A'%2C%20'').replace(%2F%5B%2F%5C%5C%3F%25*%7C%22%3C%3E%5D%2Fg%2C%20'-')%3B%0A%20%20%20%20%7D%20else%20%7B%0A%20%20%20%20%20%20fileName%20%3D%20fileName.replace('%3A'%2C%20'').replace(%2F%5C%2F%2Fg%2C%20'-').replace(%2F%5C%5C%2Fg%2C%20'-')%3B%0A%20%20%20%20%7D%0A%20%20%20%20return%20fileName%3B%0A%20%20%7D%0A%20%20const%20fileName%20%3D%20getFileName(title)%3B%0A%0A%20%20if%20(selection)%20%7B%0A%20%20%20%20%20%20var%20markdownify%20%3D%20selection%3B%0A%20%20%7D%20else%20%7B%0A%20%20%20%20%20%20var%20markdownify%20%3D%20content%3B%0A%20%20%7D%0A%0A%20%20if%20(vault)%20%7B%0A%20%20%20%20%20%20var%20vaultName%20%3D%20'%26vault%3D'%20%2B%20encodeURIComponent(%60%24%7Bvault%7D%60)%3B%0A%20%20%7D%20else%20%7B%0A%20%20%20%20%20%20var%20vaultName%20%3D%20''%3B%0A%20%20%7D%0A%0A%20%20const%20markdownBody%20%3D%20new%20Turndown(%7B%0A%20%20%20%20%20%20headingStyle%3A%20'atx'%2C%0A%20%20%20%20%20%20hr%3A%20'---'%2C%0A%20%20%20%20%20%20bulletListMarker%3A%20'-'%2C%0A%20%20%20%20%20%20codeBlockStyle%3A%20'fenced'%2C%0A%20%20%20%20%20%20emDelimiter%3A%20'*'%2C%0A%20%20%7D).turndown(markdownify)%3B%0A%0A%20%20var%20date%20%3D%20new%20Date()%3B%0A%0A%20%20function%20convertDate(date)%20%7B%0A%20%20%20%20var%20yyyy%20%3D%20date.getFullYear().toString()%3B%0A%20%20%20%20var%20mm%20%3D%20(date.getMonth()%2B1).toString()%3B%0A%20%20%20%20var%20dd%20%20%3D%20date.getDate().toString()%3B%0A%20%20%20%20var%20mmChars%20%3D%20mm.split('')%3B%0A%20%20%20%20var%20ddChars%20%3D%20dd.split('')%3B%0A%20%20%20%20return%20yyyy%20%2B%20'-'%20%2B%20(mmChars%5B1%5D%3Fmm%3A%220%22%2BmmChars%5B0%5D)%20%2B%20'-'%20%2B%20(ddChars%5B1%5D%3Fdd%3A%220%22%2BddChars%5B0%5D)%3B%0A%20%20%7D%0A%0A%20%20const%20today%20%3D%20convertDate(date)%3B%0A%0A%20%20%2F*%20Fetch%20the%20meta%20author%20*%2F%0A%20%20var%20metaAuthorElement%20%3D%20document.querySelector(%22meta%5Bname%3D'author'%5D%22)%3B%0A%20%20var%20metaAuthor%20%3D%20metaAuthorElement%20%3F%20metaAuthorElement.getAttribute(%22content%22)%20%3A%20%22%22%3B%0A%0A%20%20%2F*%20Fetch%20site%20name%20as%20backup%20*%2F%0A%20%20var%20metaSiteNameElement%20%3D%20document.querySelector(%22meta%5Bname%3D'og%3Asite_name'%5D%22)%3B%0A%20%20var%20siteName%20%3D%20metaSiteNameElement%20%3F%20metaSiteNameElement.getAttribute(%22content%22)%20%3A%20%22%22%3B%0A%0A%20%20%2F*%20Check%20if%20there's%20an%20author%20and%20add%20brackets%20*%2F%0A%20%20var%20authorBrackets%20%3D%20%22%22%3B%0A%20%20if%20(byline%20%26%26%20byline.trim()%20!%3D%3D%20%22%22)%20%7B%0A%20%20%20%20%20%20authorBrackets%20%3D%20'%22%5B%5B%20'%20%2B%20byline%20%2B%20'%20%5D%5D%22'%3B%0A%20%20%7D%20else%20if%20(metaAuthor%20%26%26%20metaAuthor.trim()%20!%3D%3D%20%22%22)%20%7B%0A%20%20%20%20%20%20authorBrackets%20%3D%20'%22%5B%5B%20'%20%2B%20metaAuthor%20%2B%20'%20%5D%5D%22'%3B%0A%20%20%7D%20else%20if%20(siteName%20%26%26%20siteName.trim()%20!%3D%3D%20%22%22)%20%7B%0A%20%20%20%20%20%20authorBrackets%20%3D%20'%22%5B%5B%20'%20%2B%20siteName%20%2B%20'%20%5D%5D%22'%3B%0A%20%20%7D%0A%0A%20%20%2F*%20Try%20to%20get%20published%20date%20*%2F%0A%20%20var%20timeElement%20%3D%20document.querySelector(%22time%22)%3B%0A%20%20var%20publishedDate%20%3D%20timeElement%20%3F%20timeElement.getAttribute(%22datetime%22)%20%3A%20%22%22%3B%0A%0A%20%20if%20(publishedDate%20%26%26%20publishedDate.trim()%20!%3D%3D%20%22%22)%20%7B%0A%20%20%20%20%20%20var%20date%20%3D%20new%20Date(publishedDate)%3B%0A%20%20%20%20%20%20var%20year%20%3D%20date.getFullYear()%3B%0A%20%20%20%20%20%20var%20month%20%3D%20date.getMonth()%20%2B%201%3B%20%2F%2F%20Months%20are%200-based%20in%20JavaScript%0A%20%20%20%20%20%20var%20day%20%3D%20date.getDate()%3B%0A%0A%20%20%20%20%20%20%2F%2F%20Pad%20month%20and%20day%20with%20leading%20zeros%20if%20necessary%0A%20%20%20%20%20%20month%20%3D%20month%20%3C%2010%20%3F%20'0'%20%2B%20month%20%3A%20month%3B%0A%20%20%20%20%20%20day%20%3D%20day%20%3C%2010%20%3F%20'0'%20%2B%20day%20%3A%20day%3B%0A%0A%20%20%20%20%20%20var%20published%20%3D%20year%20%2B%20'-'%20%2B%20month%20%2B%20'-'%20%2B%20day%3B%0A%20%20%7D%20else%20%7B%0A%20%20%20%20%20%20var%20published%20%3D%20''%0A%20%20%7D%0A%0A%20%20%2F*%20YAML%20front%20matter%20as%20tags%20render%20cleaner%20with%20special%20chars%20%20*%2F%0A%20%20const%20fileContent%20%3D%20%0A%20%20%20%20%20%20'---%5Cn'%0A%20%20%20%20%20%20%2B%20'author%3A%20'%20%2B%20authorBrackets%20%2B%20'%5Cn'%0A%20%20%20%20%20%20%2B%20'title%3A%20%22'%20%2B%20title%20%2B%20'%22%5Cn'%0A%20%20%20%20%20%20%2B%20'source%3A%20'%20%2B%20document.URL%20%2B%20'%5Cn'%0A%20%20%20%20%20%20%2B%20'clipped%3A%20'%20%2B%20today%20%2B%20'%5Cn'%0A%20%20%20%20%20%20%2B%20'published%3A%20'%20%2B%20published%20%2B%20'%5Cn'%20%0A%20%20%20%20%20%20%2B%20'tags%3A%20%5B'%20%2B%20tags%20%2B%20'%5D%5Cn'%0A%20%20%20%20%20%20%2B%20'---%5Cn%5Cn'%0A%20%20%20%20%20%20%2B%20markdownBody%20%3B%0A%0A%20%20%2F*%20assemble%20URL%2C%20decrementing%20each%20time%2C%20until%20it%20does%20not%20exceed%20the%20max%20URL%20length%20for%20this%20browser%2C%20supposedly%202048%20but%20allow%20for%20a%20little%20error%20with%202030%20*%2F%0A%20%20contentLength%20%3D%202048%3B%0A%20%20maxURLLength%20%3D%202030%3B%0A%20%20decrement%20%3D%201%3B%0A%0A%20%20do%20%7B%0A%20%20hrefString%20%3D%20'obsidian%3A%2F%2Fnew%3F'%0A%20%20%20%20%20%20%2B%20'file%3D'%20%2B%20encodeURIComponent(folder%20%2B%20fileName)%0A%20%20%20%20%20%20%2B%20'%26content%3D'%20%2B%20encodeURIComponent(fileContent.substr(0%2CcontentLength-1))%0A%20%20%20%20%20%20%2B%20vaultName%20%3B%0A%20%20contentLength%20%3D%20contentLength%20-%20decrement%3B%0A%20%20%7D%20while%20(hrefString.length%20%3E%20maxURLLength)%3B%0A%0A%20%20document.location.href%20%3D%20hrefString%3B%0A%0A%7D)%7D)()%3B
    javascript:(function()%7Bjavascript%3A%20Promise.all(%5Bimport('https%3A%2F%2Funpkg.com%2Fturndown%406.0.0%3Fmodule')%2C%20import('https%3A%2F%2Funpkg.com%2F%40tehshrike%2Freadability%400.2.0')%2C%20%5D).then(async%20(%5B%7B%0A%20%20%20%20default%3A%20Turndown%0A%7D%2C%20%7B%0A%20%20%20%20default%3A%20Readability%0A%7D%5D)%20%3D%3E%20%7B%0A%0A%20%20%2F*%20Optional%20vault%20name%20*%2F%0A%20%20const%20vault%20%3D%20%22%22%3B%0A%0A%20%20%2F*%20Optional%20folder%20name%20such%20as%20%22Clippings%2F%22%20*%2F%0A%20%20const%20folder%20%3D%20%22%22%3B%0A%0A%20%20%2F*%20Optional%20tags%20%20*%2F%0A%20%20let%20tags%20%3D%20%22clippings%22%3B%0A%0A%20%20%2F*%20Parse%20the%20site's%20meta%20keywords%20content%20into%20tags%2C%20if%20present%20*%2F%0A%20%20if%20(document.querySelector('meta%5Bname%3D%22keywords%22%20i%5D'))%20%7B%0A%20%20%20%20%20%20var%20keywords%20%3D%20document.querySelector('meta%5Bname%3D%22keywords%22%20i%5D').getAttribute('content').split('%2C')%3B%0A%0A%20%20%20%20%20%20keywords.forEach(function(keyword)%20%7B%0A%20%20%20%20%20%20%20%20%20%20let%20tag%20%3D%20'%20'%20%2B%20keyword.split('%20').join('')%3B%0A%20%20%20%20%20%20%20%20%20%20tags%20%2B%3D%20tag%3B%0A%20%20%20%20%20%20%7D)%3B%0A%20%20%7D%0A%0A%20%20function%20getSelectionHtml()%20%7B%0A%20%20%20%20var%20html%20%3D%20%22%22%3B%0A%20%20%20%20if%20(typeof%20window.getSelection%20!%3D%20%22undefined%22)%20%7B%0A%20%20%20%20%20%20%20%20var%20sel%20%3D%20window.getSelection()%3B%0A%20%20%20%20%20%20%20%20if%20(sel.rangeCount)%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20var%20container%20%3D%20document.createElement(%22div%22)%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20for%20(var%20i%20%3D%200%2C%20len%20%3D%20sel.rangeCount%3B%20i%20%3C%20len%3B%20%2B%2Bi)%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20container.appendChild(sel.getRangeAt(i).cloneContents())%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%20%20%20%20html%20%3D%20container.innerHTML%3B%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%7D%20else%20if%20(typeof%20document.selection%20!%3D%20%22undefined%22)%20%7B%0A%20%20%20%20%20%20%20%20if%20(document.selection.type%20%3D%3D%20%22Text%22)%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20html%20%3D%20document.selection.createRange().htmlText%3B%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%7D%0A%20%20%20%20return%20html%3B%0A%20%20%7D%0A%0A%20%20const%20selection%20%3D%20getSelectionHtml()%3B%0A%0A%20%20const%20%7B%0A%20%20%20%20%20%20title%2C%0A%20%20%20%20%20%20byline%2C%0A%20%20%20%20%20%20content%0A%20%20%7D%20%3D%20new%20Readability(document.cloneNode(true)).parse()%3B%0A%0A%20%20function%20getFileName(fileName)%20%7B%0A%20%20%20%20var%20userAgent%20%3D%20window.navigator.userAgent%2C%0A%20%20%20%20%20%20%20%20platform%20%3D%20window.navigator.platform%2C%0A%20%20%20%20%20%20%20%20windowsPlatforms%20%3D%20%5B'Win32'%2C%20'Win64'%2C%20'Windows'%2C%20'WinCE'%5D%3B%0A%0A%20%20%20%20if%20(windowsPlatforms.indexOf(platform)%20!%3D%3D%20-1)%20%7B%0A%20%20%20%20%20%20fileName%20%3D%20fileName.replace('%3A'%2C%20'').replace(%2F%5B%2F%5C%5C%3F%25*%7C%22%3C%3E%5D%2Fg%2C%20'-')%3B%0A%20%20%20%20%7D%20else%20%7B%0A%20%20%20%20%20%20fileName%20%3D%20fileName.replace('%3A'%2C%20'').replace(%2F%5C%2F%2Fg%2C%20'-').replace(%2F%5C%5C%2Fg%2C%20'-')%3B%0A%20%20%20%20%7D%0A%20%20%20%20return%20fileName%3B%0A%20%20%7D%0A%20%20const%20fileName%20%3D%20getFileName(title)%3B%0A%0A%20%20if%20(selection)%20%7B%0A%20%20%20%20%20%20var%20markdownify%20%3D%20selection%3B%0A%20%20%7D%20else%20%7B%0A%20%20%20%20%20%20var%20markdownify%20%3D%20content%3B%0A%20%20%7D%0A%0A%20%20if%20(vault)%20%7B%0A%20%20%20%20%20%20var%20vaultName%20%3D%20'%26vault%3D'%20%2B%20encodeURIComponent(%60%24%7Bvault%7D%60)%3B%0A%20%20%7D%20else%20%7B%0A%20%20%20%20%20%20var%20vaultName%20%3D%20''%3B%0A%20%20%7D%0A%0A%20%20const%20markdownBody%20%3D%20new%20Turndown(%7B%0A%20%20%20%20%20%20headingStyle%3A%20'atx'%2C%0A%20%20%20%20%20%20hr%3A%20'---'%2C%0A%20%20%20%20%20%20bulletListMarker%3A%20'-'%2C%0A%20%20%20%20%20%20codeBlockStyle%3A%20'fenced'%2C%0A%20%20%20%20%20%20emDelimiter%3A%20'*'%2C%0A%20%20%7D).turndown(markdownify)%3B%0A%0A%20%20var%20date%20%3D%20new%20Date()%3B%0A%0A%20%20function%20convertDate(date)%20%7B%0A%20%20%20%20var%20yyyy%20%3D%20date.getFullYear().toString()%3B%0A%20%20%20%20var%20mm%20%3D%20(date.getMonth()%2B1).toString()%3B%0A%20%20%20%20var%20dd%20%20%3D%20date.getDate().toString()%3B%0A%20%20%20%20var%20mmChars%20%3D%20mm.split('')%3B%0A%20%20%20%20var%20ddChars%20%3D%20dd.split('')%3B%0A%20%20%20%20return%20yyyy%20%2B%20'-'%20%2B%20(mmChars%5B1%5D%3Fmm%3A%220%22%2BmmChars%5B0%5D)%20%2B%20'-'%20%2B%20(ddChars%5B1%5D%3Fdd%3A%220%22%2BddChars%5B0%5D)%3B%0A%20%20%7D%0A%0A%20%20const%20today%20%3D%20convertDate(date)%3B%0A%0A%20%20%2F*%20Fetch%20the%20meta%20author%20*%2F%0A%20%20var%20metaAuthorElement%20%3D%20document.querySelector(%22meta%5Bname%3D'author'%5D%22)%3B%0A%20%20var%20metaAuthor%20%3D%20metaAuthorElement%20%3F%20metaAuthorElement.getAttribute(%22content%22)%20%3A%20%22%22%3B%0A%0A%20%20%2F*%20Fetch%20site%20name%20as%20backup%20*%2F%0A%20%20var%20metaSiteNameElement%20%3D%20document.querySelector(%22meta%5Bproperty%3D'og%3Asite_name'%5D%22)%3B%0A%20%20var%20siteName%20%3D%20metaSiteNameElement%20%3F%20metaSiteNameElement.getAttribute(%22content%22)%20%3A%20%22%22%3B%0A%0A%20%20%2F*%20Check%20if%20there's%20an%20author%20and%20add%20brackets%20*%2F%0A%20%20var%20authorBrackets%20%3D%20%22%22%3B%0A%20%20if%20(byline%20%26%26%20byline.trim()%20!%3D%3D%20%22%22)%20%7B%0A%20%20%20%20%20%20authorBrackets%20%3D%20'%22%5B%5B'%20%2B%20byline%20%2B%20'%5D%5D%22'%3B%0A%20%20%7D%20else%20if%20(metaAuthor%20%26%26%20metaAuthor.trim()%20!%3D%3D%20%22%22)%20%7B%0A%20%20%20%20%20%20authorBrackets%20%3D%20'%22%5B%5B'%20%2B%20metaAuthor%20%2B%20'%5D%5D%22'%3B%0A%20%20%7D%20else%20if%20(siteName%20%26%26%20siteName.trim()%20!%3D%3D%20%22%22)%20%7B%0A%20%20%20%20%20%20authorBrackets%20%3D%20'%22%5B%5B'%20%2B%20siteName%20%2B%20'%5D%5D%22'%3B%0A%20%20%7D%0A%0A%20%20%2F*%20Try%20to%20get%20published%20date%20*%2F%0A%20%20var%20timeElement%20%3D%20document.querySelector(%22time%22)%3B%0A%20%20var%20publishedDate%20%3D%20timeElement%20%3F%20timeElement.getAttribute(%22datetime%22)%20%3A%20%22%22%3B%0A%0A%20%20if%20(publishedDate%20%26%26%20publishedDate.trim()%20!%3D%3D%20%22%22)%20%7B%0A%20%20%20%20%20%20var%20date%20%3D%20new%20Date(publishedDate)%3B%0A%20%20%20%20%20%20var%20year%20%3D%20date.getFullYear()%3B%0A%20%20%20%20%20%20var%20month%20%3D%20date.getMonth()%20%2B%201%3B%20%2F%2F%20Months%20are%200-based%20in%20JavaScript%0A%20%20%20%20%20%20var%20day%20%3D%20date.getDate()%3B%0A%0A%20%20%20%20%20%20%2F%2F%20Pad%20month%20and%20day%20with%20leading%20zeros%20if%20necessary%0A%20%20%20%20%20%20month%20%3D%20month%20%3C%2010%20%3F%20'0'%20%2B%20month%20%3A%20month%3B%0A%20%20%20%20%20%20day%20%3D%20day%20%3C%2010%20%3F%20'0'%20%2B%20day%20%3A%20day%3B%0A%0A%20%20%20%20%20%20var%20published%20%3D%20year%20%2B%20'-'%20%2B%20month%20%2B%20'-'%20%2B%20day%3B%0A%20%20%7D%20else%20%7B%0A%20%20%20%20%20%20var%20published%20%3D%20''%0A%20%20%7D%0A%0A%20%20%2F*%20YAML%20front%20matter%20as%20tags%20render%20cleaner%20with%20special%20chars%20%20*%2F%0A%20%20const%20fileContent%20%3D%20%0A%20%20%20%20%20%20'---%5Cn'%0A%20%20%20%20%20%20%2B%20'author%3A%20'%20%2B%20authorBrackets%20%2B%20'%5Cn'%0A%20%20%20%20%20%20%2B%20'title%3A%20%22'%20%2B%20title%20%2B%20'%22%5Cn'%0A%20%20%20%20%20%20%2B%20'source%3A%20'%20%2B%20document.URL%20%2B%20'%5Cn'%0A%20%20%20%20%20%20%2B%20'clipped%3A%20'%20%2B%20today%20%2B%20'%5Cn'%0A%20%20%20%20%20%20%2B%20'published%3A%20'%20%2B%20published%20%2B%20'%5Cn'%20%0A%20%20%20%20%20%20%2B%20'tags%3A%20%5B'%20%2B%20tags%20%2B%20'%5D%5Cn'%0A%20%20%20%20%20%20%2B%20'---%5Cn%5Cn'%0A%20%20%20%20%20%20%2B%20markdownBody%20%3B%0A%0A%20%20%2F*%20assemble%20URL%2C%20decrementing%20each%20time%2C%20until%20it%20does%20not%20exceed%20the%20max%20URL%20length%20for%20this%20browser%2C%20supposedly%202048%20but%20allow%20for%20a%20little%20error%20with%202030%20*%2F%0A%20%20contentLength%20%3D%202048%3B%0A%20%20maxURLLength%20%3D%202030%3B%0A%20%20decrement%20%3D%201%3B%0A%0A%20%20do%20%7B%0A%20%20hrefString%20%3D%20'obsidian%3A%2F%2Fnew%3F'%0A%20%20%20%20%20%20%2B%20'file%3D'%20%2B%20encodeURIComponent(folder%20%2B%20fileName)%0A%20%20%20%20%20%20%2B%20'%26content%3D'%20%2B%20encodeURIComponent(fileContent.substr(0%2CcontentLength-1))%0A%20%20%20%20%20%20%2B%20vaultName%20%3B%0A%20%20contentLength%20%3D%20contentLength%20-%20decrement%3B%0A%20%20%7D%20while%20(hrefString.length%20%3E%20maxURLLength)%3B%0A%0A%20%20document.location.href%20%3D%20hrefString%3B%0A%0A%7D)%7D)()%3B
  8. @kepano kepano revised this gist Jul 29, 2023. 2 changed files with 22 additions and 3 deletions.
    23 changes: 21 additions & 2 deletions obsidian-web-clipper.js
    Original file line number Diff line number Diff line change
    @@ -115,14 +115,33 @@ javascript: Promise.all([import('https://unpkg.com/[email protected]?module'), impo
    authorBrackets = '"[[ ' + siteName + ' ]]"';
    }

    /* Try to get published date */
    var timeElement = document.querySelector("time");
    var publishedDate = timeElement ? timeElement.getAttribute("datetime") : "";

    if (publishedDate && publishedDate.trim() !== "") {
    var date = new Date(publishedDate);
    var year = date.getFullYear();
    var month = date.getMonth() + 1; // Months are 0-based in JavaScript
    var day = date.getDate();

    // Pad month and day with leading zeros if necessary
    month = month < 10 ? '0' + month : month;
    day = day < 10 ? '0' + day : day;

    var published = year + '-' + month + '-' + day;
    } else {
    var published = ''
    }

    /* YAML front matter as tags render cleaner with special chars */
    const fileContent =
    '---\n'
    + 'author: ' + authorBrackets + '\n'
    + 'title: ' + title + '\n'
    + 'title: "' + title + '"\n'
    + 'source: ' + document.URL + '\n'
    + 'clipped: ' + today + '\n'
    + 'published: \n'
    + 'published: ' + published + '\n'
    + 'tags: [' + tags + ']\n'
    + '---\n\n'
    + markdownBody ;
    2 changes: 1 addition & 1 deletion obsidian-web-clipper.min.js
    Original file line number Diff line number Diff line change
    @@ -1 +1 @@
    javascript:(function()%7Bjavascript%3A%20Promise.all(%5Bimport('https%3A%2F%2Funpkg.com%2Fturndown%406.0.0%3Fmodule')%2C%20import('https%3A%2F%2Funpkg.com%2F%40tehshrike%2Freadability%400.2.0')%2C%20%5D).then(async%20(%5B%7B%0A%20%20%20%20default%3A%20Turndown%0A%7D%2C%20%7B%0A%20%20%20%20default%3A%20Readability%0A%7D%5D)%20%3D%3E%20%7B%0A%0A%20%20%2F*%20Optional%20vault%20name%20*%2F%0A%20%20const%20vault%20%3D%20%22%22%3B%0A%0A%20%20%2F*%20Optional%20folder%20name%20such%20as%20%22Clippings%2F%22%20*%2F%0A%20%20const%20folder%20%3D%20%22%22%3B%0A%0A%20%20%2F*%20Optional%20tags%20%20*%2F%0A%20%20const%20tags%20%3D%20%22%23clippings%22%3B%0A%0A%20%20function%20getSelectionHtml()%20%7B%0A%20%20%20%20var%20html%20%3D%20%22%22%3B%0A%20%20%20%20if%20(typeof%20window.getSelection%20!%3D%20%22undefined%22)%20%7B%0A%20%20%20%20%20%20%20%20var%20sel%20%3D%20window.getSelection()%3B%0A%20%20%20%20%20%20%20%20if%20(sel.rangeCount)%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20var%20container%20%3D%20document.createElement(%22div%22)%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20for%20(var%20i%20%3D%200%2C%20len%20%3D%20sel.rangeCount%3B%20i%20%3C%20len%3B%20%2B%2Bi)%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20container.appendChild(sel.getRangeAt(i).cloneContents())%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%20%20%20%20html%20%3D%20container.innerHTML%3B%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%7D%20else%20if%20(typeof%20document.selection%20!%3D%20%22undefined%22)%20%7B%0A%20%20%20%20%20%20%20%20if%20(document.selection.type%20%3D%3D%20%22Text%22)%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20html%20%3D%20document.selection.createRange().htmlText%3B%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%7D%0A%20%20%20%20return%20html%3B%0A%20%20%7D%0A%0A%20%20const%20selection%20%3D%20getSelectionHtml()%3B%0A%0A%20%20const%20%7B%0A%20%20%20%20%20%20title%2C%0A%20%20%20%20%20%20byline%2C%0A%20%20%20%20%20%20content%0A%20%20%7D%20%3D%20new%20Readability(document.cloneNode(true)).parse()%3B%0A%0A%20%20function%20getFileName(fileName)%20%7B%0A%20%20%20%20var%20userAgent%20%3D%20window.navigator.userAgent%2C%0A%20%20%20%20%20%20%20%20platform%20%3D%20window.navigator.platform%2C%0A%20%20%20%20%20%20%20%20windowsPlatforms%20%3D%20%5B'Win32'%2C%20'Win64'%2C%20'Windows'%2C%20'WinCE'%5D%3B%0A%0A%20%20%20%20if%20(windowsPlatforms.indexOf(platform)%20!%3D%3D%20-1)%20%7B%0A%20%20%20%20%20%20fileName%20%3D%20fileName.replace('%3A'%2C%20'').replace(%2F%5B%2F%5C%5C%3F%25*%7C%22%3C%3E%5D%2Fg%2C%20'-')%3B%0A%20%20%20%20%7D%20else%20%7B%0A%20%20%20%20%20%20fileName%20%3D%20fileName.replace('%3A'%2C%20'').replace(%2F%5C%2F%2Fg%2C%20'-').replace(%2F%5C%5C%2Fg%2C%20'-')%3B%0A%20%20%20%20%7D%0A%20%20%20%20return%20fileName%3B%0A%20%20%7D%0A%20%20const%20fileName%20%3D%20getFileName(title)%3B%0A%0A%20%20if%20(selection)%20%7B%0A%20%20%20%20%20%20var%20markdownify%20%3D%20selection%3B%0A%20%20%7D%20else%20%7B%0A%20%20%20%20%20%20var%20markdownify%20%3D%20content%3B%0A%20%20%7D%0A%0A%20%20if%20(vault)%20%7B%0A%20%20%20%20%20%20var%20vaultName%20%3D%20'%26vault%3D'%20%2B%20encodeURIComponent(%60%24%7Bvault%7D%60)%3B%0A%20%20%7D%20else%20%7B%0A%20%20%20%20%20%20var%20vaultName%20%3D%20''%3B%0A%20%20%7D%0A%0A%20%20const%20markdownBody%20%3D%20new%20Turndown(%7B%0A%20%20%20%20%20%20headingStyle%3A%20'atx'%2C%0A%20%20%20%20%20%20hr%3A%20'---'%2C%0A%20%20%20%20%20%20bulletListMarker%3A%20'-'%2C%0A%20%20%20%20%20%20codeBlockStyle%3A%20'fenced'%2C%0A%20%20%20%20%20%20emDelimiter%3A%20'*'%2C%0A%20%20%7D).turndown(markdownify)%3B%0A%0A%20%20var%20date%20%3D%20new%20Date()%3B%0A%0A%20%20function%20convertDate(date)%20%7B%0A%20%20%20%20var%20yyyy%20%3D%20date.getFullYear().toString()%3B%0A%20%20%20%20var%20mm%20%3D%20(date.getMonth()%2B1).toString()%3B%0A%20%20%20%20var%20dd%20%20%3D%20date.getDate().toString()%3B%0A%20%20%20%20var%20mmChars%20%3D%20mm.split('')%3B%0A%20%20%20%20var%20ddChars%20%3D%20dd.split('')%3B%0A%20%20%20%20return%20yyyy%20%2B%20'-'%20%2B%20(mmChars%5B1%5D%3Fmm%3A%220%22%2BmmChars%5B0%5D)%20%2B%20'-'%20%2B%20(ddChars%5B1%5D%3Fdd%3A%220%22%2BddChars%5B0%5D)%3B%0A%20%20%7D%0A%0A%20%20const%20today%20%3D%20convertDate(date)%3B%0A%0A%20%20const%20fileContent%20%3D%20%0A%20%20%20%20%20%20%22author%3A%3A%20%22%20%2B%20byline%20%2B%20%22%5Cn%22%0A%20%20%20%20%20%20%2B%20%22source%3A%3A%20%5B%22%20%2B%20title%20%2B%20%22%5D(%22%20%2B%20document.URL%20%2B%20%22)%5Cn%22%0A%20%20%20%20%20%20%2B%20%22clipped%3A%3A%20%5B%5B%22%20%2B%20today%20%2B%20%22%5D%5D%5Cn%22%0A%20%20%20%20%20%20%2B%20%22published%3A%3A%20%5Cn%5Cn%22%20%0A%20%20%20%20%20%20%2B%20tags%20%2B%20%22%5Cn%5Cn%22%0A%20%20%20%20%20%20%2B%20markdownBody%20%3B%0A%20%20%0A%20%20document.location.href%20%3D%20%22obsidian%3A%2F%2Fnew%3F%22%0A%20%20%20%20%2B%20%22file%3D%22%20%2B%20encodeURIComponent(folder%20%2B%20fileName)%0A%20%20%20%20%2B%20%22%26content%3D%22%20%2B%20encodeURIComponent(fileContent)%0A%20%20%20%20%2B%20vaultName%20%3B%0A%7D)%7D)()%3B
    javascript:(function()%7Bjavascript%3A%20Promise.all(%5Bimport('https%3A%2F%2Funpkg.com%2Fturndown%406.0.0%3Fmodule')%2C%20import('https%3A%2F%2Funpkg.com%2F%40tehshrike%2Freadability%400.2.0')%2C%20%5D).then(async%20(%5B%7B%0A%20%20%20%20default%3A%20Turndown%0A%7D%2C%20%7B%0A%20%20%20%20default%3A%20Readability%0A%7D%5D)%20%3D%3E%20%7B%0A%0A%20%20%2F*%20Optional%20vault%20name%20*%2F%0A%20%20const%20vault%20%3D%20%22%22%3B%0A%0A%20%20%2F*%20Optional%20folder%20name%20such%20as%20%22Clippings%2F%22%20*%2F%0A%20%20const%20folder%20%3D%20%22%22%3B%0A%0A%20%20%2F*%20Optional%20tags%20%20*%2F%0A%20%20let%20tags%20%3D%20%22clippings%22%3B%0A%0A%20%20%2F*%20Parse%20the%20site's%20meta%20keywords%20content%20into%20tags%2C%20if%20present%20*%2F%0A%20%20if%20(document.querySelector('meta%5Bname%3D%22keywords%22%20i%5D'))%20%7B%0A%20%20%20%20%20%20var%20keywords%20%3D%20document.querySelector('meta%5Bname%3D%22keywords%22%20i%5D').getAttribute('content').split('%2C')%3B%0A%0A%20%20%20%20%20%20keywords.forEach(function(keyword)%20%7B%0A%20%20%20%20%20%20%20%20%20%20let%20tag%20%3D%20'%20'%20%2B%20keyword.split('%20').join('')%3B%0A%20%20%20%20%20%20%20%20%20%20tags%20%2B%3D%20tag%3B%0A%20%20%20%20%20%20%7D)%3B%0A%20%20%7D%0A%0A%20%20function%20getSelectionHtml()%20%7B%0A%20%20%20%20var%20html%20%3D%20%22%22%3B%0A%20%20%20%20if%20(typeof%20window.getSelection%20!%3D%20%22undefined%22)%20%7B%0A%20%20%20%20%20%20%20%20var%20sel%20%3D%20window.getSelection()%3B%0A%20%20%20%20%20%20%20%20if%20(sel.rangeCount)%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20var%20container%20%3D%20document.createElement(%22div%22)%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20for%20(var%20i%20%3D%200%2C%20len%20%3D%20sel.rangeCount%3B%20i%20%3C%20len%3B%20%2B%2Bi)%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20container.appendChild(sel.getRangeAt(i).cloneContents())%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%20%20%20%20html%20%3D%20container.innerHTML%3B%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%7D%20else%20if%20(typeof%20document.selection%20!%3D%20%22undefined%22)%20%7B%0A%20%20%20%20%20%20%20%20if%20(document.selection.type%20%3D%3D%20%22Text%22)%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20html%20%3D%20document.selection.createRange().htmlText%3B%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%7D%0A%20%20%20%20return%20html%3B%0A%20%20%7D%0A%0A%20%20const%20selection%20%3D%20getSelectionHtml()%3B%0A%0A%20%20const%20%7B%0A%20%20%20%20%20%20title%2C%0A%20%20%20%20%20%20byline%2C%0A%20%20%20%20%20%20content%0A%20%20%7D%20%3D%20new%20Readability(document.cloneNode(true)).parse()%3B%0A%0A%20%20function%20getFileName(fileName)%20%7B%0A%20%20%20%20var%20userAgent%20%3D%20window.navigator.userAgent%2C%0A%20%20%20%20%20%20%20%20platform%20%3D%20window.navigator.platform%2C%0A%20%20%20%20%20%20%20%20windowsPlatforms%20%3D%20%5B'Win32'%2C%20'Win64'%2C%20'Windows'%2C%20'WinCE'%5D%3B%0A%0A%20%20%20%20if%20(windowsPlatforms.indexOf(platform)%20!%3D%3D%20-1)%20%7B%0A%20%20%20%20%20%20fileName%20%3D%20fileName.replace('%3A'%2C%20'').replace(%2F%5B%2F%5C%5C%3F%25*%7C%22%3C%3E%5D%2Fg%2C%20'-')%3B%0A%20%20%20%20%7D%20else%20%7B%0A%20%20%20%20%20%20fileName%20%3D%20fileName.replace('%3A'%2C%20'').replace(%2F%5C%2F%2Fg%2C%20'-').replace(%2F%5C%5C%2Fg%2C%20'-')%3B%0A%20%20%20%20%7D%0A%20%20%20%20return%20fileName%3B%0A%20%20%7D%0A%20%20const%20fileName%20%3D%20getFileName(title)%3B%0A%0A%20%20if%20(selection)%20%7B%0A%20%20%20%20%20%20var%20markdownify%20%3D%20selection%3B%0A%20%20%7D%20else%20%7B%0A%20%20%20%20%20%20var%20markdownify%20%3D%20content%3B%0A%20%20%7D%0A%0A%20%20if%20(vault)%20%7B%0A%20%20%20%20%20%20var%20vaultName%20%3D%20'%26vault%3D'%20%2B%20encodeURIComponent(%60%24%7Bvault%7D%60)%3B%0A%20%20%7D%20else%20%7B%0A%20%20%20%20%20%20var%20vaultName%20%3D%20''%3B%0A%20%20%7D%0A%0A%20%20const%20markdownBody%20%3D%20new%20Turndown(%7B%0A%20%20%20%20%20%20headingStyle%3A%20'atx'%2C%0A%20%20%20%20%20%20hr%3A%20'---'%2C%0A%20%20%20%20%20%20bulletListMarker%3A%20'-'%2C%0A%20%20%20%20%20%20codeBlockStyle%3A%20'fenced'%2C%0A%20%20%20%20%20%20emDelimiter%3A%20'*'%2C%0A%20%20%7D).turndown(markdownify)%3B%0A%0A%20%20var%20date%20%3D%20new%20Date()%3B%0A%0A%20%20function%20convertDate(date)%20%7B%0A%20%20%20%20var%20yyyy%20%3D%20date.getFullYear().toString()%3B%0A%20%20%20%20var%20mm%20%3D%20(date.getMonth()%2B1).toString()%3B%0A%20%20%20%20var%20dd%20%20%3D%20date.getDate().toString()%3B%0A%20%20%20%20var%20mmChars%20%3D%20mm.split('')%3B%0A%20%20%20%20var%20ddChars%20%3D%20dd.split('')%3B%0A%20%20%20%20return%20yyyy%20%2B%20'-'%20%2B%20(mmChars%5B1%5D%3Fmm%3A%220%22%2BmmChars%5B0%5D)%20%2B%20'-'%20%2B%20(ddChars%5B1%5D%3Fdd%3A%220%22%2BddChars%5B0%5D)%3B%0A%20%20%7D%0A%0A%20%20const%20today%20%3D%20convertDate(date)%3B%0A%0A%20%20%2F*%20Fetch%20the%20meta%20author%20*%2F%0A%20%20var%20metaAuthorElement%20%3D%20document.querySelector(%22meta%5Bname%3D'author'%5D%22)%3B%0A%20%20var%20metaAuthor%20%3D%20metaAuthorElement%20%3F%20metaAuthorElement.getAttribute(%22content%22)%20%3A%20%22%22%3B%0A%0A%20%20%2F*%20Fetch%20site%20name%20as%20backup%20*%2F%0A%20%20var%20metaSiteNameElement%20%3D%20document.querySelector(%22meta%5Bname%3D'og%3Asite_name'%5D%22)%3B%0A%20%20var%20siteName%20%3D%20metaSiteNameElement%20%3F%20metaSiteNameElement.getAttribute(%22content%22)%20%3A%20%22%22%3B%0A%0A%20%20%2F*%20Check%20if%20there's%20an%20author%20and%20add%20brackets%20*%2F%0A%20%20var%20authorBrackets%20%3D%20%22%22%3B%0A%20%20if%20(byline%20%26%26%20byline.trim()%20!%3D%3D%20%22%22)%20%7B%0A%20%20%20%20%20%20authorBrackets%20%3D%20'%22%5B%5B%20'%20%2B%20byline%20%2B%20'%20%5D%5D%22'%3B%0A%20%20%7D%20else%20if%20(metaAuthor%20%26%26%20metaAuthor.trim()%20!%3D%3D%20%22%22)%20%7B%0A%20%20%20%20%20%20authorBrackets%20%3D%20'%22%5B%5B%20'%20%2B%20metaAuthor%20%2B%20'%20%5D%5D%22'%3B%0A%20%20%7D%20else%20if%20(siteName%20%26%26%20siteName.trim()%20!%3D%3D%20%22%22)%20%7B%0A%20%20%20%20%20%20authorBrackets%20%3D%20'%22%5B%5B%20'%20%2B%20siteName%20%2B%20'%20%5D%5D%22'%3B%0A%20%20%7D%0A%0A%20%20%2F*%20Try%20to%20get%20published%20date%20*%2F%0A%20%20var%20timeElement%20%3D%20document.querySelector(%22time%22)%3B%0A%20%20var%20publishedDate%20%3D%20timeElement%20%3F%20timeElement.getAttribute(%22datetime%22)%20%3A%20%22%22%3B%0A%0A%20%20if%20(publishedDate%20%26%26%20publishedDate.trim()%20!%3D%3D%20%22%22)%20%7B%0A%20%20%20%20%20%20var%20date%20%3D%20new%20Date(publishedDate)%3B%0A%20%20%20%20%20%20var%20year%20%3D%20date.getFullYear()%3B%0A%20%20%20%20%20%20var%20month%20%3D%20date.getMonth()%20%2B%201%3B%20%2F%2F%20Months%20are%200-based%20in%20JavaScript%0A%20%20%20%20%20%20var%20day%20%3D%20date.getDate()%3B%0A%0A%20%20%20%20%20%20%2F%2F%20Pad%20month%20and%20day%20with%20leading%20zeros%20if%20necessary%0A%20%20%20%20%20%20month%20%3D%20month%20%3C%2010%20%3F%20'0'%20%2B%20month%20%3A%20month%3B%0A%20%20%20%20%20%20day%20%3D%20day%20%3C%2010%20%3F%20'0'%20%2B%20day%20%3A%20day%3B%0A%0A%20%20%20%20%20%20var%20published%20%3D%20year%20%2B%20'-'%20%2B%20month%20%2B%20'-'%20%2B%20day%3B%0A%20%20%7D%20else%20%7B%0A%20%20%20%20%20%20var%20published%20%3D%20''%0A%20%20%7D%0A%0A%20%20%2F*%20YAML%20front%20matter%20as%20tags%20render%20cleaner%20with%20special%20chars%20%20*%2F%0A%20%20const%20fileContent%20%3D%20%0A%20%20%20%20%20%20'---%5Cn'%0A%20%20%20%20%20%20%2B%20'author%3A%20'%20%2B%20authorBrackets%20%2B%20'%5Cn'%0A%20%20%20%20%20%20%2B%20'title%3A%20%22'%20%2B%20title%20%2B%20'%22%5Cn'%0A%20%20%20%20%20%20%2B%20'source%3A%20'%20%2B%20document.URL%20%2B%20'%5Cn'%0A%20%20%20%20%20%20%2B%20'clipped%3A%20'%20%2B%20today%20%2B%20'%5Cn'%0A%20%20%20%20%20%20%2B%20'published%3A%20'%20%2B%20published%20%2B%20'%5Cn'%20%0A%20%20%20%20%20%20%2B%20'tags%3A%20%5B'%20%2B%20tags%20%2B%20'%5D%5Cn'%0A%20%20%20%20%20%20%2B%20'---%5Cn%5Cn'%0A%20%20%20%20%20%20%2B%20markdownBody%20%3B%0A%0A%20%20%2F*%20assemble%20URL%2C%20decrementing%20each%20time%2C%20until%20it%20does%20not%20exceed%20the%20max%20URL%20length%20for%20this%20browser%2C%20supposedly%202048%20but%20allow%20for%20a%20little%20error%20with%202030%20*%2F%0A%20%20contentLength%20%3D%202048%3B%0A%20%20maxURLLength%20%3D%202030%3B%0A%20%20decrement%20%3D%201%3B%0A%0A%20%20do%20%7B%0A%20%20hrefString%20%3D%20'obsidian%3A%2F%2Fnew%3F'%0A%20%20%20%20%20%20%2B%20'file%3D'%20%2B%20encodeURIComponent(folder%20%2B%20fileName)%0A%20%20%20%20%20%20%2B%20'%26content%3D'%20%2B%20encodeURIComponent(fileContent.substr(0%2CcontentLength-1))%0A%20%20%20%20%20%20%2B%20vaultName%20%3B%0A%20%20contentLength%20%3D%20contentLength%20-%20decrement%3B%0A%20%20%7D%20while%20(hrefString.length%20%3E%20maxURLLength)%3B%0A%0A%20%20document.location.href%20%3D%20hrefString%3B%0A%0A%7D)%7D)()%3B
  9. @kepano kepano revised this gist Jul 29, 2023. 1 changed file with 54 additions and 11 deletions.
    65 changes: 54 additions & 11 deletions obsidian-web-clipper.js
    Original file line number Diff line number Diff line change
    @@ -11,7 +11,17 @@ javascript: Promise.all([import('https://unpkg.com/[email protected]?module'), impo
    const folder = "";

    /* Optional tags */
    const tags = "#clippings";
    let tags = "clippings";

    /* Parse the site's meta keywords content into tags, if present */
    if (document.querySelector('meta[name="keywords" i]')) {
    var keywords = document.querySelector('meta[name="keywords" i]').getAttribute('content').split(',');

    keywords.forEach(function(keyword) {
    let tag = ' ' + keyword.split(' ').join('');
    tags += tag;
    });
    }

    function getSelectionHtml() {
    var html = "";
    @@ -87,16 +97,49 @@ javascript: Promise.all([import('https://unpkg.com/[email protected]?module'), impo

    const today = convertDate(date);

    /* Fetch the meta author */
    var metaAuthorElement = document.querySelector("meta[name='author']");
    var metaAuthor = metaAuthorElement ? metaAuthorElement.getAttribute("content") : "";

    /* Fetch site name as backup */
    var metaSiteNameElement = document.querySelector("meta[name='og:site_name']");
    var siteName = metaSiteNameElement ? metaSiteNameElement.getAttribute("content") : "";

    /* Check if there's an author and add brackets */
    var authorBrackets = "";
    if (byline && byline.trim() !== "") {
    authorBrackets = '"[[ ' + byline + ' ]]"';
    } else if (metaAuthor && metaAuthor.trim() !== "") {
    authorBrackets = '"[[ ' + metaAuthor + ' ]]"';
    } else if (siteName && siteName.trim() !== "") {
    authorBrackets = '"[[ ' + siteName + ' ]]"';
    }

    /* YAML front matter as tags render cleaner with special chars */
    const fileContent =
    "author:: " + byline + "\n"
    + "source:: [" + title + "](" + document.URL + ")\n"
    + "clipped:: [[" + today + "]]\n"
    + "published:: \n\n"
    + tags + "\n\n"
    '---\n'
    + 'author: ' + authorBrackets + '\n'
    + 'title: ' + title + '\n'
    + 'source: ' + document.URL + '\n'
    + 'clipped: ' + today + '\n'
    + 'published: \n'
    + 'tags: [' + tags + ']\n'
    + '---\n\n'
    + markdownBody ;

    document.location.href = "obsidian://new?"
    + "file=" + encodeURIComponent(folder + fileName)
    + "&content=" + encodeURIComponent(fileContent)
    + vaultName ;

    /* assemble URL, decrementing each time, until it does not exceed the max URL length for this browser, supposedly 2048 but allow for a little error with 2030 */
    contentLength = 2048;
    maxURLLength = 2030;
    decrement = 1;

    do {
    hrefString = 'obsidian://new?'
    + 'file=' + encodeURIComponent(folder + fileName)
    + '&content=' + encodeURIComponent(fileContent.substr(0,contentLength-1))
    + vaultName ;
    contentLength = contentLength - decrement;
    } while (hrefString.length > maxURLLength);

    document.location.href = hrefString;

    })
  10. Stephan Ango revised this gist May 1, 2022. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions readme.md
    Original file line number Diff line number Diff line change
    @@ -13,6 +13,8 @@ You can customize the output using the optional variables at the top, and the te
    ### Usage
    By default, clicking the bookmarklet creates a new Obsidian file from the main body of the article (similar to Readability view). Alternatively you can choose to create a file from a selection, by either selecting all (`CMD+A`), or just a portion of the page.

    Any images in the content will be embedded as external references. If you want to download images locally you can use the [Local Images plugin](https://github.com/aleksey-rezvov/obsidian-local-images) which allows you to download images for a note.

    ### Troubleshooting

    This bookmarklet may not work on all websites. If you run into issues, you can also try the [MarkDownload browser extension](https://forum.obsidian.md/t/markdownload-markdown-web-clipper/173) which provides similar functionality. You can troubleshoot issues by opening the Developer Console in your browser and checking if any errors appear when you click the bookmarklet. The most common error is that a website or the browser itself is blocking third party code execution. Unfortunately there is no good solve for that yet.
  11. Stephan Ango revised this gist Nov 2, 2021. No changes.
  12. Stephan Ango revised this gist Nov 2, 2021. No changes.
  13. Stephan Ango revised this gist Aug 14, 2021. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion readme.md
    Original file line number Diff line number Diff line change
    @@ -15,4 +15,4 @@ By default, clicking the bookmarklet creates a new Obsidian file from the main b

    ### Troubleshooting

    This bookmarklet may not work on all websites. If you run into issues, you can also try the [MarkDownload browser extension](https://forum.obsidian.md/t/markdownload-markdown-web-clipper/173) which provides similar functionality. You can also troubleshoot issues by opening the Developer Console in your browser and checking if any errors appear when you click the bookmarklet. The most common error is that a website or the browser itself is blocking third party code execution. Unfortunately there is no good solve for that yet.
    This bookmarklet may not work on all websites. If you run into issues, you can also try the [MarkDownload browser extension](https://forum.obsidian.md/t/markdownload-markdown-web-clipper/173) which provides similar functionality. You can troubleshoot issues by opening the Developer Console in your browser and checking if any errors appear when you click the bookmarklet. The most common error is that a website or the browser itself is blocking third party code execution. Unfortunately there is no good solve for that yet.
  14. Stephan Ango revised this gist Aug 14, 2021. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions readme.md
    Original file line number Diff line number Diff line change
    @@ -13,6 +13,6 @@ You can customize the output using the optional variables at the top, and the te
    ### Usage
    By default, clicking the bookmarklet creates a new Obsidian file from the main body of the article (similar to Readability view). Alternatively you can choose to create a file from a selection, by either selecting all (`CMD+A`), or just a portion of the page.

    ### Disclaimer
    ### Troubleshooting

    This bookmarklet may not work on all websites. If you run into issues, you can also try the [MarkDownload browser extension](https://forum.obsidian.md/t/markdownload-markdown-web-clipper/173) which provides similar functionality.
    This bookmarklet may not work on all websites. If you run into issues, you can also try the [MarkDownload browser extension](https://forum.obsidian.md/t/markdownload-markdown-web-clipper/173) which provides similar functionality. You can also troubleshoot issues by opening the Developer Console in your browser and checking if any errors appear when you click the bookmarklet. The most common error is that a website or the browser itself is blocking third party code execution. Unfortunately there is no good solve for that yet.
  15. Stephan Ango revised this gist Aug 9, 2021. 2 changed files with 2 additions and 2 deletions.
    2 changes: 1 addition & 1 deletion obsidian-web-clipper.js
    Original file line number Diff line number Diff line change
    @@ -96,7 +96,7 @@ javascript: Promise.all([import('https://unpkg.com/[email protected]?module'), impo
    + markdownBody ;

    document.location.href = "obsidian://new?"
    + "name=" + encodeURIComponent(folder + fileName)
    + "file=" + encodeURIComponent(folder + fileName)
    + "&content=" + encodeURIComponent(fileContent)
    + vaultName ;
    })
    2 changes: 1 addition & 1 deletion obsidian-web-clipper.min.js
    Original file line number Diff line number Diff line change
    @@ -1 +1 @@
    javascript:(function()%7Bjavascript%3A%20Promise.all(%5Bimport('https%3A%2F%2Funpkg.com%2Fturndown%406.0.0%3Fmodule')%2C%20import('https%3A%2F%2Funpkg.com%2F%40tehshrike%2Freadability%400.2.0')%2C%20%5D).then(async%20(%5B%7B%0A%20%20%20%20default%3A%20Turndown%0A%7D%2C%20%7B%0A%20%20%20%20default%3A%20Readability%0A%7D%5D)%20%3D%3E%20%7B%0A%0A%20%20%2F*%20Optional%20vault%20name%20*%2F%0A%20%20const%20vault%20%3D%20%22%22%3B%0A%0A%20%20%2F*%20Optional%20folder%20name%20such%20as%20%22Clippings%2F%22%20*%2F%0A%20%20const%20folder%20%3D%20%22%22%3B%0A%0A%20%20%2F*%20Optional%20tags%20%20*%2F%0A%20%20const%20tags%20%3D%20%22%23clippings%22%3B%0A%0A%20%20function%20getSelectionHtml()%20%7B%0A%20%20%20%20var%20html%20%3D%20%22%22%3B%0A%20%20%20%20if%20(typeof%20window.getSelection%20!%3D%20%22undefined%22)%20%7B%0A%20%20%20%20%20%20%20%20var%20sel%20%3D%20window.getSelection()%3B%0A%20%20%20%20%20%20%20%20if%20(sel.rangeCount)%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20var%20container%20%3D%20document.createElement(%22div%22)%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20for%20(var%20i%20%3D%200%2C%20len%20%3D%20sel.rangeCount%3B%20i%20%3C%20len%3B%20%2B%2Bi)%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20container.appendChild(sel.getRangeAt(i).cloneContents())%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%20%20%20%20html%20%3D%20container.innerHTML%3B%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%7D%20else%20if%20(typeof%20document.selection%20!%3D%20%22undefined%22)%20%7B%0A%20%20%20%20%20%20%20%20if%20(document.selection.type%20%3D%3D%20%22Text%22)%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20html%20%3D%20document.selection.createRange().htmlText%3B%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%7D%0A%20%20%20%20return%20html%3B%0A%20%20%7D%0A%0A%20%20const%20selection%20%3D%20getSelectionHtml()%3B%0A%0A%20%20const%20%7B%0A%20%20%20%20%20%20title%2C%0A%20%20%20%20%20%20byline%2C%0A%20%20%20%20%20%20content%0A%20%20%7D%20%3D%20new%20Readability(document.cloneNode(true)).parse()%3B%0A%0A%20%20function%20getFileName(fileName)%20%7B%0A%20%20%20%20var%20userAgent%20%3D%20window.navigator.userAgent%2C%0A%20%20%20%20%20%20%20%20platform%20%3D%20window.navigator.platform%2C%0A%20%20%20%20%20%20%20%20windowsPlatforms%20%3D%20%5B'Win32'%2C%20'Win64'%2C%20'Windows'%2C%20'WinCE'%5D%3B%0A%0A%20%20%20%20if%20(windowsPlatforms.indexOf(platform)%20!%3D%3D%20-1)%20%7B%0A%20%20%20%20%20%20fileName%20%3D%20fileName.replace('%3A'%2C%20'').replace(%2F%5B%2F%5C%5C%3F%25*%7C%22%3C%3E%5D%2Fg%2C%20'-')%3B%0A%20%20%20%20%7D%20else%20%7B%0A%20%20%20%20%20%20fileName%20%3D%20fileName.replace('%3A'%2C%20'').replace(%2F%5C%2F%2Fg%2C%20'-').replace(%2F%5C%5C%2Fg%2C%20'-')%3B%0A%20%20%20%20%7D%0A%20%20%20%20return%20fileName%3B%0A%20%20%7D%0A%20%20const%20fileName%20%3D%20getFileName(title)%3B%0A%0A%20%20if%20(selection)%20%7B%0A%20%20%20%20%20%20var%20markdownify%20%3D%20selection%3B%0A%20%20%7D%20else%20%7B%0A%20%20%20%20%20%20var%20markdownify%20%3D%20content%3B%0A%20%20%7D%0A%0A%20%20if%20(vault)%20%7B%0A%20%20%20%20%20%20var%20vaultName%20%3D%20'%26vault%3D'%20%2B%20encodeURIComponent(%60%24%7Bvault%7D%60)%3B%0A%20%20%7D%20else%20%7B%0A%20%20%20%20%20%20var%20vaultName%20%3D%20''%3B%0A%20%20%7D%0A%0A%20%20const%20markdownBody%20%3D%20new%20Turndown(%7B%0A%20%20%20%20%20%20headingStyle%3A%20'atx'%2C%0A%20%20%20%20%20%20hr%3A%20'---'%2C%0A%20%20%20%20%20%20bulletListMarker%3A%20'-'%2C%0A%20%20%20%20%20%20codeBlockStyle%3A%20'fenced'%2C%0A%20%20%20%20%20%20emDelimiter%3A%20'*'%2C%0A%20%20%7D).turndown(markdownify)%3B%0A%0A%20%20var%20date%20%3D%20new%20Date()%3B%0A%0A%20%20function%20convertDate(date)%20%7B%0A%20%20%20%20var%20yyyy%20%3D%20date.getFullYear().toString()%3B%0A%20%20%20%20var%20mm%20%3D%20(date.getMonth()%2B1).toString()%3B%0A%20%20%20%20var%20dd%20%20%3D%20date.getDate().toString()%3B%0A%20%20%20%20var%20mmChars%20%3D%20mm.split('')%3B%0A%20%20%20%20var%20ddChars%20%3D%20dd.split('')%3B%0A%20%20%20%20return%20yyyy%20%2B%20'-'%20%2B%20(mmChars%5B1%5D%3Fmm%3A%220%22%2BmmChars%5B0%5D)%20%2B%20'-'%20%2B%20(ddChars%5B1%5D%3Fdd%3A%220%22%2BddChars%5B0%5D)%3B%0A%20%20%7D%0A%0A%20%20const%20today%20%3D%20convertDate(date)%3B%0A%0A%20%20const%20fileContent%20%3D%20%0A%20%20%20%20%20%20%22author%3A%3A%20%22%20%2B%20byline%20%2B%20%22%5Cn%22%0A%20%20%20%20%20%20%2B%20%22source%3A%3A%20%5B%22%20%2B%20title%20%2B%20%22%5D(%22%20%2B%20document.URL%20%2B%20%22)%5Cn%22%0A%20%20%20%20%20%20%2B%20%22clipped%3A%3A%20%5B%5B%22%20%2B%20today%20%2B%20%22%5D%5D%5Cn%22%0A%20%20%20%20%20%20%2B%20%22published%3A%3A%20%5Cn%5Cn%22%20%0A%20%20%20%20%20%20%2B%20tags%20%2B%20%22%5Cn%5Cn%22%0A%20%20%20%20%20%20%2B%20markdownBody%20%3B%0A%20%20%0A%20%20document.location.href%20%3D%20%22obsidian%3A%2F%2Fnew%3F%22%0A%20%20%20%20%2B%20%22name%3D%22%20%2B%20encodeURIComponent(folder%20%2B%20fileName)%0A%20%20%20%20%2B%20%22%26content%3D%22%20%2B%20encodeURIComponent(fileContent)%0A%20%20%20%20%2B%20vaultName%20%3B%0A%7D)%7D)()%3B
    javascript:(function()%7Bjavascript%3A%20Promise.all(%5Bimport('https%3A%2F%2Funpkg.com%2Fturndown%406.0.0%3Fmodule')%2C%20import('https%3A%2F%2Funpkg.com%2F%40tehshrike%2Freadability%400.2.0')%2C%20%5D).then(async%20(%5B%7B%0A%20%20%20%20default%3A%20Turndown%0A%7D%2C%20%7B%0A%20%20%20%20default%3A%20Readability%0A%7D%5D)%20%3D%3E%20%7B%0A%0A%20%20%2F*%20Optional%20vault%20name%20*%2F%0A%20%20const%20vault%20%3D%20%22%22%3B%0A%0A%20%20%2F*%20Optional%20folder%20name%20such%20as%20%22Clippings%2F%22%20*%2F%0A%20%20const%20folder%20%3D%20%22%22%3B%0A%0A%20%20%2F*%20Optional%20tags%20%20*%2F%0A%20%20const%20tags%20%3D%20%22%23clippings%22%3B%0A%0A%20%20function%20getSelectionHtml()%20%7B%0A%20%20%20%20var%20html%20%3D%20%22%22%3B%0A%20%20%20%20if%20(typeof%20window.getSelection%20!%3D%20%22undefined%22)%20%7B%0A%20%20%20%20%20%20%20%20var%20sel%20%3D%20window.getSelection()%3B%0A%20%20%20%20%20%20%20%20if%20(sel.rangeCount)%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20var%20container%20%3D%20document.createElement(%22div%22)%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20for%20(var%20i%20%3D%200%2C%20len%20%3D%20sel.rangeCount%3B%20i%20%3C%20len%3B%20%2B%2Bi)%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20container.appendChild(sel.getRangeAt(i).cloneContents())%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%20%20%20%20html%20%3D%20container.innerHTML%3B%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%7D%20else%20if%20(typeof%20document.selection%20!%3D%20%22undefined%22)%20%7B%0A%20%20%20%20%20%20%20%20if%20(document.selection.type%20%3D%3D%20%22Text%22)%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20html%20%3D%20document.selection.createRange().htmlText%3B%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%7D%0A%20%20%20%20return%20html%3B%0A%20%20%7D%0A%0A%20%20const%20selection%20%3D%20getSelectionHtml()%3B%0A%0A%20%20const%20%7B%0A%20%20%20%20%20%20title%2C%0A%20%20%20%20%20%20byline%2C%0A%20%20%20%20%20%20content%0A%20%20%7D%20%3D%20new%20Readability(document.cloneNode(true)).parse()%3B%0A%0A%20%20function%20getFileName(fileName)%20%7B%0A%20%20%20%20var%20userAgent%20%3D%20window.navigator.userAgent%2C%0A%20%20%20%20%20%20%20%20platform%20%3D%20window.navigator.platform%2C%0A%20%20%20%20%20%20%20%20windowsPlatforms%20%3D%20%5B'Win32'%2C%20'Win64'%2C%20'Windows'%2C%20'WinCE'%5D%3B%0A%0A%20%20%20%20if%20(windowsPlatforms.indexOf(platform)%20!%3D%3D%20-1)%20%7B%0A%20%20%20%20%20%20fileName%20%3D%20fileName.replace('%3A'%2C%20'').replace(%2F%5B%2F%5C%5C%3F%25*%7C%22%3C%3E%5D%2Fg%2C%20'-')%3B%0A%20%20%20%20%7D%20else%20%7B%0A%20%20%20%20%20%20fileName%20%3D%20fileName.replace('%3A'%2C%20'').replace(%2F%5C%2F%2Fg%2C%20'-').replace(%2F%5C%5C%2Fg%2C%20'-')%3B%0A%20%20%20%20%7D%0A%20%20%20%20return%20fileName%3B%0A%20%20%7D%0A%20%20const%20fileName%20%3D%20getFileName(title)%3B%0A%0A%20%20if%20(selection)%20%7B%0A%20%20%20%20%20%20var%20markdownify%20%3D%20selection%3B%0A%20%20%7D%20else%20%7B%0A%20%20%20%20%20%20var%20markdownify%20%3D%20content%3B%0A%20%20%7D%0A%0A%20%20if%20(vault)%20%7B%0A%20%20%20%20%20%20var%20vaultName%20%3D%20'%26vault%3D'%20%2B%20encodeURIComponent(%60%24%7Bvault%7D%60)%3B%0A%20%20%7D%20else%20%7B%0A%20%20%20%20%20%20var%20vaultName%20%3D%20''%3B%0A%20%20%7D%0A%0A%20%20const%20markdownBody%20%3D%20new%20Turndown(%7B%0A%20%20%20%20%20%20headingStyle%3A%20'atx'%2C%0A%20%20%20%20%20%20hr%3A%20'---'%2C%0A%20%20%20%20%20%20bulletListMarker%3A%20'-'%2C%0A%20%20%20%20%20%20codeBlockStyle%3A%20'fenced'%2C%0A%20%20%20%20%20%20emDelimiter%3A%20'*'%2C%0A%20%20%7D).turndown(markdownify)%3B%0A%0A%20%20var%20date%20%3D%20new%20Date()%3B%0A%0A%20%20function%20convertDate(date)%20%7B%0A%20%20%20%20var%20yyyy%20%3D%20date.getFullYear().toString()%3B%0A%20%20%20%20var%20mm%20%3D%20(date.getMonth()%2B1).toString()%3B%0A%20%20%20%20var%20dd%20%20%3D%20date.getDate().toString()%3B%0A%20%20%20%20var%20mmChars%20%3D%20mm.split('')%3B%0A%20%20%20%20var%20ddChars%20%3D%20dd.split('')%3B%0A%20%20%20%20return%20yyyy%20%2B%20'-'%20%2B%20(mmChars%5B1%5D%3Fmm%3A%220%22%2BmmChars%5B0%5D)%20%2B%20'-'%20%2B%20(ddChars%5B1%5D%3Fdd%3A%220%22%2BddChars%5B0%5D)%3B%0A%20%20%7D%0A%0A%20%20const%20today%20%3D%20convertDate(date)%3B%0A%0A%20%20const%20fileContent%20%3D%20%0A%20%20%20%20%20%20%22author%3A%3A%20%22%20%2B%20byline%20%2B%20%22%5Cn%22%0A%20%20%20%20%20%20%2B%20%22source%3A%3A%20%5B%22%20%2B%20title%20%2B%20%22%5D(%22%20%2B%20document.URL%20%2B%20%22)%5Cn%22%0A%20%20%20%20%20%20%2B%20%22clipped%3A%3A%20%5B%5B%22%20%2B%20today%20%2B%20%22%5D%5D%5Cn%22%0A%20%20%20%20%20%20%2B%20%22published%3A%3A%20%5Cn%5Cn%22%20%0A%20%20%20%20%20%20%2B%20tags%20%2B%20%22%5Cn%5Cn%22%0A%20%20%20%20%20%20%2B%20markdownBody%20%3B%0A%20%20%0A%20%20document.location.href%20%3D%20%22obsidian%3A%2F%2Fnew%3F%22%0A%20%20%20%20%2B%20%22file%3D%22%20%2B%20encodeURIComponent(folder%20%2B%20fileName)%0A%20%20%20%20%2B%20%22%26content%3D%22%20%2B%20encodeURIComponent(fileContent)%0A%20%20%20%20%2B%20vaultName%20%3B%0A%7D)%7D)()%3B
  16. Stephan Ango revised this gist Aug 8, 2021. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions readme.md
    Original file line number Diff line number Diff line change
    @@ -6,13 +6,13 @@ By [@kepano](https://www.twitter.com/kepano)
    You can find a demo of this bookmarklet [on YouTube](https://www.youtube.com/watch?v=Vy1MdjickAI)

    ### Installation
    Create a new bookmark in your browser, then copy/paste the code below into the URL field.
    Create a new bookmark in your browser, then copy/paste the minified code below into the URL field.

    You can customize the output using the optional variables at the top, and the template at the bottom. The default template is designed for use with the Dataview plugin. If you make changes I recommend using [Bookmarklet Maker](https://caiorss.github.io/bookmarklet-maker/) to minify and URI encode the bookmarklet.

    ### Usage
    By default, clicking the bookmarklet creates a new Obsidian file from the main body of the article (similar to Readability view). Alternatively you can choose to create a file from a selection, by either selecting all (`CMD+A`), or just a portion of the page.

    You can customize the output using the optional variables at the top, and the template at the bottom. The default template is designed for use with the Dataview plugin. If you make changes I recommend using [Bookmarklet Maker](https://caiorss.github.io/bookmarklet-maker/) to minify and URI encode the bookmarklet.

    ### Disclaimer

    This bookmarklet may not work on all websites. If you run into issues, you can also try the [MarkDownload browser extension](https://forum.obsidian.md/t/markdownload-markdown-web-clipper/173) which provides similar functionality.
  17. Stephan Ango revised this gist Aug 8, 2021. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion readme.md
    Original file line number Diff line number Diff line change
    @@ -11,7 +11,7 @@ Create a new bookmark in your browser, then copy/paste the code below into the U
    ### Usage
    By default, clicking the bookmarklet creates a new Obsidian file from the main body of the article (similar to Readability view). Alternatively you can choose to create a file from a selection, by either selecting all (`CMD+A`), or just a portion of the page.

    You can customize the output using the optional variables at the top, and the template at the bottom. The default template is designed for use with the Dataview plugin.
    You can customize the output using the optional variables at the top, and the template at the bottom. The default template is designed for use with the Dataview plugin. If you make changes I recommend using [Bookmarklet Maker](https://caiorss.github.io/bookmarklet-maker/) to minify and URI encode the bookmarklet.

    ### Disclaimer

  18. Stephan Ango revised this gist Aug 8, 2021. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion obsidian-web-clipper.min.js
    Original file line number Diff line number Diff line change
    @@ -1 +1 @@
    javascript:(function()%7BPromise.all(%5Bimport(%22https%3A%2F%2Funpkg.com%2Fturndown%406.0.0%3Fmodule%22)%2Cimport(%22https%3A%2F%2Funpkg.com%2F%40tehshrike%2Freadability%400.2.0%22)%5D).then(async(%5B%7Bdefault%3Ae%7D%2C%7Bdefault%3An%7D%5D)%3D%3E%7Bconst%20t%3Dfunction()%7Bvar%20e%3D%22%22%3Bif(void%200!%3D%3Dwindow.getSelection)%7Bvar%20n%3Dwindow.getSelection()%3Bif(n.rangeCount)%7Bfor(var%20t%3Ddocument.createElement(%22div%22)%2Co%3D0%2Ci%3Dn.rangeCount%3Bo%3Ci%3B%2B%2Bo)t.appendChild(n.getRangeAt(o).cloneContents())%3Be%3Dt.innerHTML%7D%7Delse%20void%200!%3D%3Ddocument.selection%26%26%22Text%22%3D%3Ddocument.selection.type%26%26(e%3Ddocument.selection.createRange().htmlText)%3Breturn%20e%7D()%2C%7Btitle%3Ao%2Cbyline%3Ai%2Ccontent%3Ar%7D%3Dnew%20n(document.cloneNode(!0)).parse()%3Bconst%20a%3Dfunction(e)%7Bwindow.navigator.userAgent%3Bvar%20n%3Dwindow.navigator.platform%3Breturn%20e%3D-1!%3D%3D%5B%22Win32%22%2C%22Win64%22%2C%22Windows%22%2C%22WinCE%22%5D.indexOf(n)%3Fe.replace(%22%3A%22%2C%22%22).replace(%2F%5B%5C%2F%5C%5C%3F%25*%7C%22%3C%3E%5D%2Fg%2C%22-%22)%3Ae.replace(%22%3A%22%2C%22%22).replace(%2F%5C%2F%2Fg%2C%22-%22).replace(%2F%5C%5C%2Fg%2C%22-%22)%7D(o)%3Bif(t)var%20c%3Dt%3Belse%20c%3Dr%3Bvar%20l%3D%22%22%3Bconst%20d%3Dnew%20e(%7BheadingStyle%3A%22atx%22%2Chr%3A%22---%22%2CbulletListMarker%3A%22-%22%2CcodeBlockStyle%3A%22fenced%22%2CemDelimiter%3A%22*%22%7D).turndown(c)%3Bconst%20u%3Dfunction(e)%7Bvar%20n%3De.getFullYear().toString()%2Ct%3D(e.getMonth()%2B1).toString()%2Co%3De.getDate().toString()%2Ci%3Dt.split(%22%22)%2Cr%3Do.split(%22%22)%3Breturn%20n%2B%22-%22%2B(i%5B1%5D%3Ft%3A%220%22%2Bi%5B0%5D)%2B%22-%22%2B(r%5B1%5D%3Fo%3A%220%22%2Br%5B0%5D)%7D(new%20Date)%2Cp%3D%22author%3A%3A%20%22%2Bi%2B%22%5Cnsource%3A%3A%20%5B%22%2Bo%2B%22%5D(%22%2Bdocument.URL%2B%22)%5Cnclipped%3A%3A%20%5B%5B%22%2Bu%2B%22%5D%5D%5Cnpublished%3A%3A%20%5Cn%5Cn%23clippings%5Cn%5Cn%22%2Bd%3Bwindow.location.href%3D%22obsidian%3A%2F%2Fnew%3Fname%3D%22%2BencodeURIComponent(%22%22%2Ba)%2B%22%26content%3D%22%2BencodeURIComponent(p)%2Bl%7D)%3B%7D)()%3B
    javascript:(function()%7Bjavascript%3A%20Promise.all(%5Bimport('https%3A%2F%2Funpkg.com%2Fturndown%406.0.0%3Fmodule')%2C%20import('https%3A%2F%2Funpkg.com%2F%40tehshrike%2Freadability%400.2.0')%2C%20%5D).then(async%20(%5B%7B%0A%20%20%20%20default%3A%20Turndown%0A%7D%2C%20%7B%0A%20%20%20%20default%3A%20Readability%0A%7D%5D)%20%3D%3E%20%7B%0A%0A%20%20%2F*%20Optional%20vault%20name%20*%2F%0A%20%20const%20vault%20%3D%20%22%22%3B%0A%0A%20%20%2F*%20Optional%20folder%20name%20such%20as%20%22Clippings%2F%22%20*%2F%0A%20%20const%20folder%20%3D%20%22%22%3B%0A%0A%20%20%2F*%20Optional%20tags%20%20*%2F%0A%20%20const%20tags%20%3D%20%22%23clippings%22%3B%0A%0A%20%20function%20getSelectionHtml()%20%7B%0A%20%20%20%20var%20html%20%3D%20%22%22%3B%0A%20%20%20%20if%20(typeof%20window.getSelection%20!%3D%20%22undefined%22)%20%7B%0A%20%20%20%20%20%20%20%20var%20sel%20%3D%20window.getSelection()%3B%0A%20%20%20%20%20%20%20%20if%20(sel.rangeCount)%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20var%20container%20%3D%20document.createElement(%22div%22)%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20for%20(var%20i%20%3D%200%2C%20len%20%3D%20sel.rangeCount%3B%20i%20%3C%20len%3B%20%2B%2Bi)%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20container.appendChild(sel.getRangeAt(i).cloneContents())%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%20%20%20%20html%20%3D%20container.innerHTML%3B%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%7D%20else%20if%20(typeof%20document.selection%20!%3D%20%22undefined%22)%20%7B%0A%20%20%20%20%20%20%20%20if%20(document.selection.type%20%3D%3D%20%22Text%22)%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20html%20%3D%20document.selection.createRange().htmlText%3B%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%7D%0A%20%20%20%20return%20html%3B%0A%20%20%7D%0A%0A%20%20const%20selection%20%3D%20getSelectionHtml()%3B%0A%0A%20%20const%20%7B%0A%20%20%20%20%20%20title%2C%0A%20%20%20%20%20%20byline%2C%0A%20%20%20%20%20%20content%0A%20%20%7D%20%3D%20new%20Readability(document.cloneNode(true)).parse()%3B%0A%0A%20%20function%20getFileName(fileName)%20%7B%0A%20%20%20%20var%20userAgent%20%3D%20window.navigator.userAgent%2C%0A%20%20%20%20%20%20%20%20platform%20%3D%20window.navigator.platform%2C%0A%20%20%20%20%20%20%20%20windowsPlatforms%20%3D%20%5B'Win32'%2C%20'Win64'%2C%20'Windows'%2C%20'WinCE'%5D%3B%0A%0A%20%20%20%20if%20(windowsPlatforms.indexOf(platform)%20!%3D%3D%20-1)%20%7B%0A%20%20%20%20%20%20fileName%20%3D%20fileName.replace('%3A'%2C%20'').replace(%2F%5B%2F%5C%5C%3F%25*%7C%22%3C%3E%5D%2Fg%2C%20'-')%3B%0A%20%20%20%20%7D%20else%20%7B%0A%20%20%20%20%20%20fileName%20%3D%20fileName.replace('%3A'%2C%20'').replace(%2F%5C%2F%2Fg%2C%20'-').replace(%2F%5C%5C%2Fg%2C%20'-')%3B%0A%20%20%20%20%7D%0A%20%20%20%20return%20fileName%3B%0A%20%20%7D%0A%20%20const%20fileName%20%3D%20getFileName(title)%3B%0A%0A%20%20if%20(selection)%20%7B%0A%20%20%20%20%20%20var%20markdownify%20%3D%20selection%3B%0A%20%20%7D%20else%20%7B%0A%20%20%20%20%20%20var%20markdownify%20%3D%20content%3B%0A%20%20%7D%0A%0A%20%20if%20(vault)%20%7B%0A%20%20%20%20%20%20var%20vaultName%20%3D%20'%26vault%3D'%20%2B%20encodeURIComponent(%60%24%7Bvault%7D%60)%3B%0A%20%20%7D%20else%20%7B%0A%20%20%20%20%20%20var%20vaultName%20%3D%20''%3B%0A%20%20%7D%0A%0A%20%20const%20markdownBody%20%3D%20new%20Turndown(%7B%0A%20%20%20%20%20%20headingStyle%3A%20'atx'%2C%0A%20%20%20%20%20%20hr%3A%20'---'%2C%0A%20%20%20%20%20%20bulletListMarker%3A%20'-'%2C%0A%20%20%20%20%20%20codeBlockStyle%3A%20'fenced'%2C%0A%20%20%20%20%20%20emDelimiter%3A%20'*'%2C%0A%20%20%7D).turndown(markdownify)%3B%0A%0A%20%20var%20date%20%3D%20new%20Date()%3B%0A%0A%20%20function%20convertDate(date)%20%7B%0A%20%20%20%20var%20yyyy%20%3D%20date.getFullYear().toString()%3B%0A%20%20%20%20var%20mm%20%3D%20(date.getMonth()%2B1).toString()%3B%0A%20%20%20%20var%20dd%20%20%3D%20date.getDate().toString()%3B%0A%20%20%20%20var%20mmChars%20%3D%20mm.split('')%3B%0A%20%20%20%20var%20ddChars%20%3D%20dd.split('')%3B%0A%20%20%20%20return%20yyyy%20%2B%20'-'%20%2B%20(mmChars%5B1%5D%3Fmm%3A%220%22%2BmmChars%5B0%5D)%20%2B%20'-'%20%2B%20(ddChars%5B1%5D%3Fdd%3A%220%22%2BddChars%5B0%5D)%3B%0A%20%20%7D%0A%0A%20%20const%20today%20%3D%20convertDate(date)%3B%0A%0A%20%20const%20fileContent%20%3D%20%0A%20%20%20%20%20%20%22author%3A%3A%20%22%20%2B%20byline%20%2B%20%22%5Cn%22%0A%20%20%20%20%20%20%2B%20%22source%3A%3A%20%5B%22%20%2B%20title%20%2B%20%22%5D(%22%20%2B%20document.URL%20%2B%20%22)%5Cn%22%0A%20%20%20%20%20%20%2B%20%22clipped%3A%3A%20%5B%5B%22%20%2B%20today%20%2B%20%22%5D%5D%5Cn%22%0A%20%20%20%20%20%20%2B%20%22published%3A%3A%20%5Cn%5Cn%22%20%0A%20%20%20%20%20%20%2B%20tags%20%2B%20%22%5Cn%5Cn%22%0A%20%20%20%20%20%20%2B%20markdownBody%20%3B%0A%20%20%0A%20%20document.location.href%20%3D%20%22obsidian%3A%2F%2Fnew%3F%22%0A%20%20%20%20%2B%20%22name%3D%22%20%2B%20encodeURIComponent(folder%20%2B%20fileName)%0A%20%20%20%20%2B%20%22%26content%3D%22%20%2B%20encodeURIComponent(fileContent)%0A%20%20%20%20%2B%20vaultName%20%3B%0A%7D)%7D)()%3B
  19. Stephan Ango revised this gist Aug 8, 2021. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions obsidian-web-clipper.min.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1 @@
    javascript:(function()%7BPromise.all(%5Bimport(%22https%3A%2F%2Funpkg.com%2Fturndown%406.0.0%3Fmodule%22)%2Cimport(%22https%3A%2F%2Funpkg.com%2F%40tehshrike%2Freadability%400.2.0%22)%5D).then(async(%5B%7Bdefault%3Ae%7D%2C%7Bdefault%3An%7D%5D)%3D%3E%7Bconst%20t%3Dfunction()%7Bvar%20e%3D%22%22%3Bif(void%200!%3D%3Dwindow.getSelection)%7Bvar%20n%3Dwindow.getSelection()%3Bif(n.rangeCount)%7Bfor(var%20t%3Ddocument.createElement(%22div%22)%2Co%3D0%2Ci%3Dn.rangeCount%3Bo%3Ci%3B%2B%2Bo)t.appendChild(n.getRangeAt(o).cloneContents())%3Be%3Dt.innerHTML%7D%7Delse%20void%200!%3D%3Ddocument.selection%26%26%22Text%22%3D%3Ddocument.selection.type%26%26(e%3Ddocument.selection.createRange().htmlText)%3Breturn%20e%7D()%2C%7Btitle%3Ao%2Cbyline%3Ai%2Ccontent%3Ar%7D%3Dnew%20n(document.cloneNode(!0)).parse()%3Bconst%20a%3Dfunction(e)%7Bwindow.navigator.userAgent%3Bvar%20n%3Dwindow.navigator.platform%3Breturn%20e%3D-1!%3D%3D%5B%22Win32%22%2C%22Win64%22%2C%22Windows%22%2C%22WinCE%22%5D.indexOf(n)%3Fe.replace(%22%3A%22%2C%22%22).replace(%2F%5B%5C%2F%5C%5C%3F%25*%7C%22%3C%3E%5D%2Fg%2C%22-%22)%3Ae.replace(%22%3A%22%2C%22%22).replace(%2F%5C%2F%2Fg%2C%22-%22).replace(%2F%5C%5C%2Fg%2C%22-%22)%7D(o)%3Bif(t)var%20c%3Dt%3Belse%20c%3Dr%3Bvar%20l%3D%22%22%3Bconst%20d%3Dnew%20e(%7BheadingStyle%3A%22atx%22%2Chr%3A%22---%22%2CbulletListMarker%3A%22-%22%2CcodeBlockStyle%3A%22fenced%22%2CemDelimiter%3A%22*%22%7D).turndown(c)%3Bconst%20u%3Dfunction(e)%7Bvar%20n%3De.getFullYear().toString()%2Ct%3D(e.getMonth()%2B1).toString()%2Co%3De.getDate().toString()%2Ci%3Dt.split(%22%22)%2Cr%3Do.split(%22%22)%3Breturn%20n%2B%22-%22%2B(i%5B1%5D%3Ft%3A%220%22%2Bi%5B0%5D)%2B%22-%22%2B(r%5B1%5D%3Fo%3A%220%22%2Br%5B0%5D)%7D(new%20Date)%2Cp%3D%22author%3A%3A%20%22%2Bi%2B%22%5Cnsource%3A%3A%20%5B%22%2Bo%2B%22%5D(%22%2Bdocument.URL%2B%22)%5Cnclipped%3A%3A%20%5B%5B%22%2Bu%2B%22%5D%5D%5Cnpublished%3A%3A%20%5Cn%5Cn%23clippings%5Cn%5Cn%22%2Bd%3Bwindow.location.href%3D%22obsidian%3A%2F%2Fnew%3Fname%3D%22%2BencodeURIComponent(%22%22%2Ba)%2B%22%26content%3D%22%2BencodeURIComponent(p)%2Bl%7D)%3B%7D)()%3B
  20. Stephan Ango revised this gist Aug 7, 2021. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions readme.md
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,5 @@
    By [@kepano](https://www.twitter.com/kepano)

    🎉 Support my work at [buymeacoffee.com/kepano](https://www.buymeacoffee.com/kepano)

    ### Demo
  21. Stephan Ango revised this gist Aug 7, 2021. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion readme.md
    Original file line number Diff line number Diff line change
    @@ -14,4 +14,4 @@ You can customize the output using the optional variables at the top, and the te

    ### Disclaimer

    Note that this bookmarklet may not work on all websites. If you run into issues, you can also try the [MarkDownload browser extension](https://forum.obsidian.md/t/markdownload-markdown-web-clipper/173) which provides similar functionality.
    This bookmarklet may not work on all websites. If you run into issues, you can also try the [MarkDownload browser extension](https://forum.obsidian.md/t/markdownload-markdown-web-clipper/173) which provides similar functionality.
  22. Stephan Ango revised this gist Aug 7, 2021. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions readme.md
    Original file line number Diff line number Diff line change
    @@ -10,6 +10,8 @@ Create a new bookmark in your browser, then copy/paste the code below into the U
    ### Usage
    By default, clicking the bookmarklet creates a new Obsidian file from the main body of the article (similar to Readability view). Alternatively you can choose to create a file from a selection, by either selecting all (`CMD+A`), or just a portion of the page.

    You can customize the output using the optional variables at the top, and the template at the bottom. The default template is designed for use with the Dataview plugin.

    ### Disclaimer

    Note that this bookmarklet may not work on all websites. If you run into issues, you can also try the [MarkDownload browser extension](https://forum.obsidian.md/t/markdownload-markdown-web-clipper/173) which provides similar functionality.
  23. Stephan Ango revised this gist Aug 7, 2021. 1 changed file with 4 additions and 4 deletions.
    8 changes: 4 additions & 4 deletions readme.md
    Original file line number Diff line number Diff line change
    @@ -1,15 +1,15 @@
    By [@kepano](https://www.twitter.com/kepano)
    🎉 Support my work at [buymeacoffee.com/kepano](https://www.buymeacoffee.com/kepano)

    ## Demo
    ### Demo
    You can find a demo of this bookmarklet [on YouTube](https://www.youtube.com/watch?v=Vy1MdjickAI)

    ## Installation
    ### Installation
    Create a new bookmark in your browser, then copy/paste the code below into the URL field.

    ## Usage
    ### Usage
    By default, clicking the bookmarklet creates a new Obsidian file from the main body of the article (similar to Readability view). Alternatively you can choose to create a file from a selection, by either selecting all (`CMD+A`), or just a portion of the page.

    ## Disclaimer
    ### Disclaimer

    Note that this bookmarklet may not work on all websites. If you run into issues, you can also try the [MarkDownload browser extension](https://forum.obsidian.md/t/markdownload-markdown-web-clipper/173) which provides similar functionality.
  24. Stephan Ango revised this gist Aug 7, 2021. 1 changed file with 8 additions and 2 deletions.
    10 changes: 8 additions & 2 deletions readme.md
    Original file line number Diff line number Diff line change
    @@ -1,9 +1,15 @@
    By [@kepano](https://www.twitter.com/kepano)
    🎉 Support my work at [buymeacoffee.com/kepano](https://www.buymeacoffee.com/kepano)

    ## Demo
    You can find a demo of this bookmarklet [on YouTube](https://www.youtube.com/watch?v=Vy1MdjickAI)

    To use it, create a new bookmark in your browser, then copy/paste the code below into the URL field.
    ## Installation
    Create a new bookmark in your browser, then copy/paste the code below into the URL field.

    Support my work at [buymeacoffee.com/kepano](https://www.buymeacoffee.com/kepano)
    ## Usage
    By default, clicking the bookmarklet creates a new Obsidian file from the main body of the article (similar to Readability view). Alternatively you can choose to create a file from a selection, by either selecting all (`CMD+A`), or just a portion of the page.

    ## Disclaimer

    Note that this bookmarklet may not work on all websites. If you run into issues, you can also try the [MarkDownload browser extension](https://forum.obsidian.md/t/markdownload-markdown-web-clipper/173) which provides similar functionality.
  25. Stephan Ango revised this gist Aug 7, 2021. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions obsidian-web-clipper.js
    Original file line number Diff line number Diff line change
    @@ -61,7 +61,7 @@ javascript: Promise.all([import('https://unpkg.com/[email protected]?module'), impo
    }

    if (vault) {
    var vaultName = `&vault=${vault}`
    var vaultName = '&vault=' + encodeURIComponent(`${vault}`);
    } else {
    var vaultName = '';
    }
    @@ -96,7 +96,7 @@ javascript: Promise.all([import('https://unpkg.com/[email protected]?module'), impo
    + markdownBody ;

    document.location.href = "obsidian://new?"
    + "name=" + folder + fileName
    + "name=" + encodeURIComponent(folder + fileName)
    + "&content=" + encodeURIComponent(fileContent)
    + vaultName ;
    })
  26. Stephan Ango revised this gist Aug 7, 2021. 1 changed file with 81 additions and 48 deletions.
    129 changes: 81 additions & 48 deletions obsidian-web-clipper.js
    Original file line number Diff line number Diff line change
    @@ -4,66 +4,99 @@ javascript: Promise.all([import('https://unpkg.com/[email protected]?module'), impo
    default: Readability
    }]) => {

    function getSelectionHtml() {
    var html = "";
    if (typeof window.getSelection != "undefined") {
    var sel = window.getSelection();
    if (sel.rangeCount) {
    var container = document.createElement("div");
    for (var i = 0, len = sel.rangeCount; i < len; ++i) {
    container.appendChild(sel.getRangeAt(i).cloneContents());
    }
    html = container.innerHTML;
    }
    } else if (typeof document.selection != "undefined") {
    if (document.selection.type == "Text") {
    html = document.selection.createRange().htmlText;
    /* Optional vault name */
    const vault = "";

    /* Optional folder name such as "Clippings/" */
    const folder = "";

    /* Optional tags */
    const tags = "#clippings";

    function getSelectionHtml() {
    var html = "";
    if (typeof window.getSelection != "undefined") {
    var sel = window.getSelection();
    if (sel.rangeCount) {
    var container = document.createElement("div");
    for (var i = 0, len = sel.rangeCount; i < len; ++i) {
    container.appendChild(sel.getRangeAt(i).cloneContents());
    }
    html = container.innerHTML;
    }
    } else if (typeof document.selection != "undefined") {
    if (document.selection.type == "Text") {
    html = document.selection.createRange().htmlText;
    }
    return html;
    }
    return html;
    }

    const selection = getSelectionHtml();
    const selection = getSelectionHtml();

    const {
    title,
    byline,
    content
    } = new Readability(document.cloneNode(true)).parse();
    const {
    title,
    byline,
    content
    } = new Readability(document.cloneNode(true)).parse();

    const titleUri = title.replace(':', '').replace(/\//g, '-').replace(/\\/g, '-');
    function getFileName(fileName) {
    var userAgent = window.navigator.userAgent,
    platform = window.navigator.platform,
    windowsPlatforms = ['Win32', 'Win64', 'Windows', 'WinCE'];

    if (selection) {
    var markdownify = selection;
    if (windowsPlatforms.indexOf(platform) !== -1) {
    fileName = fileName.replace(':', '').replace(/[/\\?%*|"<>]/g, '-');
    } else {
    var markdownify = content;
    fileName = fileName.replace(':', '').replace(/\//g, '-').replace(/\\/g, '-');
    }
    return fileName;
    }
    const fileName = getFileName(title);

    const markdown = new Turndown({
    headingStyle: 'atx',
    hr: '---',
    bulletListMarker: '-',
    codeBlockStyle: 'fenced',
    emDelimiter: '*',
    }).turndown(markdownify);
    if (selection) {
    var markdownify = selection;
    } else {
    var markdownify = content;
    }

    var date = new Date();
    if (vault) {
    var vaultName = `&vault=${vault}`
    } else {
    var vaultName = '';
    }

    function convertDate(date) {
    var yyyy = date.getFullYear().toString();
    var mm = (date.getMonth()+1).toString();
    var dd = date.getDate().toString();
    var mmChars = mm.split('');
    var ddChars = dd.split('');
    return yyyy + '-' + (mmChars[1]?mm:"0"+mmChars[0]) + '-' + (ddChars[1]?dd:"0"+ddChars[0]);
    }
    const markdownBody = new Turndown({
    headingStyle: 'atx',
    hr: '---',
    bulletListMarker: '-',
    codeBlockStyle: 'fenced',
    emDelimiter: '*',
    }).turndown(markdownify);

    var date = new Date();

    function convertDate(date) {
    var yyyy = date.getFullYear().toString();
    var mm = (date.getMonth()+1).toString();
    var dd = date.getDate().toString();
    var mmChars = mm.split('');
    var ddChars = dd.split('');
    return yyyy + '-' + (mmChars[1]?mm:"0"+mmChars[0]) + '-' + (ddChars[1]?dd:"0"+ddChars[0]);
    }

    const today = convertDate(date);
    const today = convertDate(date);

    const obsidian = `author:: ${byline}\nsource:: [${title}](${document.URL})\nclipped:: [[${today}]]\npublished:: \n\n#clippings\n\n${markdown}`;

    window.location.href = "obsidian://new?"
    + "name=" + titleUri
    + "&content="
    + encodeURIComponent(obsidian) + "" ;
    const fileContent =
    "author:: " + byline + "\n"
    + "source:: [" + title + "](" + document.URL + ")\n"
    + "clipped:: [[" + today + "]]\n"
    + "published:: \n\n"
    + tags + "\n\n"
    + markdownBody ;

    document.location.href = "obsidian://new?"
    + "name=" + folder + fileName
    + "&content=" + encodeURIComponent(fileContent)
    + vaultName ;
    })
  27. Stephan Ango revised this gist Aug 7, 2021. 2 changed files with 1 addition and 2 deletions.
    1 change: 0 additions & 1 deletion obsidian-web-clipper.min.js
    Original file line number Diff line number Diff line change
    @@ -1 +0,0 @@
    javascript:(function()%7BPromise.all(%5Bimport(%22https%3A%2F%2Funpkg.com%2Fturndown%406.0.0%3Fmodule%22)%2Cimport(%22https%3A%2F%2Funpkg.com%2F%40tehshrike%2Freadability%400.2.0%22)%5D).then(async(%5B%7Bdefault%3Ae%7D%2C%7Bdefault%3At%7D%5D)%3D%3E%7Bconst%20n%3Dfunction()%7Bvar%20e%3D%22%22%3Bif(void%200!%3D%3Dwindow.getSelection)%7Bvar%20t%3Dwindow.getSelection()%3Bif(t.rangeCount)%7Bfor(var%20n%3Ddocument.createElement(%22div%22)%2Co%3D0%2Ci%3Dt.rangeCount%3Bo%3Ci%3B%2B%2Bo)n.appendChild(t.getRangeAt(o).cloneContents())%3Be%3Dn.innerHTML%7D%7Delse%20void%200!%3D%3Ddocument.selection%26%26%22Text%22%3D%3Ddocument.selection.type%26%26(e%3Ddocument.selection.createRange().htmlText)%3Breturn%20e%7D()%2C%7Btitle%3Ao%2Cbyline%3Ai%2Ccontent%3Al%7D%3Dnew%20t(document.cloneNode(!0)).parse()%2Cr%3Do.replace(%22%3A%22%2C%22%22).replace(%2F%5C%2F%2Fg%2C%22-%22).replace(%2F%5C%5C%2Fg%2C%22-%22)%3Bif(n)var%20c%3Dn%3Belse%20c%3Dl%3Bconst%20a%3Dnew%20e(%7BheadingStyle%3A%22atx%22%2Chr%3A%22---%22%2CbulletListMarker%3A%22-%22%2CcodeBlockStyle%3A%22fenced%22%2CemDelimiter%3A%22*%22%7D).turndown(c)%3Bconst%20d%3Dfunction(e)%7Bvar%20t%3De.getFullYear().toString()%2Cn%3D(e.getMonth()%2B1).toString()%2Co%3De.getDate().toString()%2Ci%3Dn.split(%22%22)%2Cl%3Do.split(%22%22)%3Breturn%20t%2B%22-%22%2B(i%5B1%5D%3Fn%3A%220%22%2Bi%5B0%5D)%2B%22-%22%2B(l%5B1%5D%3Fo%3A%220%22%2Bl%5B0%5D)%7D(new%20Date)%2Cu%3D%60author%3A%3A%20%24%7Bi%7D%5Cnsource%3A%3A%20%5B%24%7Bo%7D%5D(%24%7Bdocument.URL%7D)%5Cnclipped%3A%3A%20%5B%5B%24%7Bd%7D%5D%5D%5Cnpublished%3A%3A%20%5Cn%5Cn%23clippings%5Cn%5Cn%24%7Ba%7D%60%3Bwindow.location.href%3D%22obsidian%3A%2F%2Fnew%3Fname%3D%22%2Br%2B%22%26content%3D%22%2BencodeURIComponent(u)%7D)%3B%7D)()%3B
    2 changes: 1 addition & 1 deletion readme.md
    Original file line number Diff line number Diff line change
    @@ -6,4 +6,4 @@ To use it, create a new bookmark in your browser, then copy/paste the code below

    Support my work at [buymeacoffee.com/kepano](https://www.buymeacoffee.com/kepano)

    If you run into issues, you can also try the [MarkDownload browser extension](https://forum.obsidian.md/t/markdownload-markdown-web-clipper/173) which provides similar functionality.
    Note that this bookmarklet may not work on all websites. If you run into issues, you can also try the [MarkDownload browser extension](https://forum.obsidian.md/t/markdownload-markdown-web-clipper/173) which provides similar functionality.
  28. Stephan Ango revised this gist Aug 7, 2021. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion readme.md
    Original file line number Diff line number Diff line change
    @@ -6,4 +6,4 @@ To use it, create a new bookmark in your browser, then copy/paste the code below

    Support my work at [buymeacoffee.com/kepano](https://www.buymeacoffee.com/kepano)

    If you run into issues, you can also try the [MarkDownload browser extension](https://forum.obsidian.md/t/markdownload-markdown-web-clipper/173) which provides similar functionality
    If you run into issues, you can also try the [MarkDownload browser extension](https://forum.obsidian.md/t/markdownload-markdown-web-clipper/173) which provides similar functionality.
  29. Stephan Ango revised this gist Aug 7, 2021. 1 changed file with 4 additions and 2 deletions.
    6 changes: 4 additions & 2 deletions readme.md
    Original file line number Diff line number Diff line change
    @@ -2,6 +2,8 @@ By [@kepano](https://www.twitter.com/kepano)

    You can find a demo of this bookmarklet [on YouTube](https://www.youtube.com/watch?v=Vy1MdjickAI)

    To use it, create a new bookmark in your browser, then copy/paste the code below into the URL field
    To use it, create a new bookmark in your browser, then copy/paste the code below into the URL field.

    Support my work at [buymeacoffee.com/kepano](https://www.buymeacoffee.com/kepano)
    Support my work at [buymeacoffee.com/kepano](https://www.buymeacoffee.com/kepano)

    If you run into issues, you can also try the [MarkDownload browser extension](https://forum.obsidian.md/t/markdownload-markdown-web-clipper/173) which provides similar functionality
  30. Stephan Ango revised this gist Aug 5, 2021. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion readme.md
    Original file line number Diff line number Diff line change
    @@ -2,6 +2,6 @@ By [@kepano](https://www.twitter.com/kepano)

    You can find a demo of this bookmarklet [on YouTube](https://www.youtube.com/watch?v=Vy1MdjickAI)

    To use it, create a new bookmark and copy/paste the code below into the URL field
    To use it, create a new bookmark in your browser, then copy/paste the code below into the URL field

    Support my work at [buymeacoffee.com/kepano](https://www.buymeacoffee.com/kepano)