Skip to content

Instantly share code, notes, and snippets.

@mallowlabs
Created June 14, 2013 18:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mallowlabs/5784186 to your computer and use it in GitHub Desktop.
Save mallowlabs/5784186 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name googleimagefilter
// @author mallowlabs
// @namespace http://mallowlabs.s206.xrea.com/
// @version 0.0.2
// @license public domain
// @description : Add a switch that on/off the filter in Google Image Search
// @published 2006-11-12
// @modified 2007-07-16
// @include http://images.google.co.jp/*
// ==/UserScript==
//
// ChangeLog
// 2007-07-16 0.0.2 fix broken layout.
// 2006-11-12 0.0.1 released.
//
// =========================================
// =========================================
(function () {
var tableNode = document.getElementsByTagName("table")[3];
var trNode = tableNode.getElementsByTagName("tr")[0];
var tdNode = document.createElement("td");
tdNode.setAttribute("nowrap", "");
if(!isFiltering()){
aNode = createANode("safe=images", "FilterON");
}else{
aNode = createANode("safe=off", "FilterOFF");
}
tdNode.appendChild(aNode);
trNode.appendChild(tdNode);
function isFiltering(){
var aNodes = document.getElementsByTagName("a");
for (var i = 0; i < aNodes.length; i++) {
if ( aNodes[i].getAttribute("href").search(/^\/preferences/) != -1 ) {
break;
}
}
var strCheckUrl = aNodes[i].getAttribute("href");
var param = strCheckUrl.slice(strCheckUrl.indexOf("?")+1).split("&");
var mode = true;
for (var i = 0;i < param.length; i++) {
if (param[i]=="safe=off"){
mode = false;
break;
}
}
return mode;
}
function createANode(newsafe, newtext){
var ref = location.href.slice(0, location.href.indexOf("?")+1);
var param = location.href.slice(location.href.indexOf("?")+1).split("&");
for (var i = 0;i < param.length; i++) {
if (param[i].search(/safe=/) != -1) {
ref += newsafe + "&";
}else{
ref += param[i] + "&";
}
}
ref = ref.slice(0, ref.length - 1);
if(ref.search(/&safe=/) == -1){
ref += "&" + newsafe;
}
var textNode = document.createTextNode(newtext);
var aNode = document.createElement("a");
aNode.setAttribute("href", ref);
aNode.appendChild(textNode);
return aNode;
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment