Ebay Popularity Sort

Sorts eBay™ search results by popularity (number of times sold)

当前为 2018-06-24 提交的版本,查看 最新版本

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

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

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

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

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

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Ebay Popularity Sort
// @version      1.0
// @description  Sorts eBay™ search results by popularity (number of times sold)
// @author       jomifepe
// @icon         https://www.ebay.com/favicon.ico
// @require      http://code.jquery.com/jquery-latest.min.js
// @include      https://www.ebay.com/sch/*
// @namespace https://greasyfork.org/users/192987
// ==/UserScript==

/* This is a port from the eBay™ Popularity Sort chrome extension.
Thanks to Elad Nava: https://github.com/eladnava/ebay-popularity-sort */

(function() {
    'use strict';

    // Wait for document to load
    $(document).ready(function () {
        // Array of search results
        var results = [];

        // Traverse search results
        $('ul.srp-results li.s-item, ul#ListViewInner li[listingid]').each(function () {
            // Convert to jQuery object
            var listing = $(this);

            // Default listing sold count to 0
            var soldCount = 0;

            // Extract hotness text
            var hotnessText = listing.find('.s-item__itemHotness, .hotness-signal').text().replace(/,/g, '');

            // Get sold count as integer
            soldCount = parseInt(hotnessText) || 0;

            // Count indicates number of users watching this item and not number of times sold?
            if (hotnessText.includes('watching')) {
                soldCount = 0;
            }

            // Count indicates a percentage discount and not number of times sold?
            if (hotnessText.includes('%')) {
                soldCount = 0;
            }

            // Add item sold count and listing itself
            results.push({ sold: soldCount, listing: listing });

            // Delete element temporarily
            listing.remove();
        });

        // Sort all listings by sold count DESC
        results.sort(function (a, b) {
            return b.sold - a.sold;
        });

        // Get search results parent list
        var ul = $('.srp-river-answer, #ListViewInner').first();

        // Warn the user about the modified result order
        ul.append('<p>These search results have been modified by <b><a href="https://github.com/eladnava/ebay-popularity-sort" target="_blank">eBay™ Popularity Sort</a></b>.</p>');

        // Re-add the sorted results
        results.forEach(function (item) {
            ul.append(item.listing);
        });
    });
})();