Price to time
April 20, 2020
A browser extension to give you knowledge about how much time to buy a product. It’s a simple tool to help you make a decision about whether to buy a product or not.
I made this extension to help me make a decision about whether to buy a product or not.
How to install the extension
Can be installed on: Firefox extension
You can install it on Chrome and Edge by downloading the source code and load it as an unpacked extension. Source
Configure your hourly rate in the extension option page
Go to any product page, you will see the time you need to work to buy that product
How it works
The extension will get the price of the product and convert it to your hourly rate. By finding the price element on the page and append to it the converted price.
Bellow is the code that does the conversion. It’s a simple function that takes the salary, the number of hours you work per month, and the number of hours you work per day. It will return a function that takes the price and convert it to time.
function run_convert(config) {
if (Object.keys(config).length === 0) {
save_default_config(config);
}
else {
const salary = parseInt(extract_prices(config.salary)[0], 10);
const month_hours = parseFloat(config.month_hours);
const hour_work_per_day = parseFloat(config.hour_work_per_day);
let filter = parse_filter(config.filter)
const time_currency = seconds_currency(salary, month_hours);
filter.map(x => {
const nodes = Array.from(document.body.getElementsByClassName(x));
price_2_time(nodes, time_currency, hour_work_per_day)
});
//special case
const nodes = Array.from(document.body.getElementsByClassName('a-price'));
nodes.filter(node => !has_p2t(node))
.map(node => {
set_p2tn(node);
const off_price = node.getElementsByClassName('a-offscreen')[0].innerText;
const off_price_time = assembly_price_time(extract_prices(off_price), time_currency, hour_work_per_day);
node.getElementsByClassName('a-price-fraction')[0].innerText += ` (${off_price_time.trim()})`
})
}
}
How to contribute
You can contribute by adding more filters to the extension. The filter is a list of class names that the extension will look for to convert the price. You can add a filter by adding the class name to the filter list in the extension option page.
You can customize the extension by changing the hourly rate, the number of hours you work per month, and the number of hours you work per day. And you can add more filters directly from the extension option page.