URL更改脚本为亚马逊无法正常工作

时间:2013-06-13 10:00:53

标签: javascript url amazon greasemonkey

我试着写一个小的greasemonkey脚本,允许我用右下角的一个小选择框更改网址。我希望能够在不同的亚马逊市场之间切换(通过用.it。或其他方式替换域名)。

使用http://www.amazon.co.uk/gp/product/B0080K4K76/和一个例子

然而它无法正常工作。 onchange似乎没有调用更换器功能。

// ==UserScript==
// @name           amazon__article_changer
// @namespace      wtf
// @include        *amazon*
// ==/UserScript==
function changer(end){
    var url = window.location.href;
    var nurl = "http://www.amazon."+ end + url.slice(url.indexOf("/gp/"), url.length);
    window.location.href = nurl;
}

box = window.document.createElement('div')
box.innerHTML = "<html><head><title></title></head><body><select onchange='changer(this.value)'><option value='de'>DE</option><option     value='co.uk'>UK</option><option value='fr'>FR</option><option value='es'>ES</option><option value='it'>IT</option></select></body></html>";
box.style.position = "fixed";
box.style.right = "0px";
box.style.bottom = "0px";
window.document.getElementsByTagName("body")[0].appendChild(box);

1 个答案:

答案 0 :(得分:-1)

让它发挥作用,我确信这可以更容易地完成

// ==UserScript==
// @name           amazon__article_changer
// @namespace      wtf
// @include        *mazon*
// ==/UserScript==
function changer(end){
    var url = window.location.href;
    var nurl = "http://www.amazon."+ end + url.slice(url.indexOf("/gp/"), url.length);
    window.location.href = nurl;
}

box = window.document.createElement('div');
box.innerHTML = "<html><head><title></title></head><body><select     onChange='changer(this.value)'><option></option><option value='de'>DE</option><option value='co.uk'>UK</option><option value='fr'>FR</option><option value='es'>ES</option><option value='it'>IT</option></select></body></html>";
box.style.position = "fixed";
box.style.right = "0px";
box.style.bottom = "0px";

sc = window.document.createElement('script');
sc.type = "text/javascript";
sc.innerHTML = "function changer(end){var url = window.location.href;var nurl = 'http://www.amazon.'+ end + url.slice(url.indexOf('/gp/'), url.length);window.location.href = nurl;}";

window.document.getElementsByTagName("head")[0].appendChild(sc);
window.document.getElementsByTagName("body")[0].appendChild(box);