Skip to content

Instantly share code, notes, and snippets.

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 xioustic/b59fa7be8d70e7c763362dcc8e1417d2 to your computer and use it in GitHub Desktop.
Save xioustic/b59fa7be8d70e7c763362dcc8e1417d2 to your computer and use it in GitHub Desktop.
// MaverickLabel Asset Tags Incremental Price Quote
// https://www.mavericklabel.com/products/asset-tags-price.html
// incrementally increases quantity for a quote
// when stopped, prints csv output
var gather, STOP
function start_iteration() {
STOP = 0
var gather = []
var old_price = false
function recursive_lookup () {
// print current values
var id_input = document.querySelector('input#Quantity')
var cur_value = parseInt(id_input.value,10)
var price_span = document.querySelector('span#fd-PRICE')
var cur_price = price_span.textContent
// skip if we should still be waiting
if (cur_price === old_price) {
console.log("value hasn't changed, waiting")
} else if (cur_price.trim() === "") {
console.log("value is still loading, waiting")
} else {
old_price = cur_price
console.log(cur_value+","+cur_price)
gather.push([cur_value+","+cur_price])
// set new qty
id_input.value = cur_value+1
// simulate changed event for price lookup
var changed = new Event('change')
id_input.dispatchEvent(changed)
}
// recursive call
if (!STOP) {
setTimeout(recursive_lookup,2000)
} else {
console.log('stopping')
console.log(gather.join('\n'))
STOP = 0
gather = []
old_price = false
}
}
recursive_lookup()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment