Web Analytics Made Easy -
StatCounter Greasemonkey / Drop Down Menus - CodingForum

Announcement

Collapse
No announcement yet.

Greasemonkey / Drop Down Menus

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Greasemonkey / Drop Down Menus

    Hey,

    Firstly, I admittedly have minimal to no understanding of JS at the moment, however will learn it one day as I'm going to study Computer Science in university next year . Someone wrote some code for a greasemonkey script and said I could release it myself. It adds advanced features to Google Image Search - Rather than having to go to the advanced page, it's on the main search page. I've edited it and added new filters, which didn't require any JS knowledge.

    Now to my question. As an example, say that you select the imagetype as 'mono', it adds &imgc=mono in the URL (mono = black & white), thus resulting in only displaying only black and white images. At the moment it's just adding what ever is in the drop-down menu to the URL. Not everyone knows what 'mono' means, so it would be good if you could select 'black & white' from the drop-down menu and it adds 'mono' in the URL.

    Could someone point me in the right direction as to how I could do this?

    Thanks in advance.

    Code:
    addFilter("as_filetype",["Any filetype","JPG","GIF","PNG","BMP"]);
    addFilter("imgcolor",["Any color","Black","Blue","Brown","Gray","Green","Orange","Pink","Purple","Red","Teal","White","Yellow"]);
    addFilter("imgc",["Any imagetype","Mono","Gray","Color"]);
    addFilter("safe",["SafeSearch","Active","Off"]);
    
    function addFilter(param,values)
    {
    	var re=new RegExp("(\\?|&)"+param+"=(\\w*)(&|$)","img");		//regexp to extract the parameter from the search string
    	var pv=re.exec(location.search)?RegExp.$2.toLowerCase():"";		//extracting parameter value
    	var url=location.pathname+location.search.replace(re,function(){return arguments[3]?arguments[1]:"";});	//search string without parameter
    	
    	//creating dropdown
    	var s=document.createElement("select");
    	s.name=param;
    	s.setAttribute("onchange","_isr_load(this);");
    	
    	//adding options
    	s.options[0]=new Option(values.shift(),url);
    	url+="&"+param+"=";
    	values.forEach(function(v){(s.options[s.options.length]=new Option(v,url+v.toLowerCase())).selected=v.toLowerCase()==pv;});
    	
    	//appending dropdown
    	s.style.margin='0px 0px 0px 8px'; 
    	document.forms[1].appendChild(s);
    }

  • #2
    Bump.

    Comment


    • #3
      Well I solved that.

      http://userscripts.org/scripts/show/45825

      Does anybody know how to add an extra option to an existing drop down menu, using JavaScript?

      Comment

      Working...
      X