Skip to content

Instantly share code, notes, and snippets.

@seanemmel-ba
Last active April 25, 2016 18:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save seanemmel-ba/f82fd8a5f10af97e153d to your computer and use it in GitHub Desktop.
Save seanemmel-ba/f82fd8a5f10af97e153d to your computer and use it in GitHub Desktop.
A bookmarklet that adds experiment ID info to each experiment summary row in the Qubit Dashboard on the "Live" and "Drafts" tabs for ease of reference.
javascript:(function() {
/**
* @package N/A
* @version 1.2 //=> 4/25/2016
* @author Blue Acorn <code@blueacorn.com>, Sean Emmel <sean.emmel@blueacorn.com>
* @copyright Copyright © 2016 Blue Acorn.
*
* LAST UPDATED: 4/25/2016
@FIXES:
* Changing latest_dom_el_dependency/selectors and associated fn for
* retrieving exp ID after Qubit interface updates rolled out on 4/19/16
*
* Errors? Email me: <sean.emmel@blueacorn.com>
*/
/* Quick check for latest DOM el dependency. If not found, exit. */
var gist_ref = 'https://gist.github.com/seanemmel-ba/f82fd8a5f10af97e153d';
var error_msg = "Error! You must be in the Qubit Dashboard on the 'Live', 'Paused', or 'Drafts' tabs. If you are, then this bookmarklet may be broken. Check here for the latest version: " + gist_ref;
var latest_dom_el_dependency = document.querySelector('.SummaryList-experiments .Summary-experimentLink');
if (!latest_dom_el_dependency) {
alert(error_msg);
return;
}
/* Constructor */
function Summary() {
this.styles = '.exp-id-info { padding: 0 20px; color: red; font-weight: bold; font-size: 15px; } .exp-id-info .exp-id-header { text-decoration: underline; } .exp-id-info .exp-id { margin-left: 10px; }';
}
Summary.prototype = {
/* querySelectorAll - convert arguments to array quick helper */
_qsa: function(selector) {
return Array.prototype.slice.call(document.querySelectorAll(selector));
},
createAndAddStylesheet: function(styles) {
var css = document.createElement('style');
css.type = 'text/css';
css.id = "qubit-expID-info-styles";
if (css.styleSheet) {
css.styleSheet.cssText = styles;
} else {
css.appendChild(document.createTextNode(styles));
}
document.getElementsByTagName('head')[0].appendChild(css);
},
getExpIdFromLink: function(anchor) {
return anchor.getAttribute('href').split('experiences/')[1];
},
buildExpIdRow: function(id) {
var wrap = document.createElement('div');
var html = '<span class="exp-id-header">EXPERIMENT ID:</span><span class="exp-id"> ' + id + '</span>';
wrap.setAttribute('class', 'exp-id-info');
wrap.innerHTML = html;
return wrap;
},
addExpIdInfo: function() {
var i, id, target_div;
var self = this;
var anchors = this._qsa('.SummaryList-experiments .Summary-experimentLink');
var summary_info = this._qsa('.SummaryList-experiments .Summary-experimentLink');
for (i = 0; i < anchors.length; i++) {
id = this.getExpIdFromLink(anchors[i]);
target_div = summary_info[i];
target_div.appendChild(this.buildExpIdRow(id));
}
},
init: function() {
this.createAndAddStylesheet(this.styles);
this.addExpIdInfo();
}
};
var summary = new Summary();
summary.init();
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment