View behavior.js
(function (w, d, a) {
var $ = w[a.k] = {
"a": a, "w": w, "d": d,
"s": {},
"v": {},
"f": (function () {
return {
// get a DOM property or text attribute
get: function (el, att) {
var v = null;
View readme.md

A Modernized JavaScript Class Name Changer

Previously we'd do something horrible with string matching when we wanted to change an HTML element's class name with JavaScript.

var changeClass = function (el, add, remove) {
  if (el) {

    if (!el.className) {
      el.className = '';
View refreshContextMenus.md

Showing and Hiding Context Menus in Browser Extensions

Browser extensions that add extra context menus typically face an all-or-nothing situation: the menu item will always be present on all pages once it is created.

If we need our context menu to only be there on certain Internet domains, we need to constantly check the active tab and refresh the context menu. Here's one way of doing it:

Content

In our content script, we'll set up a special block of functions that wait for requests from the background script.

View wat_url.md

Some URLs Abbreviated in Chrome When Processed By JavaScript

While rebuilding the Pinterest extension for Chrome we ran across a weird edge case at vox.com. We could preview their nice big fat srcset-enabled images in the grid and scrape + post to Pinterest, but could not take the src attribute of an IMG tag and directly apply it to the background-image style attribute of a new DIV.

Here are some reduced cases:

Win

Copy this to clipboard:

View xhr_promises.js
var xhr = o => {
return new Promise(function(resolve, reject) {
var req = new XMLHttpRequest();
o.method = o.method || 'GET';
// third parameter must be there and be true to use o.formData
req.open(o.method, o.url, true);
// default text; can send json
req.responseType = o.responseType || 'text';
// get reply back from API in proper language
View content.js
var browser = chrome || browser;
var iframe = document.createElement('IFRAME');
iframe.style.position = 'fixed';
iframe.style.height = '100px';
iframe.style.width = '300px';
iframe.style.top = '0';
iframe.style.right = '0';
iframe.src = browser.extension.getURL('iframe.html');
document.body.appendChild(iframe);
View pinterest_meta.md

Just like Facebook and Twitter, Pinterest has its own namespace. Go like this:

<meta property="pin:url" content="https://yourpage.com/pinit/test/pinterest_meta.html" />
<meta property="pin:description" content="This pin was generated by the Pinterest meta." />
<meta property="pin:media" content="http://cdn.yourpage.com/your_image_here.jpg" />

... and your preferred image (which need not actually appear on the page) will show at the top of the grid when someone uses Pinterest's mobile device, browser extension, or Any Image Save button.

View IPBSIEIP.md

January 25, 2017

MEMORANDUM FOR:

Kevin McAleenan, Acting Commissioner, U.S. Customs and Border Protection

Dan Ragsdale, Acting Director, U.S. Immigration and Customs Enforcement

Lori Scialabba, Acting Director, U.S. Citizenship and Immigration Services

View stub.html
<!doctype html>
<html>
<head>
<title></title>
<meta charset="utf-8">
<link rel="stylesheet" href="presentation.css">
</head>
<body>
<script src="behavior.js"></script>
</body>
View WebExtensionCheck.js
// If we know the extension's ID and a path to one of its web-accessible resources, we can quietly check for presence.
(function (w, a) {
var checkExt = function (callback) {
var hazExt = false;
var img = new Image();
img.onload = function () {
hazExt = true;
};
// need to know the right protocol for Firefox and Edge extensions