Skip to content

Instantly share code, notes, and snippets.

@do18
do18 / yt-embed.js
Last active July 13, 2023 11:22
If you are concerned about web site performance, you probably noticed that embedded YouTube iframes are costly. Instead of iframes, you may embed images that link to the respective videos, and make these links replace themselves with iframes when clicked. (IE 9+ because of getElementsByClassName.)
/*jshint maxlen: 79 */
var MYSITE = MYSITE || {};
/**
* Make YouTube links with .yt-embed replace themselves with YouTube iframes
* when clicked. The first child element is assumed to be the img element
* holding the poster frame. The YouTube URL must contain the "v" parameter,
* but no further parameters. The data-yt-options attribute may hold iframe
* URL parameters.
@do18
do18 / mailto-es6.js
Last active March 12, 2019 21:57
For trivial protection against dumb email address crawlers, write <a href=mailto:me(at)example(dot)org>me(at)example(dot)org</a> and include this JS at the bottom of the page.
// jshint esversion: 6, maxlen: 80, strict: global
'use strict';
// In mailto: links, replace '(at)' with '@' and '(dot)' with '.'
{
const at = /\(at\)/gi;
const dot = /\(dot\)/gi;
const links = document.querySelectorAll('a[href^="mailto:"]');