Source for "Scroogle - Use GET over SSL"

By khopesh
Has 3 other scripts.


// ==UserScript==
// @name           Scroogle - Use GET over SSL
// @namespace      namespace
// @description    Nicer look, SSL + GET for increased security and usability.
// @include        https://*scroogle.org/cgi-bin/nbbw.cgi*
// @include        http://*scroogle.org/cgi-bin/nbbw.cgi*
// ==/UserScript==
/*
 * If using SSL, further searches should be SSL.
 * If using SSL, it is safe to use GET (which makes session management easier)
 * as noted at https://ssl.scroogle.org/sslnote.html
 * If not using SSL, it is not safe to use GET.  We ensure we're using POST
 * for the reasons outlined at http://www.scroogle.org/scget.html
 *
 * Add a bookmark to https://ssl.scroogle.org/cgi-bin/nbbw.cgi?Gw=%s&n=5
 * and give it a quicksearch shortcut like "g" or "google" for quick searching,
 * so that you can type "g this is a search query" into your locationbar.
 *
 * For more on why this is important, see one of these sources:
 *   - http://www.scroogle.org/
 *   - http://www.google-watch.org/
 *   - http://www.gmail-is-too-creepy.com/
 *
 * Copyright 2008 by Adam Katz <scriptsATkhopiscom>, v0.2 (2008-03-20), LGPL 2+
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation, either version 2 of the
 * License, or any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License at <http://www.gnu.org/licenses>.
 */

var override = false; // make this to true to always use SSL on refined searches

var forms = document.forms; // getElementsByName didn't work...
for (var i = 0; i < forms.length; i++) {
  if ( forms[i].action.match(/\/nbbw\.cgi$/) ) { // sanity check for search box
    if ( override || location.protocol == "https:" ) {
      forms[i].method = "get";
      urlHead = "https://ssl.";
    } else {
      forms[i].method = "post";
      urlHead = "http://www.";
    }
    forms[i].action = urlHead + "scroogle.org/cgi-bin/nbbw.cgi";
  }
}

// create image (no SSL version of image available)
var img = '<a id="logo" href="http://scroogle.org">';
img += '<img height="72" alt="S C R O O G L E" src="http://scroogle.org/gifs/';
if (Math.random() > 0.6) {
  img += 'gooburns.gif"'; // 40% chance of google logo burning/falling down
} else {
  img += 'scrooge2.gif"'; // 60% chance of scroogle logo
}
img += ' ><\/a>';

// insert image, search summary gets class for CSS modifying later
var myHTML = document.body.innerHTML;
myHTML = myHTML.replace(/<center>/, '<div id="title">' + img);
myHTML = myHTML.replace(/<.center>/, '</div');
myHTML = myHTML.replace(/<b>/, '<b class="searchtitle">');
myHTML = myHTML.replace(/<b>Google returned no results for this search.<.b>/i,
                     "\n<h1>Google returned no results for this search.</h1>");
document.body.innerHTML = myHTML;

// styles to spruce it up some ... better spacing, mostly
GM_addStyle("body { margin:-1.5em 0 0 -1em; padding:0; }");
GM_addStyle(".searchtitle { background-color:#d5ddf3; color:black;"
  + "                       display:block; border-top:blue solid 1px;"
  + "                       font-weight:normal; font-size:0.8em;"
  + "                       line-height:2em; margin:-1em 0 -2em 0; }");
GM_addStyle("h1 { margin:2em 0 -1em 0; font-size:1.5em; }");
GM_addStyle("#logo img { border:none; height:6em!important; margin-top:-1em;}");
GM_addStyle("form { display:inline; }");
GM_addStyle("#title, #title *, center, center * { vertical-align:middle; }");
GM_addStyle("ul { margin-top:0.25em; margin-bottom:0.75em; }");