206 lines
9.0 KiB
HTML
Executable File
206 lines
9.0 KiB
HTML
Executable File
<html>
|
|
<body>
|
|
<h2>Copart Auctions</h2>
|
|
<form id="form" target="hidden" onsubmit="query(); return false;">
|
|
<input type="text"/>
|
|
<button type="submit">Search</button>
|
|
</form>
|
|
<table><tbody>
|
|
<tr>
|
|
<th>Title</th>
|
|
</tr>
|
|
</tbody></table>
|
|
<div id="log"></div>
|
|
<iframe name="hidden", width=0, height=0, border=0, style="display: none;"></iframe>
|
|
</body>
|
|
<head>
|
|
<script>
|
|
function http(method, remote, callback, body) {
|
|
var xmlhttp = new XMLHttpRequest();
|
|
xmlhttp.onreadystatechange = function() {
|
|
if (xmlhttp.readyState == XMLHttpRequest.DONE) { // XMLHttpRequest.DONE == 4
|
|
callback(xmlhttp.status, xmlhttp.responseText)
|
|
}
|
|
};
|
|
xmlhttp.open(method, remote, true);
|
|
if (typeof body == "undefined") {
|
|
body = null
|
|
}
|
|
xmlhttp.send(body);
|
|
}
|
|
|
|
function log() {
|
|
args = []
|
|
for (var i in arguments)
|
|
args.push(arguments[i])
|
|
msg = args.join(", ")
|
|
document.getElementById("log").innerHTML += "<br>"+msg
|
|
}
|
|
|
|
function populate(items) {
|
|
doc = list_headers
|
|
for (var i in items) {
|
|
doc += "<tr>"
|
|
for (var j in items[i]) {
|
|
if (j == 0)
|
|
items[i][j] = halve(items[i][j])
|
|
doc += "<td>" + items[i][j] + "</td>"
|
|
}
|
|
for (var j = items[i].length; j < 5; j++)
|
|
doc += "<td></td>"
|
|
doc += "</tr>\n"
|
|
}
|
|
document.getElementsByTagName("tbody")[0].innerHTML = doc
|
|
}
|
|
|
|
function populate_list(status_code, body) {
|
|
var k = 0
|
|
var list = []
|
|
var writelist = []
|
|
if (status_code != 200) {
|
|
log("ERR failed to load list", status_code)
|
|
writelist = [ ["Sample car title goes here", "2000-01-02", "$2"] ]
|
|
} else {
|
|
list = JSON.parse(body)
|
|
}
|
|
for (var i in list) {
|
|
k += 1
|
|
if (k > 50)
|
|
break
|
|
form = list[i].substr(5, list[i].indexOf(" watched")-5)
|
|
bid = form.substr(0, form.indexOf("title:"))
|
|
title = form.substr(form.indexOf("title:")+6, form.length)
|
|
when = list[i].substr(list[i].indexOf("when:")+5, 10)
|
|
writelist.push([title, when, bid])
|
|
}
|
|
populate(writelist)
|
|
}
|
|
|
|
function halve(s) {
|
|
s = s.split(" ")
|
|
n = s.length
|
|
n /= 2
|
|
n = n
|
|
s = s.slice(0, n).join(" ") + "<br>" + s.slice(n, s.length).join(" ")
|
|
return s
|
|
}
|
|
|
|
function query() {
|
|
form = document.getElementById("form")
|
|
text = form.getElementsByTagName("input")[0].value
|
|
text = text.split(" ")
|
|
q = []
|
|
for (var i in text)
|
|
if (text[i].length > 0)
|
|
q.push("q="+text[i])
|
|
q = q.join("&")
|
|
callback = function(status_code, body) {
|
|
if (status_code != 200) {
|
|
results = []
|
|
} else {
|
|
results = JSON.parse(body)
|
|
}
|
|
items = []
|
|
for (var i in results) {
|
|
item = []
|
|
keys = Object.keys(results[i]).sort()
|
|
keys.splice(keys.indexOf("title"), 1)
|
|
keys.unshift("title")
|
|
for (var j in keys) {
|
|
if (keys[j] == "details")
|
|
item.push(format_details(results[i][keys[j]]))
|
|
else if (keys[j] == "images")
|
|
item.push(format_images(results[i][keys[j]]))
|
|
else
|
|
item.push(results[i][keys[j]])
|
|
}
|
|
items.push(item)
|
|
}
|
|
populate(items)
|
|
}
|
|
http("get", "/api?"+q, callback, "")
|
|
}
|
|
|
|
function format_details(details) {
|
|
out = ""
|
|
for (var k in details) {
|
|
v = details[k]
|
|
if (out.length > 0)
|
|
out += "<br>"
|
|
out += k+": "+v
|
|
}
|
|
out = "<details>"+out+"<summary>Details</summary></details>"
|
|
return out
|
|
}
|
|
|
|
function format_images(images) {
|
|
out = ""
|
|
for (var i in images) {
|
|
out += "<img src='"+images[i]+"'></img>"
|
|
}
|
|
out = "<details>"+out+"<summary>Pictures</summary></details>"
|
|
return out
|
|
}
|
|
|
|
var list_headers = '<tr>'
|
|
+'<th>Title</th>'
|
|
+'<th>Auction Date</th>'
|
|
+'<th>Sale Price</th>'
|
|
+'<th>Details</th>'
|
|
+'<th>Images</th>'
|
|
+'</tr>'
|
|
var cors_anywhere = "https://cors-anywhere.herokuapp.com"
|
|
var google_doc_pre = "https://docs.google.com/spreadsheets/d/"
|
|
var google_doc_id = "14F7zRrwGT6JkCeZqZLPM2r2GScrm9FLFxlPtDINbNWg"
|
|
var google_doc_post = "/gviz/tq?tqx=out:csv"
|
|
|
|
/*
|
|
http(
|
|
"get",
|
|
`${cors_anywhere}/${google_doc_pre}/${google_doc_id}/${google_doc_post}`,
|
|
callback,
|
|
JSON.stringify({"cc": "cc"}),
|
|
)
|
|
*/
|
|
|
|
http("get", "/api/LIST", populate_list, "")
|
|
</script>
|
|
<style>
|
|
body
|
|
, tbody
|
|
{
|
|
font-size: 125% !important;
|
|
max-width: 90% !important;
|
|
}
|
|
td
|
|
img
|
|
{
|
|
display: block;
|
|
}
|
|
#nav
|
|
{
|
|
width: 150px;
|
|
vertical-align: top;
|
|
background-color: #990000;
|
|
color: #fff;
|
|
height: 100%;
|
|
}
|
|
#nav > a
|
|
{
|
|
color: #fff;
|
|
}
|
|
summary
|
|
{
|
|
cursor: pointer;
|
|
-webkit-touch-callout: none;
|
|
-webkit-user-select: none;
|
|
-khtml-user-select: none;
|
|
-moz-user-select: none;
|
|
-ms-user-select: none;
|
|
user-select: none;
|
|
}
|
|
@charset "UTF-8";body{font-family:system-ui,-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen,Ubuntu,Cantarell,Fira Sans,Droid Sans,Helvetica Neue,sans-serif;line-height:1.4;max-width:800px;margin:20px auto;padding:0 10px;color:#363636;background:#fff;text-rendering:optimizeLegibility}button,input,textarea{transition:background-color .1s linear,border-color .1s linear,color .1s linear,box-shadow .1s linear,transform .1s ease}h1{font-size:2.2em;margin-top:0}h1,h2,h3,h4,h5,h6{margin-bottom:12px}h1,h2,h3,h4,h5,h6,strong{color:#000}b,h1,h2,h3,h4,h5,h6,strong,th{font-weight:600}blockquote{border-left:4px solid #700;margin:1.5em 0;padding:.5em 1em;font-style:italic}blockquote>footer{margin-top:10px;font-style:normal}address,blockquote cite{font-style:normal}a[href^=mailto]:before{content:"📧 "}a[href^=tel]:before{content:"📞 "}a[href^=sms]:before{content:"💬 "}button,input[type=button],input[type=checkbox],input[type=submit]{cursor:pointer}input:not([type=checkbox]):not([type=radio]),select{display:block}button,input,select,textarea{color:#000;background-color:#efefef;font-family:inherit;font-size:inherit;margin-right:6px;margin-bottom:6px;padding:10px;border:none;border-radius:6px;outline:none}button,input:not([type=checkbox]):not([type=radio]),select,textarea{-webkit-appearance:none}textarea{margin-right:0;width:100%;box-sizing:border-box;resize:vertical}button,input[type=button],input[type=submit]{padding-right:30px;padding-left:30px}button:hover,input[type=button]:hover,input[type=submit]:hover{background:#ddd}button:focus,input:focus,select:focus,textarea:focus{box-shadow:0 0 0 2px #700}button:active,input[type=button]:active,input[type=checkbox]:active,input[type=radio]:active,input[type=submit]:active{transform:translateY(2px)}button:disabled,input:disabled,select:disabled,textarea:disabled{cursor:not-allowed;opacity:.5}::-webkit-input-placeholder{color:#949494}::-moz-placeholder{color:#949494}:-ms-input-placeholder{color:#949494}::-ms-input-placeholder{color:#949494}::placeholder{color:#949494}a{text-decoration:none;color:#900}a:hover{text-decoration:underline}code,kbd{background:#efefef;color:#000;padding:5px;border-radius:6px}pre>code{padding:10px;display:block;overflow-x:auto}img{max-width:100%;height:auto}hr{border:none;border-top:1px solid #dbdbdb}table{border-collapse:collapse;margin-bottom:10px;width:100%}td,th{padding:6px;text-align:left}th{border-bottom:1px solid #dbdbdb}tbody tr:nth-child(2n){background-color:#efefef}::-webkit-scrollbar{height:10px;width:10px}::-webkit-scrollbar-track{background:#efefef;border-radius:6px}::-webkit-scrollbar-thumb{background:#d5d5d5;border-radius:6px}::-webkit-scrollbar-thumb:hover{background:#c4c4c4}::-moz-selection{background-color:#9e9e9e}::selection{background-color:#9e9e9e}
|
|
</style>
|
|
</head>
|
|
</html>
|