Skip to content

Instantly share code, notes, and snippets.

View shgysk8zer0's full-sized avatar
💭
I may be slow to respond.

Chris Zuber shgysk8zer0

💭
I may be slow to respond.
View GitHub Profile
@shgysk8zer0
shgysk8zer0 / gist.js
Last active December 2, 2021 00:02
A demo of <github-gist> usage (See https://codepen.io/shgysk8zer0/full/jOGEJRj)
const protectedData = new WeakMap();
function render(target) {
const { user, gist, file, height, width } = target;
const { shadow } = protectedData.get(target);
const iframe = document.createElement('iframe');
const script = document.createElement('script');
const link = document.createElement('link');
const src = new URL(`/${user}/${gist}.js`, 'https://gist.github.com');
const controller = new AbortController();
@shgysk8zer0
shgysk8zer0 / README.md
Last active December 2, 2021 08:00
<github-gist> class for lazy-loading Gists

<github-gist> Instructions

This is a custom element / web component built using vanilla JavaScript to embed GistHub Gists into a webpage without having to worry about the inline scripts which call document.write(). It can be configured to lazy-load using loading="lazy" and styled with CSS through the github-gist & github-gist::part(embed) selectors.

Under-the-hood it creates an <iframe> using:

<iframe srcdoc="..." sandbox="allow-scripts allow-popups" width="..." height="..." referrerpolicy="no-referrer"></iframe>
/**
* Opens an IDB Cursor as an asynchronous iterable, allowing iteration over the results of a database query.
*
* @async
* @generator
* @param {IDBDatabase} db The IndexedDB database.
* @param {string} storeName The name of the object store.
* @param {object} [options] Options for the cursor.
* @param {IDBTransactionMode} [options.mode="readonly"] The transaction mode.
* @param {IDBTransactionDurability} [options.durability="default"] The transaction durability.