【问题标题】:URL changing Script for amazon not working亚马逊的 URL 更改脚本不起作用
【发布时间】:2013-06-13 10:00:52
【问题描述】:

我正在尝试编写一个小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);

【问题讨论】:

    标签: javascript url amazon greasemonkey


    【解决方案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);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-12-08
      • 2014-03-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多