Craft.do Web Clipper Bookmarklet

slug
craft_web_clipper
date
Sep 11, 2021
summary
Save web page content to Craft Inbox with one click.
tags
Craft.do
Bookmarklet
status
Published
type
Post
💡
Waiting for the official API…
Save web page content to Craft Inbox with one click.
Modified from Obsidian Bookmarklet.

Source Code

javascript: Promise.all([ import("<https://unpkg.com/[email protected]?module>"), import("<https://unpkg.com/@tehshrike/[email protected]>"), ]).then(async ([{ default: Turndown }, { 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; } } return html; } const selection = getSelectionHtml(); const { title, byline, content } = new Readability( document.cloneNode(true) ).parse(); if (selection) { var markdownify = selection; } else { var markdownify = content; } 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 clipContent = "author: " + byline + "\\n" + "source: [" + title + "](" + document.URL + ")\\n" + "clipped: [[" + today + "]]\\n\\n" + "----\\n\\n" + markdownBody; console.log(clipContent); });

Compressed version

javascript:Promise.all([import("<https://unpkg.com/[email protected]?module"),import("https://unpkg.com/@tehshrike/[email protected]>"),]).then(async([{default:Turndown},{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}}return html}const selection=getSelectionHtml();const{title,byline,content}=new Readability(document.cloneNode(true)).parse();if(selection){var markdownify=selection}else{var markdownify=content}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 clipContent="author: "+byline+"\\nsource: ["+title+"]("+document.URL+")\\nclipped: [["+today+"]]\\n\\n----\\n\\n"+markdownBody;console.log(clipContent)});
对于本文内容有任何疑问, 可与我联系.