Skip to content

Instantly share code, notes, and snippets.

@townivan
townivan / stuff.js
Created Jan 8, 2019
Read all of the .html files in a folder without using a library like glob
View stuff.js
const fs = require('fs');
const targetPath = './src/pages/'
// *.html files
let fileNamesArray = fs.readdirSync(targetPath).filter( (file) => {
return file.includes('.html')
})
// 'all-comps.html', 'c090.html', 'c100.html', 'c101.html', 'c102.html', 'index.html' ]
View favicon-chrome-error-quick-fix.html
<link rel="icon" href="data:;base64,iVBORw0KGgo=">
<!-- credit: https://vsparrow.com/2017/05/01/favicon-ico-failed-to-load-resource-the-server-responded-with-a-status-of-404-not-found/ -->
@townivan
townivan / basic.html
Created Nov 7, 2018
standard html page setup
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>
@townivan
townivan / online-keyboard-only.html
Last active Nov 14, 2018
outline style only for keyboard
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>
@townivan
townivan / color object
Created Sep 13, 2018 — forked from OneCent01/color object
Every color contained in an object with its corresponding hexa value for O(1) time lookup, find function below object
View color object
var colors = {
ALICEBLUE: '#F0F8FF',
ANTIQUEWHITE: '#FAEBD7',
AQUA: '#00FFFF',
AQUAMARINE: '#7FFFD4',
AZURE: '#F0FFFF',
BEIGE: '#F5F5DC',
BISQUE: '#FFE4C4',
BLACK: '#000000',
BLANCHEDALMOND: '#FFEBCD',
@townivan
townivan / export-errors
Created May 18, 2018
Export errors from HTML_CodeSniffer.
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 } })
@townivan
townivan / a11y-img-with-no-alt
Created Mar 22, 2018
Chuck's excellent script to deal with tracker images without alt tag - the ones that mess up a11y scans!
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);
@townivan
townivan / icur.js
Last active Nov 1, 2017
updated JavaScript function for displaying currency (allows rounding up to next whole cent or dollar)
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"
You can’t perform that action at this time.