<?xml version="1.0" encoding="UTF-8"?>
<Module>
  <ModulePrefs title="Google.com vs. Google.cn (regex)"
               directory_title="Google.com vs. Google.cn"
               description="Compare results between Google China and Google in the free world."
               author="Daniel C. Silverstein"
               author_email="cubes.feedback+googlevgoogle@gmail.com"
               author_affiliation="Free Agent"
               author_location="El Cerrito, CA"
               render_inline="optional"
               height="400"/>

<Content type="html">
<![CDATA[
<!--
Copyright © 2006 Daniel C. Silverstein (dans@csua.berkeley.edu)

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.1 of the
License, or (at your option) 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 for more details.

You should have received a copy of the GNU Lesser General Public
License along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor,
Boston, MA  02110-1301  USA

This program is also subject to the Google Homepage API Terms and
Condtions located at http://www.google.com/apis/homepage/terms.html.
--><!--

<rdf:RDF xmlns="http://web.resource.org/cc/"
    xmlns:dc="http://purl.org/dc/elements/1.1/"
    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
<Work rdf:about="">
   <license rdf:resource="http://creativecommons.org/licenses/LGPL/2.1/" />
   <dc:type rdf:resource="http://purl.org/dc/dcmitype/Software" />
</Work>

<License rdf:about="http://creativecommons.org/licenses/LGPL/2.1/">
<permits rdf:resource="http://web.resource.org/cc/Reproduction" />
   <permits rdf:resource="http://web.resource.org/cc/Distribution" />
   <requires rdf:resource="http://web.resource.org/cc/Notice" />
   <permits rdf:resource="http://web.resource.org/cc/DerivativeWorks" />
   <requires rdf:resource="http://web.resource.org/cc/ShareAlike" />
   <requires rdf:resource="http://web.resource.org/cc/SourceCode" />
</License>

</rdf:RDF>

-->
<style>
<!--
div.result__MODULE_ID__ {height: 46%; overflow: auto}
p.defresult__MODULE_ID__ {text-align: center; padding-top: 25%; padding-bottom: 15%}
p.loading__MODULE_ID__ {text-align: center; padding-top: 25%; padding-bottom: 15%}
-->
</style>
<script type="text/javascript"
        src="http://www.csua.berkeley.edu/~dans/igmonkey/igmonkey.js"></script>

<script type="text/javascript"><!--
function submit__MODULE_ID__ (query) {
    var monkey =
        new IGMonkey([ "http://www.google.com/search?hl=en&q=" + _esc(query) +
                       "&btnG=Google+Search",
                       "http://www.google.cn/search?hl=zh-CN&q=" + _esc(query) +
                       "&btnG=Google+搜索&meta=" ],
                     [ "Google.com", "Google.cn" ],
                     [ _gel("fwResDiv"+__MODULE_ID__),
                       _gel("cnResDiv"+__MODULE_ID__) ]);

    monkey.requestFilters.push(qFltrBustCacheDay);
    monkey.resultFilters.push(sFltrGoogleResultsRegex__MODULE_ID__);
    // monkey.resultFilters.push(sFltrViewHTML);

    monkey.exec();
}

function sFltrGoogleResultsRegex__MODULE_ID__ (canvas) {
    var stanzas = [], header = null, pattern = null;
    
    header = canvas.innerHTML.match(new RegExp(
        openTagAllAttrsEx("table", [ ["bgcolor", "#e5ecf9"], ["border", "0"],
                                     ["cellpadding", "0"], ["cellspacing", "0"],
                                     ["width", "100%"] ]) +
        anyText + closeTag("table")))[0];

    // Push the text `Results 1 - n of about x,xxx,xxx...' into its own row.
    // It would be nice to remove the query run time for screen real estate
    // reasons.  \(.*\d?\.\d{1,4}.*\)(.*) almost does it, but fails on .cn
    header = header.replace(
        new RegExp(makeSubExp(closeTag("td")) +
                   makeSubExp(openTagAnyAttrsInc("td")) +
                   makeSubExp(openTagAllAttrsEx("font", [["size", "-1"]]) +
                              anyText)),
        "$1</tr><tr>$2&nbsp;&nbsp;$3");
    stanzas.push(header);

    searchResult = new RegExp(openTagAllAttrsEx("p", [["class", "g"]]) +
                              anyText + closeTag("p"),
                              "g");
    for(var m; m = searchResult.exec(canvas.innerHTML);) { stanzas.push(m[0]); }

    canvas.innerHTML =
        "<span style='font-size:0.8em'>" + stanzas.join("") + "</span>";
    return canvas; // Filter functions *MUST* return the canvas object!
}
--></script>

<div id="searchDiv__MODULE_ID__" style="margin-bottom: -10px">
  <form id="f__MODULE_ID__" name="f" action="#"
        onsubmit="submit__MODULE_ID__(this.q__MODULE_ID__.value); return false;">
    <input id="q__MODULE_ID__" style="width: 75%" name="q" type="text" value="" />
    <input id="s__MODULE_ID__" style="width: 20%" name="s" type="submit" value="Fight!" />
  </form>
</div>
<div id="fwResDiv__MODULE_ID__" class="result__MODULE_ID__"
     style="border-bottom-style: solid; border-width: 1px; border-color: #aaaaaa">
  <p class="defresult__MODULE_ID__">Google Search</p>
</div>
<div id="cnResDiv__MODULE_ID__" class="result__MODULE_ID__">
  <p class="defresult__MODULE_ID__">Google 搜索</p>
</div>
]]>
</Content>
</Module>
