Skip to content

Instantly share code, notes, and snippets.

@shogun70
shogun70 / gist:5362893
Last active December 16, 2015 02:29
Test-case for `<plaintext>` insertion and document rewrite. This would be the starting point for adding error recovery to Mobify.js.
<!DOCTYPE html>
<script>
(function(window, document, detector, timeout, scripts) {
var bootScript = $('script'); // bootScript is used in loadScript()
bootScript.setAttribute('onload', ';'); // old Safari will have a misleading ('onload' in bootScript)
if (typeof bootScript.onload !== 'function' || !detector()) {
alert('Browser not supported. No action'); // NOTE this alert pops-up twice on IE <= 8 - parsing restarts when charset is declared
return;
}
@shogun70
shogun70 / gist:5388420
Last active November 6, 2017 20:02
Log `document.readyState` for various stages of markup parsing and events.
<!DOCTYPE html>
<script type="text/javascript">
var addEvent = document.addEventListener ?
function(node, name, fn) { node.addEventListener(name, fn, false); } :
function(node, name, fn) { node.attachEvent('on' + name, fn); }
var begin = +new Date;
var log = [];
log.push('Event, Time: readyState, EOF');
function logEvent(name) {
@shogun70
shogun70 / URLUtils.js
Created June 22, 2016 12:16 — forked from Yaffle/URLUtils.js
parse URL + absolutize URL in javascript (URLUtils shim - http://url.spec.whatwg.org/#url)
/*jslint regexp: true, maxerr: 50, indent: 2 */
(function (global) {
"use strict";
function URLUtils(url, baseURL) {
var m = String(url).replace(/^\s+|\s+$/g, "").match(/^([^:\/?#]+:)?(?:\/\/(?:([^:@\/?#]*)(?::([^:@\/?#]*))?@)?(([^:\/?#]*)(?::(\d*))?))?([^?#]*)(\?[^#]*)?(#[\s\S]*)?/);
if (!m) {
throw new RangeError();
}