Google Shopping Duplicates

Detect duplicate items

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Google Shopping Duplicates
// @namespace    https://www.latinsud.com
// @version      0.4
// @description  Detect duplicate items
// @author       LatinSuD
// @match        https://shoppinglist.google.com/lists/*
// @match        https://shoppinglist.google.com/u/0/lists/*
// @grant        none
// @license MIT
// ==/UserScript==

// ChangeLog:
//  0.4 (2022-04-24): Updated to new Google Shopping List UI (It won't work on the old one)

(function() {
    'use strict';

    var mydivd=document.createElement('DIV');

    document.body.appendChild(mydivd)
    mydivd.style="position: fixed; left: 3em; top: 0; z-index: 9999";

    var retraso=null;



    // Esta es la chicha
    function calcular() {
        console.log("Checking duplicates...")


        //var lista=Array.from(document.body.querySelectorAll('SPAN.listItemTitle'));
        var lista = Array.from(document.body.querySelector('INPUT[type=text]').parentElement.parentElement.parentElement.parentElement.querySelectorAll('DIV[role=button]'))

        var dups=""

        lista.forEach(function(e) {
            lista.some(function(f) {
                if (e==f) { return true; }

                // Try and detect plurals. This works better with spanish words.
                if (e.textContent.trim().toUpperCase().replace(/E?S *$/,"") == f.textContent.trim().toUpperCase().replace(/E?S *$/,"")) {
                    dups=dups+e.textContent +", ";
                    //console.log("BIEN");
                }

            })
        })

        mydivd.innerHTML="Duplicates: " + dups;
    }


    /****************************************/
    /*  CONFIGURAMOS EL OBSERVER Y EL TIMER */
    /****************************************/

    // selecciona el nodo target
    //var target = document.querySelector('#some-id');
    var target = document.body;


    // Configura el observer:
    var config = { attributes: false, childList: false, characterData: true, subtree: true };


    // Crea una instancia de observer
    var observer = new MutationObserver(function(mutations) {
        console.log(mutations)
        if (retraso) clearTimeout(retraso);


        retraso=setTimeout(calcular, 1000);
        console.log("FIN MUTACION")

        // pasa al observer el nodo y la configuracion
        //observer.observe(document.body, config);
    });


    // pasa al observer el nodo y la configuracion
    observer.observe(document.body, config);

    setTimeout(calcular,100);

})();