mirror of
https://github.com/thewesker/greptweet.git
synced 2025-12-20 12:11:05 -05:00
Offline first
http://natalian.org/archives/2012/07/16/navigator.onLine/
This commit is contained in:
@@ -1 +0,0 @@
|
|||||||
find $(dirname $0) -name lock | xargs rm -f
|
|
||||||
@@ -66,7 +66,6 @@ fi
|
|||||||
cd u/$id
|
cd u/$id
|
||||||
|
|
||||||
ln -sf ../../index.html || true
|
ln -sf ../../index.html || true
|
||||||
ln -sf ../../grep.php || true
|
|
||||||
|
|
||||||
if echo $id | grep -q -v '_' # Underscores in domain names is a no no
|
if echo $id | grep -q -v '_' # Underscores in domain names is a no no
|
||||||
then
|
then
|
||||||
|
|||||||
16
grep.php
16
grep.php
@@ -1,16 +0,0 @@
|
|||||||
<?php
|
|
||||||
header('Content-type: application/json');
|
|
||||||
if (empty($_GET['q'])) { die(); }
|
|
||||||
|
|
||||||
// Is this the correct way to sanitise args to shell from PHP?
|
|
||||||
$QUERY=urldecode(escapeshellarg(urlencode($_GET['q'])));
|
|
||||||
|
|
||||||
// Debug Logging
|
|
||||||
//$fp = fopen('debug.log', 'a');
|
|
||||||
//fwrite($fp, $_GET['q'] . " : " . $QUERY . "\n");
|
|
||||||
//fclose($fp);
|
|
||||||
|
|
||||||
exec("grep -hi $QUERY tweets.txt", $array);
|
|
||||||
$data = json_encode($array);
|
|
||||||
echo $_GET['jsoncallback'] . '(' . $data . ');';
|
|
||||||
?>
|
|
||||||
@@ -8,5 +8,3 @@ tweets.txt
|
|||||||
/bootstrap/docs/assets/img/glyphicons-halflings.png
|
/bootstrap/docs/assets/img/glyphicons-halflings.png
|
||||||
/style.css
|
/style.css
|
||||||
/jquery-1.7.2.min.js
|
/jquery-1.7.2.min.js
|
||||||
NETWORK:
|
|
||||||
grep.php
|
|
||||||
|
|||||||
25
main.js
25
main.js
@@ -1,4 +1,5 @@
|
|||||||
var l = []; // avoid expensive $.get for local searches
|
var l = []; // avoid expensive $.get for local searches
|
||||||
|
|
||||||
function search(query, lines) {
|
function search(query, lines) {
|
||||||
var results = "<p class=\"label\">Searched for: " + query + "</p><ol>";
|
var results = "<p class=\"label\">Searched for: " + query + "</p><ol>";
|
||||||
for (var i = 0; i < lines.length; i++) {
|
for (var i = 0; i < lines.length; i++) {
|
||||||
@@ -21,27 +22,15 @@ function search(query, lines) {
|
|||||||
|
|
||||||
function grep(query) {
|
function grep(query) {
|
||||||
|
|
||||||
if (navigator.onLine) {
|
if (l.length > 0) {
|
||||||
|
search(query, l);
|
||||||
$.getJSON("/u/" + NAME + "/grep.php?jsoncallback=?", {
|
|
||||||
q: query
|
|
||||||
},
|
|
||||||
function(data) {
|
|
||||||
search(query, data);
|
|
||||||
});
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
$.get('tweets.txt', function(data) {
|
||||||
if (l.length > 0) {
|
l = data.split("\n");
|
||||||
search(query, l);
|
search(query, l);
|
||||||
} else {
|
});
|
||||||
$.get('tweets.txt', function(data) {
|
|
||||||
l = data.split("\n");
|
|
||||||
search(query, l);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$(document).ready(function() {
|
$(document).ready(function() {
|
||||||
|
|||||||
Reference in New Issue
Block a user