blob: 88a3dab069ce6a52af0e25a3ea3693a9ff7086f1 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
<html>
<head>
<title>dump.fm image search</title>
$head()$
<style>
img { max-width: 400px; max-height: 400px;}
</style>
</head>
<body>
<input type="text" name="search-query" id="search-query" />
<div id="message"></div>
<div id="content"></div>
</body>
<script>
var term = ""
var maxImages = 25;
function addScript(term){
jQuery("#search-script").remove()
jQuery("head").append("<scr"+"ipt src='/cmd/ghettosearch/"+term+"' id='search-script'></sc"+"ript>")
}
function setContent(x){
jQuery("#content").html(x)
}
function setMessage(x){
jQuery("#message").html(x)
}
function searchError(error){
setContent("")
setMessage(error)
}
function searchResult(results){
var images = []
var alreadyGot = {}
if(results === null || results.length == 0) {
setContent("")
setMessage("no results found")
} else {
for(var r = 0; r<results.length; r++){
if (images.length == maxImages) break;
var content = results[r]['content']
if (content.substring(0,6) == "<safe>") continue; // skip html posts
var imageUrls = getImagesAsArray(content);
for (var i=0; i<imageUrls.length; i++){
var imageUrl = imageUrls[i];
if (imageUrl in alreadyGot) continue;
alreadyGot[imageUrl] = true
if (imageUrl.indexOf(term) > -1)
images.push(imageUrl)
}
}
var contentString = ''
for(var i = 0; i < images.length; i++){
contentString += '<a href="'+images[i]+'"><img src="'+images[i]+'"></a>'
}
setContent(contentString)
}
}
function doSearch(){
term = jQuery("#search-query").val().trim()
if (term.length < 3) {
setMessage("search query too small")
} else {
setMessage("searching for '"+term+"'")
addScript(term)
}
}
// only search every 500ms while someone is typing
function keyHandler(){
if (keyHandler.timeout) clearTimeout(keyHandler.timeout);
keyHandler.timeout = setTimeout(doSearch, 250)
}
jQuery("#search-query").keyup(keyHandler)
</script>
</html>
|