Click to install this script

TWoP: Google Search

  • Added: October 27, 2007
  • Last Updated: October 27, 2007

File Name: twop_google.user.js

Click to hide sectionDescription

TWoP is yet another site that has a defective search. This script adds a Google Search next to the existing search forms on the forum pages. I recently figured out how to restrict searches to a topic, so now searching from the Google Search on a topic page will restrict results to that topic. Searches on other pages will be restricted to the TWoP forums. As of right now, I'm not sure how to restrict searches to a subforum.

Screenshot of Google search box added by script

Click to hide sectionScript Source

// TWoP: Google Search // Copyright (c) 2006-2007 Orbona // Version 1.0 // Release Date: 2007-10-22 // // See also: http://www.orbona.com/greasemonkey/ // // Original file name: twop_google.user.js // Please reference the original file name when contacting me regarding this // script. // // This software is licensed under the CC-GNU GPL: // http://creativecommons.org/license/cc-gpl // // ----------------------------------------------------------------------------- // DESCRIPTION // // Adds a Google search to the "showTopic" and "showForum" pages at Television // Without PIty. The Google search is added immediately before the native TWoP // search form. // // If searching from the topic pages, searches are performed within that topic. // On any other page, searches are performed per site; I currently am not sure // how to restrict searches to a forum/subforum. // ----------------------------------------------------------------------------- // ==UserScript== // @name TWoP: Google Search // @description Adds a "Google Search" to TWoP forum pages // @namespace http://www.orbona.com/greasemonkey/ // @include http://forums.televisionwithoutpity.com/index.php?show* // ==/UserScript== // ----------------------------------------------------------------------- // This function intercepts the form submit. Adds the appropriate // advanced search parameters, which will restrict the search to the site // or the topic, to the user-entered query string and then allows the // submit to proceed. // ----------------------------------------------------------------------- function googleSubmit(event) { var target = event ? event.target : this; if (target.name=='googlesearch') { var thedomain=window.location.host; target.elements[1].value= window.location.href.indexOf('showtopic')>0 ? target.elements[1].value + ' site:' + thedomain + ' intitle:"' + window.document.title + '"' : target.elements[1].value + ' site:' + thedomain; } this._submit(); } // ---------------------------------------------------------------------------- // Main function that does everything described in the description area above. // ---------------------------------------------------------------------------- function doIt() { var searchElem = document.getElementsByName('search'); var googleSearchElem, inputElemH1, inputElemSearch, submitElem; if (searchElem && searchElem[0]) { googleSearchElem = document.createElement('form'); googleSearchElem.action = 'http://www.google.com/search'; googleSearchElem.name= 'googlesearch'; googleSearchElem.style.display = 'inline'; inputElemH1=document.createElement('input'); inputElemH1.type='hidden'; inputElemH1.name='h1'; inputElemH1.value='en'; inputElemSearch=document.createElement('input'); inputElemSearch.name='q'; inputElemSearch.maxlength='2048'; inputElemSearch.size='25'; inputElemSearch.title='GoogleSearch'; submitElem=document.createElement('input'); submitElem.type='submit'; submitElem.name='btnG'; submitElem.value='Google Search'; googleSearchElem.appendChild(inputElemH1); googleSearchElem.appendChild(inputElemSearch); googleSearchElem.appendChild(submitElem); googleSearchElem.addEventListener('submit', googleSubmit, true); //no need to redefine method of HTMLFormElement class since //no other scripts should be submitting my brand-spankin-new form searchElem[0].parentNode.insertBefore(googleSearchElem, searchElem[0]); } } // ------------------END OF FUNCTIONS ----------------------------- window.addEventListener("load", function() { doIt(); }, false);