Giter VIP home page Giter VIP logo

ikeaprices's Introduction

IKEA price comparison magic button

A customizable magic button (bookmarklet) to compare IKEA prices across countries.

Try it! โ†’ http://mnazarov.github.io/ikeaprices

Idea

Living in a small country like Belgium, sometimes it pays to drive over the border to get a good deal. Depending on the location in Belgium, within 1-2 hours it is possible to reach IKEA in the Netherlands, Germany or France. Out of desire to save and curiosity this tool was born.

Implementation

Since most of the IKEA international websites are located at the same www.ikea.com domain, we can use client-side AJAX requests to other country websites from any product page, favorites list or shopping cart. Unfortunately there are some exceptions, such as www.ikea.lt or www.ikea.cn, and this approach won't work for them because of Cross-Origin Resource Sharing (CORS) policies.

The product URLs have the following structure: www.ikea.com/xx/yy/p/zzz/

where xx is the country code (like "be" or "gb"), yy is the language code ("nl" or "en"), and zzz is the product description with article number (like kyrre-kruk-berken-60416925) or just article number prefixed with "-". Luckily for us, even if the product description part of the URL is language-specific, the same links still work when changing the country/language combination.

Product pages

Now, starting from a product page we can perform the following steps:

  1. Get the URL of the current page and split it into country and product information parts:
    var url = window.location.pathname; 
    var country = url.slice(1, 6);    // e.g. "be/nl"
    var urlProduct = url.slice(6, );  // e.g. "kyrre-kruk-berken-60416925"
  2. Make a list of countries we want to compare to, and for each of the country/language codes fetch the corresponding page:
    fetch("https://www.ikea.com/" + countryToCompare + urlProduct)
  3. Parse it to find the price - we use the div element with class range-revamp-pip-price-package__main-price which contains the price together with the currency symbol:
    var doc = new DOMParser().parseFromString(data, "text/html");
    var price = doc.evaluate("//div[@class='range-revamp-pip-price-package__main-price']", doc, null, 4, null).iterateNext().textContent;
  4. Show it on the current page by creating an element (linking to the country page) and appending it to the currently shown price which can be found with:
    document.querySelector("div.range-revamp-pip-price-package__main-price").appendChild(...)

Favorites list and shopping cart pages

Using similar ideas, we can extend the functionality to pages with multiple products, such as favorites lists and shopping carts. Instead of the 1st step above, we identify products on the page and their product URLs, then we fetch the prices for each product as described in steps 2 and 3 above, and finally display the obtained prices on the page.

The full code can be consulted in the ikea.js file in the repostiory.

ikeaprices's People

Contributors

mnazarov avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

fdammeke rth-10

ikeaprices's Issues

Price comparisons on favourites

Hi

Great tool. Will test it out more.

Would be interesting to be able to run on the favourites/shopping list so to compare multiple products at the same time.

isse

OVerflow:

the script doesnt work right now, runs in a overflow.

Do you have time to have a look and repair?

Much appreciated

Doesn't work anymore

Hello,

The script doesn't seem to work anymore - clicking the bookmark has simply no effect, even on the provided demo product.

Regards.

Currency conversion

I love this script but I still have to manually do conversion for countries that are not using euros. What would be awesome would be to have the option to display a converted price in a selected currency!

Example:
Price on website used
Country code | price local currency | price converted in selected currency

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.