-1

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

http://www.amazon.co.uk/gp/product/B0080K4K76/为例

但是它不能正常工作。onchange 似乎没有调用 changer 函数。

// ==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);
4

1 回答 1

-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);
于 2013-06-13T12:02:08.103 回答