$(function(){
var pattern ={
// /products/list.php の変換マスタ
// "カテゴリID":"変換後ファイル名"
"category_list":{
"18" :"aerobics",
"58" :"stream/aerobics"
},
"products_category_list":{
"1" :"aerobics",
"2" :"aerobics",
"3" :"aerobics",
"4" :"aerobics",
"176" :"aerobics",
"177" :"aerobics",
"178" :"aerobics",
"179" :"aerobics",
"180" :"aerobics",
"181" :"aerobics",
"182" :"aerobics",
"183" :"aerobics",
"184" :"aerobics",
"185" :"aerobics",
"186" :"aerobics",
"187" :"aerobics",
"188" :"aerobics",
"189" :"aerobics",
"1601" :"stream/aerobics",
"1602" :"stream/aerobics",
"1603" :"stream/aerobics",
"1760" :"stream/aerobics",
"1761" :"stream/aerobics",
"1762" :"stream/aerobics",
"1763" :"stream/aerobics",
"1764" :"stream/aerobics",
"1765" :"stream/aerobics",
"1766" :"stream/aerobics",
"1767" :"stream/aerobics",
"1768" :"stream/aerobics",
"1769" :"stream/aerobics",
"1770" :"stream/aerobics"
}
};
/* リンクURL書き換え */
$('a').each(function() {
var ret = $(this).attr('href');
if(ret){
var res_data = null;
var cat_res = ret.match(/\/products\/list\.php\?(.*)category_id=(\d{1,})(.*)/); // カテゴリ別商品ページ
var detail_res = ret.match(/\/products\/detail\.php\?(.*)product_id=(\d{1,})(.*)/); // 商品詳細ページ
// 初期化
var rep_url = null;
var rep_param = '';
if(cat_res){
// カテゴリ別商品ページ用URL変換処理
res_data = cat_res;
if((typeof res_data[2] != "undefined") && res_data[2] && (typeof pattern['category_list'][res_data[2]] != "undefined") && pattern['category_list'][res_data[2]]){
rep_url = window.location.protocol + '//' + window.location.host + '/' + pattern['category_list'][res_data[2]] + '.php';
}
}
else if(detail_res){
// 商品詳細ページ用URL変換処理
res_data = detail_res;
if((typeof res_data[2] != "undefined") && res_data[2] && (typeof pattern['products_category_list'][res_data[2]] != "undefined") && pattern['products_category_list'][res_data[2]]){
rep_url = window.location.protocol + '//' + window.location.host + '/' + pattern['products_category_list'][res_data[2]] + '_' + res_data[2] + '.php';
}
}
if(res_data && rep_url){
if((typeof res_data[1] != "undefined") && res_data[1]){
rep_param = '?' + res_data[1].slice(0, -1);
}
if((typeof res_data[3] != "undefined") && res_data[3]){
if(rep_param){
rep_param = rep_param + res_data[3];
}else{
rep_param = '?' + res_data[3];
}
}
if(rep_param){
rep_param = rep_param.replace('??','?');
rep_param = rep_param.replace('?&','?');
rep_param = rep_param.replace('&&','&');
}
$(this).attr('href', rep_url + rep_param);
}
}
});
});