Berry Blocker

Remove cloudberry from the Nespresso site

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

You will need to install an extension such as Tampermonkey to install this script.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्क्रिप्ट व्यवस्थापक एक्स्टेंशन इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्क्रिप्ट व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्टाईल व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

// ==UserScript==
// @name         Berry Blocker
// @namespace    http://tampermonkey.net/
// @version      0.2
// @description  Remove cloudberry from the Nespresso site
// @author       [email protected]
// @match        *://www.nespresso.com/*/order/capsules/original
// @match        *://www.nespresso.com/*/home
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    let handle;
    let tries = 20;

    const removeCloudBerry = () => {
        let success = false;
        tries--;
        if (tries <= 0) {
            clearInterval(handle);
            console.log("I can't find any cloudberries here...");
        }

        let berries = [
            { selector: 'article[data-product-code="7550.40"]', up: 1 },
            { selector: 'img[alt="Nordic Cloudberry Variation"]', up: 5 },
        ];

        berries.forEach(({ selector, up = 0 }) => {
            let ele = document.querySelector(selector);
            if (ele) {
                for (let i=0; i<up; i++) {
                    if (ele.parentNode) {
                        ele = ele.parentNode;
                    } else {
                        break;
                    }
                }

                ele.style.display = 'none'; // hide that nasty element
                console.log("I've hidden one of those nasty cloudberries");
                success = true;
            }
        });

        if (success) {
            console.log("I've gotten rid of the cloudberries, my job here is done.");
            clearInterval(handle);
        }
    };

    handle = setInterval(removeCloudBerry, 500);
})();