yen867gmail.com / apple online store location switch

// ==UserScript==
// @name           apple online store location switch
// @namespace      
// @description    apple store location switch
// @author         alexw
// @include        http://store.apple.com/*/*
// @version 1.2.0
// ==/UserScript==

var url = location.href;
var loc = '';
if(url.match(/apple\.com\/tw\//)) loc = "tw";
else if (url.match(/apple\.com\/tw-edu\//)) loc = "tw-edu";
else if (url.match(/apple\.com\/jp\//)) loc = "jp";
else if (url.match(/apple\.com\/us\//)) loc = "us";
else if (url.match(/apple\.com\/hk\//)) loc = "hk";
//alert(loc);

//regexp採用變數得要用 RegExp
var re = new RegExp(loc);
var us_url = url.replace(re, "us");
var jp_url = url.replace(re, "jp");
var tw_url = url.replace(re, "tw");
var twedu_url = url.replace(re, "tw-edu");
var hk_url = url.replace(re, "hk");

var us_html = "<a href=\"" + us_url + "\">US</a>";
var jp_html = "<a href=\"" + jp_url + "\">JP</a>";
var hk_html = "<a href=\"" + hk_url + "\">HK</a>";
var tw_html = "<a href=\"" + tw_url + "\">TW</a>";
var twedu_html = "<a href=\"" + twedu_url + "\">TW-EDU</a>";
var bar = " | ";
//var ins_t = document.getElementById("page"); 
//var ins_b = document.getElementById("globalheader"); 
var ins_t = document.getElementsByClassName("masthead clearfix");
var ins_b = document.getElementsByClassName("masthead-title");
var alexbar = document.createElement("div");
alexbar.innerHTML = "<p align=\"center\" style=\"font-size: 2em;\" >" + us_html + bar + jp_html + bar + hk_html + bar + tw_html + bar + twedu_html + "</p>";

//ins_t.insertBefore(alexbar, ins_b);
//改用getElementsByClassName要指定[0]

ins_t[0].insertBefore(alexbar, ins_b[0]);