Skip to content

Instantly share code, notes, and snippets.

@nessthehero
Created August 25, 2020 14:54
Show Gist options
  • Save nessthehero/df0d5a62a6016ac82c53daa73ca8e145 to your computer and use it in GitHub Desktop.
Save nessthehero/df0d5a62a6016ac82c53daa73ca8e145 to your computer and use it in GitHub Desktop.
Devtools Snippets
// jquerify.js
// https://github.com/bgrins/devtools-snippets
// Add jQuery to any page that does not have it already.
(function () {
if ( !window.jQuery ) {
var s = document.createElement('script');
s.setAttribute('src', '//ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js');
document.body.appendChild(s);
console.log('jquery loaded!');
}
})();
/*
log-globals
by Sindre Sorhus
https://github.com/sindresorhus/log-globals
MIT License
*/
(function () {
'use strict';
function getIframe() {
var el = document.createElement('iframe');
el.style.display = 'none';
document.body.appendChild(el);
var win = el.contentWindow;
document.body.removeChild(el);
return win;
}
function detectGlobals() {
var iframe = getIframe();
var ret = Object.create(null);
for (var prop in window) {
if (!(prop in iframe)) {
ret[prop] = window[prop];
}
}
return ret;
}
console.log(detectGlobals());
})();
pathname = window.location.pathname;
section = pathname.split('/')[1];
numSlashes = pathname.split('/').length - 1;
console.log(numSlashes);
function q () {
var vars = [],
grabUrl = window.location.search,
parts,
pieces,
qs = '',
qsVals = [];
if (typeof arguments[0] == 'string') {
qs = arguments[0];
}
if (typeof arguments[0] == 'string') {
qs = arguments[0];
}
if (typeof grabUrl != 'undefined' && grabUrl != '') {
grabUrl = grabUrl.replace("?", '');
parts = grabUrl.split("&");
for (var j in parts) {
pieces = parts[j].split('=');
if (vars.length != 0) {
for (var i in vars) {
if (vars[i].name == pieces[0].toString()) {
vars[i].values.push(pieces[1]);
} else {
vars.push({ "name" : pieces[0].toString(), "values" : [pieces[1]] });
}
}
} else {
vars.push({ "name" : pieces[0].toString(), "values" : [pieces[1]] });
}
}
if (qs != '') {
for (var i in vars) {
if (vars[i].name == qs) {
return vars[i].values;
}
}
return ['-1'];
}
return vars;
} else {
return [];
}
}
q();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment