Javascript 如何向国际谷歌网站添加域切换选择器?
我正在写一个Greasemonkey脚本来改变google.com的顶级域名 完整的代码如下。在dev工具中测试我的代码时,它确实显示了choosebox和按钮。但是,当我点击按钮时,页面只是重新加载,它没有切换语言站点Javascript 如何向国际谷歌网站添加域切换选择器?,javascript,internationalization,greasemonkey,html-select,Javascript,Internationalization,Greasemonkey,Html Select,我正在写一个Greasemonkey脚本来改变google.com的顶级域名 完整的代码如下。在dev工具中测试我的代码时,它确实显示了choosebox和按钮。但是,当我点击按钮时,页面只是重新加载,它没有切换语言站点 // ==UserScript== // @name GoogleFieldExpress // @namespace http://example.gg/ // @version 1.0 // @description to change field f
// ==UserScript==
// @name GoogleFieldExpress
// @namespace http://example.gg/
// @version 1.0
// @description to change field from database
// @match http://www.google.*/
// @match https:/www.google.*/
// @copyright 2013,Matthew
// ==/UserScript==
//database domains and varibles
var domains=new Array;
domains=["gg","jp"];
var current="";
if (typeof this.href === "undefined") {
current = document.location.toString().toLowerCase();
}
else {
current = this.href.toString().toLowerCase();
}
var inner='\
<center>\
<strong>\
Choose field below: <br />\
</strong>\
<form id="choose" >\
<select id="select_item">'
for (var i = 0; i < domains.length; i++) {
inner+='<option value="'+domains[i]+'"\\>'+domains[i]+'</option>';
};
inner+='</select>\
<button id="goto2">go!</button>\
</form>\
</center>\
'
//functions
function getLanguageElement(){
var lang=document.getElementById("als");
return lang;
}
function appendHTML(element,html){
element.innerHTML+=html;
}
//main process
(function(){
appendHTML(getLanguageElement(),inner);
document.getElementById("goto2").addEventListener("click",function(){windows.location=new String('www.google.')+(document.getElementById("select_item").value)},false);
})();
/==UserScript==
//@name GoogleFieldExpress
//@名称空间http://example.gg/
//@version 1.0
//@description更改数据库中的字段
//@匹配http://www.google.*/
//@match https:/www.google*/
//@版权所有2013,Matthew
//==/UserScript==
//数据库域和变量
var域=新数组;
域名=[“gg”,“jp”];
var current=“”;
if(typeof this.href==“未定义”){
当前=document.location.toString().toLowerCase();
}
否则{
当前=this.href.toString().toLowerCase();
}
内部变量\
\
\
选择下面的字段:
\
\
\
'
对于(var i=0;i
我是一个新手,对这些很生气。 如何重定向到正确的域以及我的代码有什么问题 我想从跳到或等等 另外,“als”元素是“Google.gg以:语言提供”这句话的容器
http://www.google.*/
和https:/www.google.*/
是。使用:
jp
似乎是无效域。谷歌似乎使用了co.jp
windows
不是有效的对象或变量
和
,单击“go!”实际上提交了表单!这将覆盖尝试设置位置URL的操作位置时需要协议(http:,等等)。
// ==UserScript==
// @name GoogleFieldExpress
// @namespace http://example.gg/
// @version 1.0
// @description to change field from database
// @include http://www.google.*/
// @include https://www.google.*/
// ==/UserScript==
//database domains and variables
var domains = ["gg", "co.jp"];
var current = location.host; // or location.href. Case-sensitive for a reason
var inner = '\
<center>\
<strong>\
Choose field below: <br />\
</strong>\
<form id="gmChoose">\
<select id="gmSelect_item">'
;
domains.forEach ( function (item) {
inner += '<option value="' + item + '"\\>' + item + '</option>';
} );
inner += '</select>\
<button id="gmGoto2" type="button">go!</button>\
</form>\
</center>\
';
//main code
var lang = document.getElementById ("als");
if (lang) {
lang.innerHTML += inner;
document.getElementById ("gmGoto2").addEventListener ("click", function () {
location.assign (
location.protocol + '\/\/www.google.'
+ document.getElementById ("gmSelect_item").value
+ '\/'
);
}, false);
}
/==UserScript==
//@name GoogleFieldExpress
//@名称空间http://example.gg/
//@version 1.0
//@description更改数据库中的字段
//@包括http://www.google.*/
//@包括https://www.google.*/
//==/UserScript==
//数据库域和变量
var域=[“gg”,“co.jp”];
var current=location.host;//或location.href。区分大小写是有原因的
内部变量\
\
\
选择下面的字段:
\
\
\
'
;
domains.forEach(函数(项){
内部+=''+项目+'';
} );
内部+='\
走\
\
\
';
//主代码
var lang=document.getElementById(“als”);
如果(朗){
lang.innerHTML+=内部;
document.getElementById(“gmGoto2”).addEventListener(“单击”,函数)(){
地点分配(
location.protocol+'\/\/www.google'
+document.getElementById(“gmSelect_项”).值
+ '\/'
);
},假);
}
几个问题:
http://www.google.*/
和https:/www.google.*/
是。使用:
jp
似乎是无效域。谷歌似乎使用了co.jp
windows
不是有效的对象或变量
和
,单击“go!”实际上提交了表单!这将覆盖尝试设置位置URL的操作位置时需要协议(http:,等等)。
// ==UserScript==
// @name GoogleFieldExpress
// @namespace http://example.gg/
// @version 1.0
// @description to change field from database
// @include http://www.google.*/
// @include https://www.google.*/
// ==/UserScript==
//database domains and variables
var domains = ["gg", "co.jp"];
var current = location.host; // or location.href. Case-sensitive for a reason
var inner = '\
<center>\
<strong>\
Choose field below: <br />\
</strong>\
<form id="gmChoose">\
<select id="gmSelect_item">'
;
domains.forEach ( function (item) {
inner += '<option value="' + item + '"\\>' + item + '</option>';
} );
inner += '</select>\
<button id="gmGoto2" type="button">go!</button>\
</form>\
</center>\
';
//main code
var lang = document.getElementById ("als");
if (lang) {
lang.innerHTML += inner;
document.getElementById ("gmGoto2").addEventListener ("click", function () {
location.assign (
location.protocol + '\/\/www.google.'
+ document.getElementById ("gmSelect_item").value
+ '\/'
);
}, false);
}
/==UserScript==
//@name GoogleFieldExpress
//@名称空间http://example.gg/
//@version 1.0
//@description更改数据库中的字段
//@包括http://www.google.*/
//@包括https://www.google.*/
//==/UserScript==
//数据库域和变量
var域=[“gg”,“co.jp”];
var current=location.host;//或location.href。区分大小写是有原因的
内部变量\
\
\
选择下面的字段:
\
\
\
'
;
domains.forEach(函数(项){
内部+=''+项目+'';
} );
内部+='\
走\
\
\
';
//主代码
var lang=document.getElementById(“als”);
如果(朗){
lang.innerHTML+=内部;
document.getElementById(“gmGoto2”).addEventListener(“单击”,函数)(){
地点分配(
location.protocol+'\/\/www.google'