Last active
August 29, 2015 14:05
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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