Ebay Include Shipping

Show the true total including shipping on Ebay

目前為 2018-03-28 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 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 );