Skip to content

Instantly share code, notes, and snippets.

@DigiTec
DigiTec / element_tag_names.js
Last active August 29, 2015 14:20
A gist of element tag names in various namespaces
// Lists primarily based on MSHTML support IE5 through IE11
// Namespaces
const nsXHTML = "http://www.w3.org/1999/xhtml";
const nsSVG = "http://www.w3.org/2000/svg";
const nsMATHML = "http://www.w3.org/1998/Math/MathML";
const nsXML = "http://www.w3.org/XML/1998/namespace";
// "x-ms-webview" added for WWA
// "main" tag added for EdgeHTML
@DigiTec
DigiTec / basic_constructors.js
Last active August 29, 2015 14:20
This gist is for my article on how a Browser implements constructors for DOM objects. It contains a short list of samples that are inserted into the article for pretty printing. Here is the link to the article: http://www.justrog.com/2015/05/constructors-by-construction-in.html
// Per spec configures a location on the global of name Node with a value
// of the instance of the function.
function ANode() {
}
// We derive from Object
ANode.prototype = Object.create(Object.prototype);
// Complete the loop back to ourselves
ANode.prototype.constructor = ANode;
@DigiTec
DigiTec / evil_vendor_prefix2.js
Created April 25, 2015 19:34
And the vendor prefixes attack again. This time, the ordinal indexing of the CSSStyleDeclaration is being used to see what the "first" vendor prefix is within the list of parser names supported by the browser. Since -ms- comes before -webkit- it will prioritize that over anything else. Also, the implicit assumption that if you support one vendor…
// Utilize duck typed slice, to enumerate 0..length indices.
// Indices on CSSStyleDeclaration return the "parser" names for properties.
// Based on the parser names, determine the vendor prefix to use.
var vendor_prefix = Array.prototype.slice.call(window.getComputedStyle(document.body)).join('').match(/-(ms|webkit|moz)-/)[0];
console.log(vendor_prefix);
@DigiTec
DigiTec / evil_vendor_prefix.js
Created April 14, 2015 18:04
Ever wonder why browser vendors dis-like bad feature detection (in this case I'd argue this is browser detection)? Well this is why. Vendor prefix sniffing that ends up assuming support of one vendor prefix means all properties are implemented that way. First, nearly all of the vendor prefixed properties appear very late in the enumeration, so y…
<script>
var r = {};
r.VENDOR_PREFIX = function () {
var e = /^(Webkit|Khtml|Moz|ms|O)(?=[A-Z])/, t = document.getElementsByTagName("script")[0].style, n;
for (n in t)
if (e.test(n))
return n.match(e)[0].toLowerCase();
return "WebkitOpacity" in t ? "webkit" : "KhtmlOpacity" in t ? "khtml" : "";
}();
</script>
@DigiTec
DigiTec / arrayIfy.js
Last active August 29, 2015 14:15
Duck Typing Demos for Array -> HTMLCollection
// http://jsfiddle.net/w3mw1r4q/
var ary = Array.apply(null, document.body.children);
console.log(Array.isArray(document.body.children));
console.log(Array.isArray(ary));
console.log(ary.length);
@DigiTec
DigiTec / vendor_enum.js
Last active August 29, 2015 14:14
Vendor Prefix Enumeration - Note prior to Chrome 43 we have to use instances to get values back. So there is a switch for some of the known instances, but this is heavily incomplete. Starting with Chrome 43 more information is on the prototype. Still, things like window and CSSStyleDeclaration lack type system and so you still need an instance f…
// http://jsfiddle.net/8n6c1dpz/12/
var out = document.getElementById("output");
var vendorPrefixes = [/^ms|^onms/i, /^moz|^onmoz/i, /^webkit|^onwebkit/i];
var vendorProps = vendorPrefixes.map(function (prefix) {
return Object.getOwnPropertyNames(window).filter(function (name) {
try {
return (this[name].prototype && this[name].prototype.constructor === this[name]);
} catch (exc) {
return false;
@DigiTec
DigiTec / img_src_override.js
Created February 1, 2015 00:27
ES 5 Configurable Properties
// http://jsfiddle.net/s4ex1dtj/
"use strict";
var myImage = new Image();
Object.defineProperty(myImage, "src", {
get: function () { return 'foo'; },
set: function (val) { alert(val); } });
console.log(myImage.src); // Logs value 'foo'
myImage.src = "new"; // alerts value 'new'
// newImage does not have a redefined setter since our previous property
@DigiTec
DigiTec / WebIDLLexer.pegjs
Last active August 29, 2015 14:13
A complete WebIDLLexer (without tests) which is compliant with the lexer rules for WebIDL Second Edition available here http://heycam.github.io/webidl/
{
function token() {
this.value = '';
this.type = 'error';
}
// Static methods on token
Object.defineProperties(token, {
createOther: {
value: function createOther(val) {
@DigiTec
DigiTec / scraper.js
Last active March 14, 2016 08:11
Personal sample of using Node.js for processing web page contents using request and cheerio
var request = require('request');
var cheerio = require('cheerio');
var urls = [
'https://developer.android.com/reference/com/google/android/gms/location/Geofence.html',
'http://developer.android.com/reference/com/google/android/gms/maps/model/LatLng.html'
];
urls.forEach(function (elem) {
request({
@DigiTec
DigiTec / config
Created December 2, 2014 08:01
Node.js filtering symbol server to avoid unnecessary symbol queries when debugging on slow connections.
var config = {
forward_server: 'msdl.microsoft.com',
forward_path: '/download/symbols',
forward_port: 80,
allow_list: [
/\/ntdll.pdb\//
],
};
module.exports = config;