LAZY AF
- Step 1. Load console-save.js
- Step 2. Load namecheap-cart-scraper.js
- Step 3. Convert with https://json-csv.com/
- Step 4. Load to Google Spreadsheet
LAZY AF
| // thanks to this guy: | |
| // http://www.declancook.com/save-json-file-from-chrome-developer-tools/ | |
| (function(console){ | |
| console.save = function(data, filename){ | |
| if(!data) { | |
| console.error('Console.save: No data') | |
| return; | |
| } | |
| if(!filename) filename = 'console.json' | |
| if(typeof data === "object"){ | |
| data = JSON.stringify(data, undefined, 4) | |
| } | |
| var blob = new Blob([data], {type: 'text/json'}), | |
| e = document.createEvent('MouseEvents'), | |
| a = document.createElement('a') | |
| a.download = filename | |
| a.href = window.URL.createObjectURL(blob) | |
| a.dataset.downloadurl = ['text/json', a.download, a.href].join(':') | |
| e.initMouseEvent('click', true, false, | |
| window, 0, 0, 0, 0, 0, | |
| false, false, false, false, 0, null) | |
| a.dispatchEvent(e) | |
| } | |
| })(console) |
| var $cartItem, | |
| name, | |
| price, | |
| options = []; | |
| function processGroup() { | |
| var $cartItem = $(this).first('div.cart-item > div'); | |
| var name = $cartItem.find('strong')[0].nextSibling.data.replace(/\s+/g, ''); | |
| var price = parseFloat($cartItem.find('div.price > span.amount')[0].innerText.substring(1)); | |
| options.push({ | |
| name: name, | |
| price: price | |
| }) | |
| } | |
| function sortOptions(a, b) { | |
| return a.price - b.price; | |
| } | |
| function toCSV(obj) { | |
| console.log(obj.name, ',', obj.price); | |
| } | |
| $('div.product-group').each(processGroup); | |
| options.sort(sortOptions); | |
| options.forEach(toCSV); |