<?xml version="1.0" encoding="UTF-8"?>
<Module>
  <ModulePrefs title="Google.com vs. Google.cn (pre-monkey 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"><!--
function submit__MODULE_ID__ (reqs) {
  for (var i = 0; i < reqs.length; i++) {
      reqs[i].canvas.innerHTML = "<p class='loading__MODULE_ID__'>Querying " + reqs[i].src_name + "</p>";

      exec_req__MODULE_ID__(reqs[i]);
  }
}

function exec_req__MODULE_ID__ (req) {
    _IG_FetchContent(req.url, function(response) {
        if (response == "") {
            req.canvas.innerHTML = "error: please try again later"; return;
        }
        
        req.canvas.innerHTML = filter_google_results_regex__MODULE_ID__(response);
        // req.canvas.innerHTML = filter_view_source__MODULE_ID__(response);
    });
}

function filter_google_results_regex__MODULE_ID__ (html) {
    var stanzas = [], header;
    var pattern = /<p class=g>(?:.|\s)+?(<p class=g>|<\/div>)/g;

    header = html.match(/<table width=100% border=0 cellpadding=0 cellspacing=0 bgcolor=#e5ecf9>(?:.|s)+?<\/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(/(<\/td>)(<td.*?>)(<font size=-1>.+)/,
                            "$1</tr><tr>$2&nbsp;&nbsp;$3");
    stanzas.push(header);

    for(var m; m = pattern.exec(html);) {
        pattern.lastIndex -= m[1].length;
        stanzas.push(m[0].substring(0, m[0].length - m[1].length));
    }

    return "<span style='font-size:0.8em'>" + stanzas.join("") + "</span>";
    // return filter_view_source__MODULE_ID__(stanzas.join());
}

function filter_view_source__MODULE_ID__ (html) {
    html = html.replace(/&/g, "&amp;");
    html = html.replace(/</g, "&lt;");
    html = html.replace(/>/g, "&gt;");
    return "<code>" + html + "</code>";
}
--></script>

<div id="searchDiv__MODULE_ID__" style="margin-bottom: -10px">
  <form id="f__MODULE_ID__" name="f" action="#"
        onsubmit="submit__MODULE_ID__(
                  [ { url: 'http://www.google.com/search?hl=en&q=' + _esc(this.q__MODULE_ID__.value) + '&btnG=Google+Search',
                      src_name: 'Google.com',
                      canvas: _gel('fwResDiv'+__MODULE_ID__) },
                    { url: 'http://www.google.cn/search?hl=zh-CN&q=' + _esc(this.q__MODULE_ID__.value)+'&btnG=Google+搜索&meta=',
                      src_name: 'Google.cn',
                      canvas: _gel('cnResDiv'+__MODULE_ID__) } ]);
                  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>
