Google Shopping Duplicates

Detect duplicate items

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 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);

})();