View background.js
const BLOCK_ME = "://";
function(r) {
return {
cancel: r.url.indexOf(BLOCK_ME) != -1
{urls: ["<all_urls>"]},

Old School:

  var clean = function (input) {
    var testMe = input, dupeTest = '';
    while (testMe !== dupeTest) {
      testMe = new DOMParser().parseFromString(testMe, "text/html").documentElement.textContent;
      dupeTest = testMe;
    testMe = testMe.replace(/</g, '&lt;');
    return testMe;
View wilensky.js
// paste me into console to explore the counterintuitive problem found here:
// setup: tweak as needed
var rounds = 10, turns = 1000, max = 100, start = 100;
// play one round
var round = function () {
// setup
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;

Towards 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 = '';

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:


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


Some URLs Abbreviated in Chrome When Processed By JavaScript

While rebuilding the Pinterest extension for Chrome we ran across a weird edge case at 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:


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, 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'); = 'fixed'; = '100px'; = '300px'; = '0'; = '0';
iframe.src = browser.extension.getURL('iframe.html');