Instantly share code, notes, and snippets.

View basic.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
View online-keyboard-only.html
<script>
// Let the document know when the mouse is being used
document.body.addEventListener('mousedown', function() {
document.body.classList.add('using-mouse');
});
document.body.addEventListener('keydown', function() {
document.body.classList.remove('using-mouse');
});
</script>
View color object
var colors = {
ALICEBLUE: '#F0F8FF',
ANTIQUEWHITE: '#FAEBD7',
AQUA: '#00FFFF',
AQUAMARINE: '#7FFFD4',
AZURE: '#F0FFFF',
BEIGE: '#F5F5DC',
BISQUE: '#FFE4C4',
BLACK: '#000000',
BLANCHEDALMOND: '#FFEBCD',
View export-errors
Array.from(document.querySelectorAll(".HTMLCS-issue-detail-list li")).map((el) => { return { detail: el.querySelector(".HTMLCS-issue-title").textContent, code: el.querySelector(".HTMLCS-issue-source-inner strong").textContent } })
View a11y-img-with-no-alt
document.addEventListener('DOMContentLoaded', function () {
const targetNode = document.body;
const callback = function (mutationsList) {
for (let mutation of mutationsList) {
if (mutation.type == 'childList') {
mutation.addedNodes.forEach((node) => {
if (node && node.src && node.src.match(/.*pages02.net.*/).length >
0) {
observer.disconnect();
node.setAttribute("aria-hidden", true);
View icur.js
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/ceil
// https://stackoverflow.com/questions/42109818/reliable-js-rounding-numbers-with-tofixed2-of-a-3-decimal-number
// Closure
(function() {
/**
* Decimal adjustment of a number.
*
* @param {String} type The type of adjustment.
* @param {Number} value The number.
* @param {Integer} exp The exponent (the 10 logarithm of the adjustment base).
View get-query-string-with-js.js
function getParameterByName(name, url) {
if (!url) url = window.location.href;
name = name.replace(/[\[\]]/g, "\\$&");
var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
results = regex.exec(url);
if (!results) return null;
if (!results[2]) return '';
return decodeURIComponent(results[2].replace(/\+/g, " "));
}
View myFormatCurrency.js
function myFormatCurrency(num, options) {
// Defaults to showing cents with normal rounding on the cent.
// myFormatCurrency(1000.021) -> "$1,000.02"
// options = 1 Don't show the cents
// myFormatCurrency(1000.021, 1) -> "$1,000"
// options = 2 Show the cents with cent rounding up the next whole cent
// myFormatCurrency(1000.021, 2) -> "$1,000.03"
View css.css
/* .invalid class prevents CSS from automatically applying */
.invalid input:required:invalid {
background: #BE4C54;
}
.invalid textarea:required:invalid {
background: #BE4C54;
}
.invalid select:required:invalid {
background: #BE4C54;
}
View inline-svg-scale
.img-svg { width:100%; height: auto; }
<img class="img-svg" src="box.svg" />