Skip to content

Instantly share code, notes, and snippets.

View bgrins's full-sized avatar

Brian Grinstead bgrins

View GitHub Profile
@bgrins
bgrins / escapeAttributeValues.js
Created July 30, 2013 20:20
Given a string convert it into an array of name/value objects
function escapeAttributeValues(attr, aAttrNode) {
let div = aAttrNode.ownerDocument.createElement("div");
div.innerHTML = "<div " + attr + "></div>";
var attributes=[];
var el = div.childNodes[0];
for (var i=0, l=el.attributes.length; i<l; i++){
let attr = el.attributes.item(i)
attributes.push({name:attr.nodeName, value: attr.nodeValue});
}
@bgrins
bgrins / attributeparse.md
Last active December 20, 2015 15:39
Thoughts on attribute parsing for devtools inspector

I want to make a function that takes in id="one" class='two' and converts it to [{name: "id", value: "one" }, { name: "class", value: "two" }]. I have a little more information and small demo of what I am trying to do at this link: http://fiddle.jshell.net/bgrins/hhSXx/show/.

attribute-parsing

@bgrins
bgrins / detectDataURL.js
Last active March 22, 2025 13:42
Detect if a string is a data URL. Doesn't try to parse it or determine validity, just a quick check if a string appears to be a data URL. See http://jsfiddle.net/bgrins/aZWTB/ for a demo.
// Detecting data URLs
// data URI - MDN https://developer.mozilla.org/en-US/docs/data_URIs
// The "data" URL scheme: http://tools.ietf.org/html/rfc2397
// Valid URL Characters: http://tools.ietf.org/html/rfc2396#section2
function isDataURL(s) {
return !!s.match(isDataURL.regex);
}
isDataURL.regex = /^\s*data:([a-z]+\/[a-z]+(;[a-z\-]+\=[a-z\-]+)?)?(;base64)?,[a-z0-9\!\$\&\'\,\(\)\*\+\,\;\=\-\.\_\~\:\@\/\?\%\s]*\s*$/i;
@bgrins
bgrins / formcontrols.js
Created August 14, 2013 18:52
Returning from a snippet
// formcontrols.js
// https://github.com/bgrins/devtools-snippets
// Print out forms and their controls
(function() {
var forms = document.querySelectorAll("form");
for (var i = 0, len = forms.length; i < len; i++) {
var tab = [ ];
/snippets
/jquerify
README.md
jquerify.js
jquerify.png
/hashlink
README.md
hashlink.js
hashlink.png
index.html (generated on build)
@bgrins
bgrins / autorun
Last active December 23, 2015 06:39
Run a command over and over, until you interrupt it
trap "exit" SIGHUP SIGINT SIGTERM
while true
do ffrun
done
@bgrins
bgrins / firefoxautorun
Last active March 17, 2016 15:28
Start firefox in a loop, allowing you to quit and have it auto rebuild devtools and restart.
# Start firefox in a loop, allowing you to quit and have it auto rebuild devtools and restart.
if [ -f mach ];
then
echo "mach exists. Starting loop."
trap "exit" SIGHUP SIGINT SIGTERM
while true
do
./mach build faster
./mach run --devtools --jsconsole -P dev
On page: http://fiddle.jshell.net/bgrins/bgJGb/show/.
console.log: UNLOAD http://fiddle.jshell.net/bgrins/bgJGb/show/
console.log: UNLOAD about:blank
console.log: UNLOAD about:blank
console.log: LOAD http://bgrins.github.io/
console.log: LOAD http://bgrins.github.io/
console.log: LOAD http://fiddle.jshell.net/bgrins/bgJGb/show/
@bgrins
bgrins / gist:6906638
Created October 9, 2013 19:16
Open output of test in sublime text
mach build browser/devtools; mach mochitest-browser browser/devtools/inspector/test/browser_inspector_changes.js > $$.txt; sublime $$.txt; rm $$.txt;
@bgrins
bgrins / rotate-children.js
Created November 7, 2013 15:57
Quick DOM operations for testing
setInterval(function() { document.body.appendChild(document.body.firstElementChild) }, 5000);