From cd48fa428652d3f9c858c737772c8cff1f89b62f Mon Sep 17 00:00:00 2001 From: Kai Hendry Date: Sat, 14 Jul 2012 20:29:25 +0200 Subject: [PATCH] kinda working --- .htaccess | 1 + create.cgi | 2 ++ grep.php | 2 +- index.html | 4 +-- main.js | 100 ++++++++++++++++++++++++++++++++++------------------- 5 files changed, 70 insertions(+), 39 deletions(-) diff --git a/.htaccess b/.htaccess index 48d99a0..64ac6d4 100644 --- a/.htaccess +++ b/.htaccess @@ -1 +1,2 @@ DirectoryIndex index.shtml index.html +AddType text/cache-manifest .manifest diff --git a/create.cgi b/create.cgi index 67733a6..2000962 100755 --- a/create.cgi +++ b/create.cgi @@ -103,6 +103,8 @@ cat <Sorry the Twitter API is failing. Try again later.' diff --git a/grep.php b/grep.php index adbb113..ab5e324 100644 --- a/grep.php +++ b/grep.php @@ -10,7 +10,7 @@ $QUERY=urldecode(escapeshellarg(urlencode($_GET['q']))); //fwrite($fp, $_GET['q'] . " : " . $QUERY . "\n"); //fclose($fp); -exec("grep -hi $QUERY *.txt", $array); +exec("grep -hi $QUERY tweets.txt", $array); $data = json_encode($array); echo $_GET['jsoncallback'] . '(' . $data . ');'; ?> diff --git a/index.html b/index.html index 9e4feab..644a9e4 100644 --- a/index.html +++ b/index.html @@ -1,5 +1,5 @@ - + Grepping twitter backup @@ -28,7 +28,7 @@

Type a search query like foo

- +
diff --git a/main.js b/main.js index 4cb99a4..19e571b 100644 --- a/main.js +++ b/main.js @@ -1,45 +1,73 @@ function grep(query) { - $.getJSON("/u/" + NAME + "/grep.php?jsoncallback=?", { q: query }, function(data) { - var results = "

Searched for: " + query + "

    "; - for (var i in data) { - tweet = data[i].split('|'); - if (tweet.length > 2) { - results += "
  1. " + tweet.slice(2) + "
  2. "; // With datetime - } else { - results += "
  3. " + tweet.slice(1) + "
  4. "; // Old style - } - } - $('#results').prepend(results + "
"); - }); + if (navigator.onLine) { + $.getJSON("/u/" + NAME + "/grep.php?jsoncallback=?", { + q: query + }, + function(data) { + var results = "

Searched for: " + query + "

    "; + for (var i in data) { + tweet = data[i].split('|'); + if (tweet.length > 2) { + results += "
  1. " + tweet.slice(2) + "
  2. "; // With datetime + } else { + results += "
  3. " + tweet.slice(1) + "
  4. "; // Old style + } + } + $('#results').prepend(results + "
"); + }); + + } else { + +if (! lines) { + $.get('tweets.txt', function(data) { + lines = data.split("\n"); + }); } -$(document).ready(function() { + var results = "

Searched for: " + query + "

    "; + for (var i = 0; i < lines.length - 1; i++) { + tweet = lines[i].split('|'); + var re = new RegExp(query, 'i'); + if (tweet[2].match(re)) { + results += "
  1. " + tweet.slice(2) + "
  2. "; + } + } + $('#results').prepend(results + "
"); - NAME = window.location.pathname.split('/')[2]; - $("#name").html(NAME); - $("input[type=search]").change(function() { - query = this.value; - window.location.search = query; - grep(query); + } +} + + $(document).ready(function() { + + NAME = window.location.pathname.split('/')[2]; + $("#name").html(NAME); + + $("input[type=search]").change(function() { + query = this.value; + // window.location.search = query; // Triggers Reload the page to get source for: http://greptweet/u/kaihendry/?food + grep(query); + }); + + if (window.location.search) { + searchquery = window.decodeURIComponent(window.location.search.substr(1)); + $("input[type=search]").val(searchquery); + grep(searchquery); + } + + $("input[type=text]").focus(); + + footer = '

Download'; + footer += ' Update

'; + $("#source").html(footer); + document.title = "Greptweet " + NAME; + + document.cookie = 'u=' + NAME + '; expires=Thu, 2 Aug 2021 20:47:11 UTC; path=/'; + $("#home").click(function() { + document.cookie = 'u=' + NAME + '; expires=Thu, 2 Aug 2001 20:47:11 UTC; path=/'; + }); + }); - if (window.location.search) { - searchquery = window.decodeURIComponent(window.location.search.substr(1)); - $("input[type=search]").val(searchquery); - grep(searchquery); - } - - $("input[type=text]").focus(); - - footer = '

Download'; - footer += ' Update

' - $("#source").html(footer); - document.title = "Greptweet " + NAME; - - document.cookie = 'u=' + NAME + '; expires=Thu, 2 Aug 2021 20:47:11 UTC; path=/'; - $("#home").click(function(){ document.cookie = 'u=' + NAME + '; expires=Thu, 2 Aug 2001 20:47:11 UTC; path=/'; }); - -});