Skip to content

Instantly share code, notes, and snippets.

@austinpray
Last active August 29, 2015 14:05
Show Gist options
  • Save austinpray/bacfe57bea3b19304969 to your computer and use it in GitHub Desktop.
Save austinpray/bacfe57bea3b19304969 to your computer and use it in GitHub Desktop.
He asked to be able to differentiate between "get more spaces" buttons (top vs. bottom) and do the same for the "create a lumo" buttons.
function () {
// charlie pretends he is a programmer
var instructions = {
'what button?': 'get more button', // possible values: 'create lumo button' or 'get more button'
'which one?': 'top' //possible values: 'top' or 'bottom'
};
// ignore the rest here
var config = {
'get more button': {
'selector': '.sd-btn[href="/plans"]'
},
'create lumo button': {
'selector': '.sd-btn[href="#modal_create"]'
},
'top': function (nodelist) {
return nodelist[0];
},
'bottom': function (nodelist) {
return nodelist[nodelist.length-1];
}
};
// lol this is dumb
var elements = document.querySelectorAll(config[instructions['what button?']].selector) || {};
return config[instructions['which one?']](elements);
}
function () {
var config = {
'selectors': [
{
"name": "getMore"
, "selector": '.sd-btn[href="/plans"]'
},
{
"name": "createLumo"
, "selector": '.sd-btn[href="#modal_create"]'
}
]
};
var elements = [];
var found;
for (var i = 0; i < config.selectors.length; i++) {
found = Array.prototype.slice.call(document.querySelectorAll(config.selectors[i].selector));
if(found[0]) {
found[0].ascLocation = "top";
}
if(found[found.length-1]) {
found[found.length-1].ascLocation = "bottom";
}
elements = elements.concat(found);
}
return elements;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment