Skip to content

Instantly share code, notes, and snippets.

@bluelovers
Last active December 16, 2015 05:18
Show Gist options
  • Save bluelovers/5383032 to your computer and use it in GitHub Desktop.
Save bluelovers/5383032 to your computer and use it in GitHub Desktop.
Shopping_Tool_SC.user.js
// ==UserScript==
// @name Shopping Tool SC
// @namespace bluelovers
// @include http*://shopping.pchome.com.tw/*
// @include http*://buy.yahoo.com.tw/*
// @include http*://search.buy.yahoo.com.tw/*
// @include http*://ecshweb.pchome.com.tw/search/*
// @include http*://tw.mall.yahoo.com/*
// @version 1
// @author bluelovers
// @exclude *.js*
// @exclude *.css*
// @grant none
// @require http://code.jquery.com/jquery-latest.js?KU201
// @require https://gist.github.com/bluelovers/5046969/raw/UserScript%20Framework.js?KU207
// ==/UserScript==
(function($){$(function(){
var _url = window.location.href;
var _url_obj = parse_url(_url);
var _url_host = _url_obj.host;
if (_url_host.match(/shopping\.pchome\.com\.tw/))
{
_url_obj.query = _url_obj.query || '';
//alert(_url_obj.query);
// http://shopping.pchome.com.tw/?mod=item&func=exhibit&IT_NO=DRAA3I-A66929774&SR_NO=DRAA3I&ROWNO=3
if (_url_obj.query.match(/mod=item&(?:amp;)?func=exhibit/) || $('#order[action="/?mod=item&func=order"]').size())
{
var _div = $('<div/>');
_div.append($('#loading').html());
var _order = $('#order');
var _order_id = _order.find('> table:eq(0)');
var _order_head = _order.find('> table:eq(1)');
var _price_table = $('#p_it_price').parents('table:eq(0)');
// _price_table.after(_div.css('text-align', 'left'));
// var _td = _price_table.parents('td:first').attr({rowspan:1, colspan:3, align:'center'});
//
// _td.prevAll().remove();
_price_table.width('auto').parent('td').attr('align', 'left').css('padding-left', 10);
_price_table.parents('table:first').find('table[onmouseout="hideLoadingLay()"]')
.after(_div.css('text-align', 'left')).remove();
_div.find('table:first').attr('align', 'center');
_div.find('table:first').css('min-width', '190').find('table:first').width('100%');
var _p_it_price = $('#p_it_price').text();
_div
.find('table table tr')
.each(function(){
var _this = $(this);
var _i1 = _this.find('td:eq(0) font > font:first').text();
var _i2 = _this.find('td:eq(1)').text().replace(/^\$/, '');
var _i3 = _i1 * _i2;
var _td1 = _this.find('td:eq(1)').clone();
var _more = (_i3 > _p_it_price) ? true : false;
_td1.find('font').text(_more ? '$' + _i3 : '').css('color', 'blue');
var _td2 = _this.find('td:eq(1)').clone();
if (_more)
{
_td2.find('font').text('$' + (_i3 - _p_it_price)).css('color', '#fff');
_td2.css({'background-color':'#E21679'});
}
else
{
_td2.empty();
}
_this.append(_td1);
_this.append(_td2);
})
;
var _title = $('title').text();
/**
* %E3%80%8A = 《
* %E3%80%8B = 》
**/
_title = decodeURIComponent(encodeURIComponent(_title).replace(/^(.+)(%E3%80%8A.+%E3%80%8B)$/, '$2$1'));
$('title').text(_title);
}
// http://shopping.pchome.com.tw/?mod=store&func=style_show&SR_NO=DRAA3I&show=1
else if (_url_obj.query.match(/mod=store&(?:amp;)?func=style_show/) || $('img[src$="24h_bar.gif"], input[name="showbutton"]').size())
{
// var _list = $('input[name="showbutton"]').parents('table:eq(1)').parent('td').find('> table:eq(6), > table:eq(8)');
var _title = $('title').text();
_title = _title.replace(/^([^\-]+)\-\s+(.+)$/, '$2 - $1');
$('title').text(_title);
var _list;
if ($('input[name="showbutton"]').size())
{
var _list = $('input[name="showbutton"]').parents('table:eq(1)').nextAll('table').filter(':not(:has(.pgNumber))');
}
else
{
var _list = $('img[src$="24h_bar.gif"]').parents('table:eq(0)').nextAll('table').filter(':not(:has(.pgNumber))');
}
// _list.css('border', '1px solid red');
_list.find('a').attr('target', '_blank');
var _items = _list
.find('td[width=148]:has(> table[width=148], > table[width=140]), td[width=145]:has(> table[width=140]), table[width=780] tr:has(> td.small8)')
;
var _itemlist = [];
_items
.each(function(indexInArray, valueOfElement){
var _tmp = $(this);
var _this;
var _desc;
if (_tmp.is('tr'))
{
_this = _tmp.children();
_this.filter('td.small8').find('font[color="#888888"] div:first')
// .css('border', '1px solid red')
.css('height', 'auto')
.css('overflow', '')
.wrapInner('<font size="2" />')
;
}
else
{
_this = _tmp.find('> table');
_desc = _this.find('font.text12[color="#666666"] div:first').text();
_this
.attr('title', _desc)
.find('.text13Link img')
.attr('title', _desc)
;
}
var _price = parseInt(_this
.find('.textprice03, .textprice02_search')
.first()
.text()
);
var _title = _this
.find('.text13Link > font, font[color="#0000FF"] div a font b.text16')
.first()
.text()
;
_data = {
idx: indexInArray,
obj: _this,
val: _price,
title: _title
};
_itemlist[indexInArray] = _data;
_this
.data(_data)
;
})
;
// _uf_log(_itemlist);
var _func = function(mode){
var _arr = $(_itemlist);
if (mode == 1)
{
_arr
.sort(function(a, b){
return a.val > b.val ? 1 : -1;
})
;
}
else if (mode == 2)
{
_arr
.sort(function(a, b){
return a.val < b.val ? 1 : -1;
})
;
}
else
{
mode = 0;
_arr
.sort(function(a, b){
return a.idx > b.idx ? 1 : -1;
})
;
}
_arr
.each(function(i, v){
this.obj.appendTo(_items.eq(i));
})
;
_div.find('a').css('color', '#0000ff').eq(mode).css('color', '#000000');
};
var _div = $('<div class="sort-type text12">排序:</div>')
.append($('<a/>').click(function(){
_func(0);
}).text('優先推薦'))
.append($('<a/>').click(function(){
_func(1);
}).text('價格低至高'))
.append($('<a/>').click(function(){
_func(2);
}).text('價格高至低'))
.css({
'background-color': '#EAEAEA',
'border-top': '1px solid #EEEEEE',
'font-size': '13px',
'height': '30px',
'line-height': '30px',
'margin-bottom': '10px',
'margin-top': '10px',
'padding': '0 1em',
})
;
_div
.find('a')
.css({
'color': '#000000',
'text-decoration': 'none'
})
.attr('href', 'javascript:void(0);')
.filter(':not(:first)')
.css({
'color': '#0000ff',
})
.before($('<span> | </span>'))
;
_items.eq(0).parents('table:first').before(_div);
}
else
{
_uf_log(_url_obj);
}
$('.text13List a[href*="mod=store&func=style_show"], .text13List a[href*="m=index&f=view"]').attr('target', '_blank');
}
else if (_url_host.match(/ecshweb\.pchome\.com\.tw/))
{
// $('a[href*="q="]').attr('target', '_blank');
$('a[href*="shopping.pchome.com.tw"]').attr('target', '_blank');
_uf_log(_url_host);
}
else if (_url_host.match(/.+\.buy\.yahoo\.com\.tw/))
{
$('.pd-image, .pd-desc .title, #srp-pdclass').find('a').attr('target', '_blank');
}
else if (_url_host.match(/buy\.yahoo\.com\.tw/))
{
$('#cl-catproduct').find('a').attr('target', '_blank');
$(window).one('load', function(){
$('#rightcx')
.find('#cl-vvrecmd a')
.each(function(){
var _this = $(this);
var _clone = _this.clone();
_this.after(_clone).remove();
_clone.attr('target', '_blank');
})
;
});
$('.pdbound, .pdbox, .sitelist .list, .sitelist .stitle, #cl-pdintro .content .tab-content .Notes').find('a').attr('target', '_blank');
_uf_log(_url_obj);
if (_url_obj.query.match(/gdid=/))
{
$('.RightItro .promoGift')
.hover(function(){
$(this).find('.bd').show();
}, function(){
$(this).find('.bd').hide();
})
.find('.bd')
;
$('td[background*="st-4280247-8.gif"]')
.parents('table:first')
.siblings(':has(td[background*="st-4280247-8.gif"])')
.andSelf()
.attr('data-title', true)
.click(function(){
var _this = $(this);
_this.nextUntil('[data-title]').filter(':not([data-title])').toggle();
});
;
$('<div>')
.append(
$('.content .tab-content:eq(1)')
.children()
.children()
.clone()
)
.prependTo('.content .tab-content:first')
;
}
}
else if (_url_host.match(/tw\.mall\.yahoo\.com/))
{
$('#bd .bd .pic, #bd .bd .title, #bd .bd .info').find('a').attr('target', '_blank');
}
function _uf_log(object)
{
var args = Array.prototype.slice.call(arguments, 0) || [];
// throw new Error(args.toString());
if (typeof console != "undefined")
{
return console.log.apply(console, args);
}
}
})})(jQuery.noConflict());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment