Greasy Fork 还支持 简体中文。

eBay hide duplicate results updated

easy toggle to show or hide bunches of repeated results in eBay searches

Versione datata 04/03/2017. Vedi la nuova versione l'ultima versione.

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

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

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

// ==UserScript==
// @name           eBay hide duplicate results updated
// @description    easy toggle to show or hide bunches of repeated results in eBay searches
// @namespace      [email protected]
// @include        http://*search.ebay.co.uk/*
// @include        http://*search.ebay.com/*
// @include        http://*shop.ebay.co.uk/*
// @include        http://*shop.ebay.com/*
// @include        http://www.ebay.com/sch/*
// @version        1.0
// ==/UserScript==

/*
This is a version of znerp's eBay hide duplicate results script from
userscripts.org that works on http://www.ebay.com/sch/.  I don't know
if it still works on the other urls that are included or even if they
still exist.

It has been extended slightly to allow for almost identical
descriptions to still count as a match and to report the number of
duplicates next to the plus/minus icons.

There was no license specified on the original code so I assume that
znerp meant to dedicate his version to the public domain.  This
version is therefore also dedicated to the public domain.

[email protected]

*/

var TAG = 'ebhdru: ';
console.log(TAG + 'start');

var plus = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAIAAACQkWg2AAAABnRSTlMA%2FwD%2FA" +
    "P83WBt9AAAAZElEQVR4nL2SUQ6AMAhDH2Q38v430DPhh4YsyHCLif0jK21hiJkBIgdvMNsAnWQ7TWCfYTtacKzl" +
    "70jp8yhn3lBguaH1RYjhZT%2FeNwdXurTTvf08tKP4xOXT0Poins5aBwhs4ATOOiHsGI5R2gAAAABJRU5ErkJgg" +
    "g%3D%3D"
var minus = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAIAAACQkWg2AAAABnRSTlMA%2FwD%2F" +
    "AP83WBt9AAAACXBIWXMAAA7EAAAOxAGVKw4bAAAARklEQVR4nGP8%2F%2F8%2FAwMDIyMjAyEAUQmjiAMkKYYCh" +
    "Evw64a7mYlUG2ivAQHw%2BAFZimQbWIi0hHwb6BlKxAJSEx8T8XogygC6eSP5CxYWpwAAAABJRU5ErkJggg%3D%" +
    "3D"
var thisResult, nextResult

switch (true) {
case /search/.test(location.host):
    console.log(TAG + 'found search');
    handlePagesNamedSearch();
    break;
case /shop/.test(location.host):
    console.log(TAG + 'found shop');
    handlePagesNamedShop();
    break;
default:
    console.log(TAG + 'found other');
    handleOtherPages();
    break;    
}

function handlePagesNamedSearch(){
    console.log(TAG + 'handlePagesNamedSearch');
    
    var allResults = document.evaluate('//table[@class="ebItemlist single"]/tbody/tr[contains(@class,"single")]/td[@class="ebcTtl"]/h3/a',
                                       document,
                                       null,
                                       XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,
                                       null);
    
    for (i = 0; i < allResults.snapshotLength - 1; i++) {
        thisResult = allResults.snapshotItem(i)
        nextResult = allResults.snapshotItem(i + 1)
        if (thisResult.textContent == nextResult.textContent) {
            nextResult.parentNode.parentNode.parentNode.style.display = "none"
            nextResult.parentNode.parentNode.parentNode.setAttribute("znerp", "hidden")
            nextResult.parentNode.appendChild(document.createTextNode("  <<duplicate>>"))
            if (thisResult.parentNode.parentNode.parentNode.style.display != "none") {
                icon = document.createElement("img")
                icon.src = plus
                icon.setAttribute("style", "padding: 3px; cursor: pointer;")
                thisResult.parentNode.parentNode.insertBefore(icon, thisResult.parentNode.parentNode.firstChild)
                icon.addEventListener(
                    'click',
                    function() {
                        this.src = (this.src == plus
                                    ? minus
                                    : plus)
                        foo = this.parentNode.parentNode
                        if (this.src == minus)
                            while((foo = foo.nextSibling).getAttribute("znerp") == "hidden") {
                                foo.style.display = ""
                                foo.setAttribute("znerp", "showing")
                            }
                        else
                            while((foo = foo.nextSibling).getAttribute("znerp") == "showing") {
                                foo.style.display = "none"
                                foo.setAttribute("znerp", "hidden")
                            }
                    },
                    true)
            }
        }
    }
    
    var otherStuff = document.evaluate('//table[@class="ebItemlist single"]/tbody/tr/td/script',
                                       document,
                                       null,
                                       XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,
                                       null);
    
    for (i = otherStuff.snapshotLength - 1; i >= 0; i--)
        (foo = otherStuff.snapshotItem(i).parentNode.parentNode).parentNode.removeChild(foo)
    
}


