Skip to content

Instantly share code, notes, and snippets.

@thejhh
Last active July 21, 2020 21:09
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 thejhh/1eca9125db84cbf4acbe421bced80901 to your computer and use it in GitHub Desktop.
Save thejhh/1eca9125db84cbf4acbe421bced80901 to your computer and use it in GitHub Desktop.
Bookmarklet to export order from holvi.com
#!/bin/bash
uglifyjs order-export.js --compress --mangle > min.js
sed -e 's/^function e(/function(/' -e 's/ /%20/g' min.js > min2.js
echo "javascript:($(cat min2.js))()"
javascript:(function(){var%20i=document,t="#store-home%20>%20div%20>%20div%20>%20div.center-padded%20>%20div.",d="a%20>%20app-list-item%20>%20div%20>%20div.data-row%20>%20div.data-row-main%20>%20div:nth-child(",e={title:d+"1)%20>%20div.col-md-7%20>%20div%20>%20app-list-item-header",amount:d+"2)%20>%20div:nth-child(1)%20>%20div%20>%20app-list-item-bottom-left%20>%20span",netPrice:d+"2)%20>%20div:nth-child(2)%20>%20div%20>%20app-list-item-bottom-middle%20>%20div%20>%20div:nth-child(1)%20>%20span",vatPercentage:d+"2)%20>%20div:nth-child(2)%20>%20div%20>%20app-list-item-bottom-middle%20>%20div%20>%20div:nth-child(2)%20>%20span",price:d+"2)%20>%20div:nth-child(3)%20>%20div%20>%20app-list-item-bottom-right"},n={question:"div%20>%20label",answer:"div%20>%20span%20>%20span"},o="#store-home%20>%20div%20>%20div%20>%20div.center-padded%20>%20div.tab-pages%20>%20div:nth-child(1)%20>%20section-block:nth-child(3)%20>%20section%20>%20div%20>%20section-content%20>%20",r=o+"app-list-item%20>%20div%20>%20div.data-row%20>%20div.data-row-main%20>%20div:nth-child(",a=o+"div:nth-child(2)%20>%20div:nth-child(",v={name:r+"1)%20>%20div.col-md-7%20>%20div%20>%20app-list-item-header",email:r+"2)%20>%20div:nth-child(1)%20>%20div%20>%20app-list-item-bottom-left",address:a+"1)%20>%20div%20>%20span",company:a+"2)%20>%20div%20>%20span",phone:o+"div:nth-child(3)%20>%20div%20>%20div%20>%20span"};function%20c(i,t){if(!t)throw%20new%20Error("!element");var%20d=t.querySelector(i);return%20d?d.href:""}function%20l(i,t){if(!t)throw%20new%20Error("!element");for(var%20d=t.querySelectorAll(i),e=0,n=[];e<d.length;e++)n.push(d[e]);return%20n}function%20h(d,e){if(!e)throw%20new%20Error("!element");return%20Object.keys(d).reduce(function(i,t){return%20i[t]=function(i,t){if(!t)throw%20new%20Error("!element");var%20d=t.querySelector(i);return%20d?d.textContent:""}(d[t],e),i},{})}var%20s={order:h({title:"#actionableNav%20>%20span:nth-child(2)%20>%20span%20>%20actionable-nav-subtitle%20>%20span%20>%20span",orderId:t+"row.my-4%20>%20div%20>%20div:nth-child(1)%20>%20span",receiptId:t+"row.my-4%20>%20div%20>%20div:nth-child(2)%20>%20span",productTitle:t+"tab-pages%20>%20div:nth-child(1)%20>%20section-block:nth-child(1)%20>%20section%20>%20div%20>%20section-content%20>%20div%20>%20a%20>%20app-list-item%20>%20div%20>%20div.data-row%20>%20div.data-row-main%20>%20div:nth-child(1)%20>%20div.col-md-7%20>%20div%20>%20app-list-item-header",totalSum:t+"tab-pages%20>%20div:nth-child(1)%20>%20section-block:nth-child(1)%20>%20section%20>%20div%20>%20section-content%20>%20app-list-item%20>%20div%20>%20div.data-row%20>%20div.data-row-main%20>%20div:nth-child(2)%20>%20div:nth-child(3)%20>%20div%20>%20app-list-item-bottom-right"},i),client:h(v,i),items:l("#store-home%20>%20div%20>%20div%20>%20div.center-padded%20>%20div.tab-pages%20>%20div:nth-child(1)%20>%20section-block:nth-child(1)%20>%20section%20>%20div%20>%20section-content%20>%20div",i).map(function(i){var%20t=h(e,i);return%20t.productId=function(i,t){for(var%20d=c(i,t).split("/");d.length;){if("product"===d.shift()&&d.length)return%20d.shift()}return""}("a",i),t.publicUrl="https://holvi.com/shop/sendanor/product/"+t.productId+"/",t.editUrl=c("a",i),t.questions=l("div%20>%20div%20>%20div%20>%20div.product-additional-data-questions%20>%20div%20>%20div",i).map(function(i){return%20h(n,i)}).reduce(function(i,t){return%20i[t.question]=t.answer,i},{}),t})};prompt("Here's%20your%20data:%20",JSON.stringify(s,null,2))})()
// noinspection JSUnusedGlobalSymbols
/**
*
* @returns {{client: {}, items: {}[], order: {}}}
*/
function e () {
var doc = document;
var SHOP_NAME = 'sendanor';
var orderBaseSelector = '#store-home > div > div > div.center-padded > div.';
var orderSelectors = {
title : '#actionableNav > span:nth-child(2) > span > actionable-nav-subtitle > span > span',
orderId : orderBaseSelector + 'row.my-4 > div > div:nth-child(1) > span',
receiptId : orderBaseSelector + 'row.my-4 > div > div:nth-child(2) > span',
productTitle : orderBaseSelector + 'tab-pages > div:nth-child(1) > section-block:nth-child(1) > section > div > section-content > div > a > app-list-item > div > div.data-row > div.data-row-main > div:nth-child(1) > div.col-md-7 > div > app-list-item-header',
totalSum : orderBaseSelector + 'tab-pages > div:nth-child(1) > section-block:nth-child(1) > section > div > section-content > app-list-item > div > div.data-row > div.data-row-main > div:nth-child(2) > div:nth-child(3) > div > app-list-item-bottom-right'
};
var itemsSelector = '#store-home > div > div > div.center-padded > div.tab-pages > div:nth-child(1) > section-block:nth-child(1) > section > div > section-content > div';
var itemBaseSelector = 'a > app-list-item > div > div.data-row > div.data-row-main > div:nth-child(';
var itemSelectors = {
title : itemBaseSelector + '1) > div.col-md-7 > div > app-list-item-header',
amount : itemBaseSelector + '2) > div:nth-child(1) > div > app-list-item-bottom-left > span',
netPrice : itemBaseSelector + '2) > div:nth-child(2) > div > app-list-item-bottom-middle > div > div:nth-child(1) > span',
vatPercentage : itemBaseSelector + '2) > div:nth-child(2) > div > app-list-item-bottom-middle > div > div:nth-child(2) > span',
price : itemBaseSelector + '2) > div:nth-child(3) > div > app-list-item-bottom-right'
};
var itemProductLinkSelector = 'a';
var itemQuestionsSelector = 'div > div > div > div.product-additional-data-questions > div > div';
var questionSelectors = {
question: 'div > label',
answer: 'div > span > span'
};
var clientBaseSelector = '#store-home > div > div > div.center-padded > div.tab-pages > div:nth-child(1) > section-block:nth-child(3) > section > div > section-content > ';
var clientBaseSelector2 = clientBaseSelector + 'app-list-item > div > div.data-row > div.data-row-main > div:nth-child(';
var clientBaseSelector3 = clientBaseSelector + 'div:nth-child(2) > div:nth-child(';
var clientSelectors = {
name : clientBaseSelector2 + '1) > div.col-md-7 > div > app-list-item-header',
email : clientBaseSelector2 + '2) > div:nth-child(1) > div > app-list-item-bottom-left',
address : clientBaseSelector3 + '1) > div > span',
company : clientBaseSelector3 + '2) > div > span',
phone : clientBaseSelector + 'div:nth-child(3) > div > div > span'
};
/**
*
* @param {string} selector
* @param element
* @returns {*}
*/
function getText (selector, element) {
if (!element) throw new Error('!element');
var e = element.querySelector(selector);
return e ? e.textContent : '';
}
/**
*
* @param {string} selector
* @param element
* @returns {*}
*/
function getHref (selector, element) {
if (!element) throw new Error('!element');
var e = element.querySelector(selector);
return e ? e.href : '';
}
function getProductId (selector, element) {
var items = getHref(selector,element).split('/');
while (items.length) {
var item = items.shift();
if (item === 'product') {
if (items.length) {
return items.shift();
}
}
}
return '';
}
/**
*
* @param {string} selector
* @param element
* @returns {*[]}
*/
function getItems (selector, element) {
if (!element) throw new Error('!element');
var result = element.querySelectorAll(selector);
var i = 0;
var list = [];
for (; i < result.length; i++) {
list.push(result[i]);
}
return list;
}
/**
*
* @param {Object.<string, string>} selectors
* @param element
*/
function getObject (selectors, element) {
if (!element) throw new Error('!element');
return Object.keys(selectors).reduce(
function (obj, key) {
obj[key] = getText(selectors[key], element);
return obj;
},
{}
);
}
var data = {
order: getObject(orderSelectors, doc),
client: getObject(clientSelectors, doc),
items: getItems(itemsSelector, doc).map(function(itemElement) {
var item = getObject(itemSelectors, itemElement);
item.productId = getProductId(itemProductLinkSelector, itemElement);
item.publicUrl = 'https://holvi.com/shop/' + SHOP_NAME + '/product/' + item.productId + '/';
item.editUrl = getHref(itemProductLinkSelector, itemElement);
item.questions = getItems(itemQuestionsSelector, itemElement).map(
function(q) { return getObject(questionSelectors, q); }
).reduce(function(obj, item) {
obj[item.question] = item.answer;
return obj;
}, {});
return item;
})
};
prompt("Here's your data: ", JSON.stringify(data, null, 2));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment