Greasy Fork

Ebay Buy It Now by Price

Buy It Now, sort by price and Gallery view on Ebay

目前为 2015-01-07 提交的版本。查看 最新版本

// ==UserScript==
// @run-at document-start
// @name        Ebay Buy It Now by Price
// @namespace   EBINbP
// @description Buy It Now, sort by price and Gallery view on Ebay
// @version     1
// @include     http://www.ebay.tld/sch/*
// @include     https://www.ebay.tld/sch/*
// @grant       none
// ==/UserScript==

try {
    var url = document.location.toString();
    var updateUrl = url
    updateUrl = updateQueryStringParameter(updateUrl, 'LH_Auction', ''); // remove Auction
    updateUrl = updateQueryStringParameter(updateUrl, 'LH_BIN', '1');   // Buy it NOW parameter
    updateUrl = updateQueryStringParameter(updateUrl, '_sop', '15');   // Sort by price parameter
    updateUrl = updateQueryStringParameter(updateUrl, '_dmd', '2');   // Gallery view parameter

    //console.log(updateUrl);
    //console.log(url != updateUrl);
    if (url != updateUrl) {
        document.location = updateUrl;
    }
} catch (e) {}

function updateQueryStringParameter(uri, key, value) {
    var re = new RegExp("([?&])" + key + "=.*?(&|$)", "i");
    var separator = uri.indexOf('?') !== -1 ? "&" : "?";
    if (uri.match(re)) {
        return uri.replace(re, '$1' + key + "=" + value + '$2');
    } else {
        return uri + separator + key + "=" + value;
    }
}