-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.html
108 lines (105 loc) · 4.13 KB
/
index.html
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
<!DOCTYPE html>
<html lang="en">
<head>
<title>OpenGameArt Search</title>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<!-- Load icon library -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css"></link>
<link rel="stylesheet" href="index.css"></link>
</head>
<body>
<a href="https://github.com/emnh/PixelArtSearch"><img loading="lazy" width="149" height="149" src="https://github.blog/wp-content/uploads/2008/12/forkme_left_red_aa0000.png?resize=149%2C149" class="attachment-full size-full" alt="Fork me on GitHub" data-recalc-dims="1"></a>
<!-- The form -->
<div id="main">
<h1>Sorry, search is down (forever, saving money on disk space)</h1>
<h2>OpenGameArt Search + Reverse Image Search</h2>
<p>Hint: Start search term with http(s):// for reverse image search.</p>
<p>Made using <a href="https://www.pinecone.io/">pinecone.io</a> free trial, so will be live for 1 month until April 3rd 2021.</p>
<form id="searchform" class="searchform" action="search/" method="POST" onsubmit="submitSearch();">
<input id="searchinput" type="text" placeholder="Search.." name="imsi">
<button type="submit"><i class="fa fa-search"></i></button>
</form>
<div id="results">
</div>
</div>
<script>
function getUrlParameter(name, decode) {
name = name.replace(/[\[]/, '\\[').replace(/[\]]/, '\\]');
var regex = new RegExp('[\\?&]' + name + '=([^&#]*)');
var results = regex.exec(location.search);
if (decode) {
return results === null ? '' : decodeURIComponent(results[1].replace(/\+/g, ' '));
} else {
return results === null ? '' : results[1];
}
};
function submitSearch() {
//var formData = JSON.stringify($("#searchform").serializeArray());
var imsi = $("#searchinput").val();
if (imsi === '') {
imsi = getUrlParameter('imsi', false);
// Some stupid stuff with regard to double url quoting
if (imsi.includes('https://emh.lart.no') && imsi.includes('%20')) {
imsi = encodeURIComponent(imsi);
}
//if (imsi.includes('https%3A%2F%2Femh.lart.no')) {
if (imsi.includes('https%3A%2F%2F') || imsi.includes('http%3A%2F%2F')) {
imsi = decodeURIComponent(imsi);
}
if (!imsi.includes('http')) {
imsi = getUrlParameter('imsi', true);
}
}
count = getUrlParameter('count');
if (count === '') {
count = 20;
}
$("#results").html("<h2>Searching..</h2>");
$.ajax({
type: "POST",
url: "/ogasearch/search/",
data: JSON.stringify({
imsi: imsi,
count: count
}),
success: function(data){
console.log("success");
$("#results").html(data);
$("img.searchresult").each(function() {
$(this).parent().append('<div><a href="/ogasearch/?imsi=' + $(this)[0].src + '">More like this</a></div>');
$(this).parent().addClass("searchparent");
});
var urlPath = '/ogasearch/?imsi=' + imsi + '&count=' + count.toString();
window.history.pushState({"html":data,"pageTitle": 'q=imsi'},"", urlPath);
},
error: function(xhr, textStatus, errorThrown) {
console.log("error");
$("#results").html('<h1>' + textStatus + '</h1><h1>' + errorThrown + '</h1>');
},
dataType: "html",
contentType : "application/json"
});
}
$(document).ready(function() {
$(window).keydown(function(event){
if(event.keyCode == 13) {
submitSearch();
event.preventDefault();
return false;
}
});
$("#submitSearch").submit(function() {
submitSearch();
event.preventDefault();
return false;
});
var imsi = getUrlParameter('imsi');
if (imsi !== '') {
submitSearch();
}
});
$("#searchform").attr("action", "")
$("#searchform").attr("method", "")
</script>
</body>
</html>