function handlePagesNamedShop(){
    console.log(TAG + 'handlePagesNamedShop');

    var allResults = document.evaluate('//div[contains(@class,"lview")]/table[@class="nol"]/tbody/tr/td[@class="details"]/div[@class="ttl"]/a',
                                       document,
                                       null,
                                       XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,
                                       null);
    for (i = 0; i < allResults.snapshotLength - 1; i++) {
        thisResult = allResults.snapshotItem(i)
        nextResult = allResults.snapshotItem(i + 1)
        if (thisResult.textContent == nextResult.textContent) {
            nextResult.parentNode.parentNode.parentNode.parentNode.parentNode.style.display = "none"
            nextResult.parentNode.parentNode.parentNode.parentNode.parentNode.nextSibling.style.display = "none"
            nextResult.parentNode.parentNode.parentNode.parentNode.parentNode.setAttribute("znerp", "hidden")
            nextResult.parentNode.parentNode.parentNode.parentNode.parentNode.nextSibling.setAttribute("znerp", "hidden")
            nextResult.parentNode.appendChild(document.createTextNode("  <<duplicate>>"))
            if (thisResult.parentNode.parentNode.parentNode.parentNode.parentNode.style.display != "none") {
                icon = document.createElement("img")
                icon.src = plus
                icon.setAttribute("style", "padding: 3px; cursor: pointer;")
                thisResult.parentNode.parentNode.insertBefore(icon, thisResult.parentNode.parentNode.firstChild)
                icon.addEventListener(
                    'click',
                    function() {
                        this.src = (this.src == plus
                                    ? minus
                                    : plus)
                        foo = this.parentNode.parentNode.parentNode.parentNode
                        if (this.src == minus)
                            while((foo = foo.nextSibling.nextSibling.nextSibling).getAttribute("znerp") == "hidden") {
                                foo.style.display = ""
                                foo.nextSibling.style.display = ""
                                foo.setAttribute("znerp", "showing")
                                foo.nextSibling.setAttribute("znerp", "showing")
                            }
                        else
                            while((foo = foo.nextSibling.nextSibling.nextSibling).getAttribute("znerp") == "showing") {
                                foo.style.display = "none"
                                foo.nextSibling.style.display = "none"
                                foo.setAttribute("znerp", "hidden")
                                foo.nextSibling.setAttribute("znerp", "hidden")
                            }
                    },
                    true)
            }
        }
    } 
}


function handleOtherPages(){
    console.log(TAG + 'handleOtherPages');
    
    var allResults = document.evaluate('//a[contains(@class,"vip")]',
                                       document,
                                       null,
                                       XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,
                                       null);
    console.log(TAG + ' len:' + allResults.snapshotLength);
    
    var duplicateCount = 0;
    for (i = 0; i < allResults.snapshotLength - 1; i++) {
        console.log(TAG + ' i:' + i);
        thisResult = allResults.snapshotItem(i)
        nextResult = allResults.snapshotItem(i + 1)
        console.log(TAG + ' tr: ' + thisResult.textContent);
        if (match(thisResult.textContent, nextResult.textContent)) {
            console.log(TAG + ' matched');
            var thisHeading = thisResult.parentNode;
            var nextHeading = nextResult.parentNode;
            var thisListItem = thisHeading.parentNode;
            var nextListItem = nextHeading.parentNode;
            console.log(TAG + ' l: ' + nextListItem.className);
            nextListItem.style.display = "none"
            nextListItem.setAttribute("znerp", "hidden")
            console.log(TAG + ' a');
            duplicateCount++;
            nextHeading.appendChild(document.createTextNode("  <<duplicate " + duplicateCount +">>"));
            console.log(TAG + ' b');
            console.log(TAG + ' c');
            console.log(TAG + ' duplicateCount: ' + duplicateCount);
            if (thisListItem.style.display != "none") {
                console.log(TAG + ' add icon');
                icon = addIcon(thisListItem);
            }
        } else {
            if (duplicateCount != 0){
                console.log(TAG + ' show dup count');
                var dups = document.createTextNode(duplicateCount + ' duplicates');
                icon.parentNode.insertBefore(dups, icon);
                duplicateCount = 0;
            }
        }
    }
    console.log(TAG + ' otherStuff');
    
    var otherStuff = document.evaluate('//table[@class="ebItemlist single"]/tbody/tr/td/script',
                                       document,
                                       null,
                                       XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,
                                       null);
    
    for (i = otherStuff.snapshotLength - 1; i >= 0; i--)
        (foo = otherStuff.snapshotItem(i).parentNode.parentNode).parentNode.removeChild(foo)
    
}

// A slightly fuzzy match.  At the momemnt it simply lops off the
// first and last two characters and checks to see if ewhat remains is
// an exact match.  The reason for ignoring the leadinga trailing
// characters is that vendors often add spurious characters to
// distinguish otherwise identical descriptions.  Should be replaced
// with a more sophisticated measure which also includes the price.
function match(s1, s2) {

    var a1 = s1.substring(2, s1.length - 2);
    var a2 = s2.substring(2, s2.length - 2);
    return a1 == a2;
}

// Add the plus icon to the beginning of the specified element and
// attach a click event handler to reveal or hide the duplicates.
function addIcon(thisListItem) {
    
    icon = document.createElement("img")
    icon.src = plus
    icon.setAttribute("style", "padding: 3px; cursor: pointer;")
    thisListItem.insertBefore(icon, thisListItem.firstChild)
    icon.addEventListener(
        'click',
        function() {
            this.src = (this.src == plus 
                        ? minus
                        : plus)
            listItem = this.parentNode;
            if (this.src == minus)
                while((listItem = listItem.nextSibling).getAttribute("znerp") == "hidden") {
                    listItem.style.display = ""
                    listItem.setAttribute("znerp", "showing")
                }
            else
                while((listItem = listItem.nextSibling).getAttribute("znerp") == "showing") {
                    listItem.style.display = "none"
                    listItem.setAttribute("znerp", "hidden")
                }
        },
        true)
    return icon;
}

console.log(TAG + 'finish');