javascript - How to add a domain-switching selector to International Google sites? -


i writing greasemonkey script change top-level domains of google.com.

the complete code below. testing code in dev tool, did display choosebox , button. but, when clicked button, page reloaded, did not switch language sites.

// ==userscript== // @name       googlefieldexpress // @namespace  http://example.gg/ // @version    1.0 // @description  change field database // @match      http://www.google.*/ // @match      https:/www.google.*/ // @copyright  2013,matthew // ==/userscript==  //database domains , 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">' (var = 0; < 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); })(); 


greenhand , mad @ these. how can redirect right domain , what's wrong code?

i want jump www.google.com www.google.gg or www.google.jp , on.

p.s. "als" element container of sentence "google.gg offered in: languages"

several issues:

  1. http://www.google.*/ , https:/www.google.*/ invalid values @match. use:

    // @include    http://www.google.*/ // @include    https://www.google.*/ 
  2. jp appears invalid domain. google appears use co.jp.

  3. windows not valid object or variable.

  4. by using <form> , <button> default type, clicking "go!" submits form! overrides trying set location url.

  5. you need protocol (http:, etc.) when setting location.

  6. do not use this in global scope of userscript. this vary markedly depending on: browser, sandbox state, possible iframe state, etc. use this inside functions , when sure refer to.

  7. the script needs error checking since sought nodes not present on google pages.

there several more minor issues -- i'll skip, since stack overflow not code-review site. see working script, below, , note different question's script.

// ==userscript== // @name       googlefieldexpress // @namespace  http://example.gg/ // @version    1.0 // @description  change field database // @include    http://www.google.*/ // @include    https://www.google.*/ // ==/userscript== //database domains , variables var domains = ["gg", "co.jp"]; var current = location.host;  // or location.href. case-sensitive 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); } 

Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -