Ebay Include Shipping

Show the true total including shipping on Ebay

当前为 2018-03-28 提交的版本,查看 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name		Ebay Include Shipping
// @namespace	ebay_include_shipping
// @description	Show the true total including shipping on Ebay
// @homepageURL	https://github.com/daraeman/ebay_include_shipping
// @author		daraeman
// @version		1.0.2
// @date		2018-03-27
// @include		/https?:\/\/www\.ebay\.com\/*/
// @require		https://code.jquery.com/jquery-3.2.1.slim.min.js
// @require		https://cdnjs.cloudflare.com/ajax/libs/big.js/5.0.3/big.min.js
// ==/UserScript==

(function( $, Big ) {

	let page;

	function getPage() {
		if ( $( "#Results" ).length )
			page = "search";
	}

	function doPage() {
		if ( page === "search" )
			doSearchPage();
	}

	function doSearchPage() {

		// hide the "previous price" thing since its not very useful and screw up the formatting
		$( ".cmpat" ).hide();

		$( "#ListViewInner .sresult" ).each( ( i, node ) => {
			let el = $( node );
			let item_text = getItemPriceEl( el ).text().trim();
			let currency = item_text[0];
			let item_price = new Big( item_text.substr( 1 ) );
			let shipping_text = getShippingPriceEl( el ).text().trim().substr( 2 ).replace( "shipping", "" ).trim();	
			if ( shipping_text ) {
				let shipping_price = new Big( shipping_text );
				addSearchItemShippingPrice( el, item_price.plus( shipping_price ), currency );
			}
		});
	}

	function getItemPriceEl( parent, post_add ) {
		let selector = ( post_add ) ? ".bold:not( .ebay_include_shipping )" : ".bold";
		let this_parent = getShippingPriceParentEl( parent );
		return this_parent.find( selector );
	}

	function getShippingPriceEl( parent ) {
		return parent.find( ".lvshipping .ship .fee" );
	}

	function getShippingPriceParentEl( parent ) {
		return parent.find( ".lvprices .lvprice" );
	}

	function addSearchItemShippingPrice( el, price, currency ) {
		let price_parent_el = getShippingPriceParentEl( el );
		price_parent_el.prepend( '<span class="bold ebay_include_shipping">'+ currency + price.toFixed( 2 ).toString() +' incl. shipping</span><br>' );
		let item_price_el = getItemPriceEl( el, true );
		let shipping_price_el = getShippingPriceEl( el );
		item_price_el.text( "(" + item_price_el.text().trim() + shipping_price_el.text().trim().replace( "+", " + " ) +")" );
		item_price_el.removeClass( "bold" ).css( {
			"display": "inline-block",
			"margin-top": "4px",
			"font-size": "13px",
		});
		shipping_price_el.hide();
	}

	function init() {
		getPage();
		doPage();
	}

	init();

})( jQuery, Big );