Skip to content

Instantly share code, notes, and snippets.

@jbrown123
Last active March 15, 2024 17:08
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jbrown123/4c768495b21b03d5529f26ccd83bf69f to your computer and use it in GitHub Desktop.
Save jbrown123/4c768495b21b03d5529f26ccd83bf69f to your computer and use it in GitHub Desktop.
A simple bookmarklet to help clip a webpage to a google doc

Bookmarklet to clip webpages to google docs

Below is a simple bookmarklet (see https://en.wikipedia.org/wiki/Bookmarklet) to make it easier to capture the content of a webpage into a google doc. This is similar (but much simpler and less functionality) to Evernote Web Clipper (see https://evernote.com/webclipper/).

This bookmarklet will copy the URL and the title of the current page. Since most browsers forbid directly manipulating the clipboard contents, it makes a copy by creating a pop-up with all the data highlighted and asks the user to press control-c (the keyboard copy shortcut) and then enter. Once you press enter it will create a new google document for you in a new tab. You can simply press control-v (the keyboard paste shortcut) to put in the URL and title.

If you press escape or hit 'cancel' in the popup, nothing happens and you return to your original webpage.

If you happen to have some text selected on the current webpage, this will be appended to the end of the pasted block. However, note that it will be converted to plain text. No formatting (bold, italics, fonts, etc.) will be retained nor will links in the copied text be preserved.

The pasted text has the following format:

The first line is for tags. I use hashtags to help me sort and classify the information I save. This line let's me create whatever hashtags are appropriate for the particular content I'm clipping.

Next is the URL of the original site you are clipping from. I find this useful if I want to return and read the original article or if I want to use it as a reference later.

Next is the original page title. This is also set as the document title through a URL parameter to the google create URL.

If you have any text selected on the original page, it will appear last in the pasted block. I usually don't use this feature, but I added it in for those who want a one-and-done solution to web clipping.

Of course at this point you can edit as necessary. I usually select the title line and change it to 'title' style. I also add the appropriate hashtags on the top line. I then go back to the original page and select, copy, and paste in whatever bits of the page I want to save.

Just create a new bookmark and make the text below (starting with javascript:) the URL of the bookmark. Note that you will need to replace the "YOUR FOLDER ID HERE" string with the actual google docs folder ID you want to use. "How do you find this folder ID" I hear you asking. Good question. Launch google drive (https://drive.google.com) and navigate to the folder you want to use. On the end of the URL line is a big ugly number. As far as I can tell, they all start with 0B followed by a bunch of other letters and numbers. Copy everything after the last forward slash and that's your folder ID.

You can create different bookmarks to create documents in different google docs folders by supplying the appropriate folder ID in each bookmarklet.

Copy the text below into your bookmark URL (be sure to substitute your folder ID):

javascript:(function(){var folder="YOUR FOLDER ID HERE"; var text=""; if(window.getSelection){text=window.getSelection().toString();}else if(document.selection && document.selection.type!="Control"){text=document.selection.createRange().text;}if(prompt("Press Ctrl+C, Enter", "Tags: \n\n"+location.href+"\n\n"+document.title+"\n\n"+text)) window.open('https://docs.google.com/document/create?usp=drive_web&folder="+folder+"&title='+encodeURIComponent(document.title))})()
@jpcotter
Copy link

I keep getting an error message from Google. See attached.
IMG_6891

@jbrown123
Copy link
Author

jbrown123 commented Mar 14, 2024

Did you replace the "YOUR FOLDER ID HERE" with the appropriate folder ID?

It's working for me so I assume it's some sort of configuration problem.

A drive folder link should look something like this (obfuscated by changing the numbers):
https://drive.google.com/drive/u/0/folders/0Basfgasdf581586asdf12325asdfadfq453546?resourcekey=0-asfasdfasdf
.......................................................................................^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ <-- get this part

You want JUST the "0Basfgasdf581586asdf12325asdfadfq453546" part from the link above. Everything between the last slash to the question mark.

BTW, I've never tried this on a phone. I do it from chrome in Windows. It's possible there's something odd with the phone browser.

@jpcotter
Copy link

jpcotter commented Mar 14, 2024 via email

@jbrown123
Copy link
Author

jbrown123 commented Mar 14, 2024

And you included the javascript: at the start, right? Replacing the https:?

I don't have an iphone so I don't know if their browser does something odd with JS in the URL portion. Perhaps they don't support that at all.

You could test it easily with a URL of javascript:alert("hello, world");
That should produce a popup box with the text in it. If that doesn't work, then iphone doesn't support JS URLs I suppose.

BTW, no screen shots in your previous post. Just a copy of the message instead.

@jpcotter
Copy link

jpcotter commented Mar 15, 2024 via email

@jbrown123
Copy link
Author

What URL does it say it's opening?

@jpcotter
Copy link

jpcotter commented Mar 15, 2024 via email

@jbrown123
Copy link
Author

Notice that it isn't properly creating the URL. The folder ID hasn't been inserted, for example.

I think there is an issue with the quote characters being misinterpreted, probably as a result of the copy & paste operation.

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