TODO
import './banana.js';
import './banana.js#foo';
These are both run by Chrome 61, but are only fetched from the network once!
// This code now lives at https://github.com/samthor/undoer (or 'undoer' on NPM). |
package main | |
import ( | |
"crypto/tls" | |
"flag" | |
"fmt" | |
"log" | |
"net/http" | |
"os" | |
"os/user" |
Array.from(document.styleSheets).forEach((ss) => { | |
const toDelete = []; | |
const toReplace = new Map(); | |
for (let i = 0; i < ss.rules.length; ++i) { | |
const rule = ss.rules[i]; | |
if (!(rule instanceof CSSMediaRule)) { | |
continue; | |
} |
const functionMatch = /^function\s*\w*\(([\w\s,]+)\) {/; | |
/** | |
* @param {!Function} fn | |
* @return {!Array<string>} array of simple arg names (no =, ... etc) | |
*/ | |
function simpleArgNames(fn) { | |
const match = functionRe.exec(fn.toString()); | |
if (!match) { return []; } | |
const args = match[1].split(',').map((x) => x.trim()); |
/** | |
* Updates the passed dialog to retain focus and restore it when the dialog is closed. Won't | |
* upgrade a dialog more than once. Supports IE11+ and is a no-op otherwise. | |
* @param {!HTMLDialogElement} dialog to upgrade | |
*/ | |
var registerFocusRestoreDialog = (function() { | |
if (!window.WeakMap || !window.MutationObserver) { | |
return function() {}; | |
} | |
var registered = new WeakMap(); |
function isLandscape() { | |
var object = window.screen.orientation || window.screen.msOrientation || window.screen.mozOrientation || null; | |
if (object) { | |
if (object.type.indexOf('landscape') !== -1) { return true; } | |
if (object.type.indexOf('portrait') !== -1) { return false; } | |
} | |
if ('orientation' in window) { | |
var value = window.orientation; | |
if (value === 0 || value === 180) { | |
return false; |
// usage: | |
// importScript('./path/to/script.js').then((allExports) => { .... })); | |
function importScript(path) { | |
let entry = window.importScript.__db[path]; | |
if (entry === undefined) { | |
const escape = path.replace(`'`, `\\'`); | |
const script = Object.assign(document.createElement('script'), { | |
type: 'module', | |
textContent: `import * as x from '${escape}'; importScript.__db['${escape}'].resolve(x);`, | |
}); |
/* | |
* Copyright 2008 Sam Thorogood. All rights reserved. | |
* | |
* Licensed under the Apache License, Version 2.0 (the "License"); you may not | |
* use this file except in compliance with the License. You may obtain a copy of | |
* the License at | |
* | |
* http://www.apache.org/licenses/LICENSE-2.0 | |
* | |
* Unless required by applicable law or agreed to in writing, software |
// UPDATE: In 2023, you should probably stop using this! The narrow version of Safari that | |
// does not support `nomodule` is probably not being used anywhere. The code below is left | |
// for posterity. | |
/** | |
* Safari 10.1 supports modules, but does not support the `nomodule` attribute - it will | |
* load <script nomodule> anyway. This snippet solve this problem, but only for script | |
* tags that load external code, e.g.: <script nomodule src="nomodule.js"></script> | |
* | |
* Again: this will **not** prevent inline script, e.g.: |