deCloudflare/tool/ansero_example.html

97 lines
2.6 KiB
HTML
Raw Normal View History

2020-03-18 10:28:19 +00:00
<html>
<head>
<title>Search</title>
<style>
body {
background: #f0f0f0
}
input#what {
width: 80%
}
span.srch_sect {
color: #2f4f4f
}
a.srch_link {
color: #4b0082
}
span.srch_url {
color: #20b2aa
}
a[onclick] {
cursor: pointer
}
</style>
<script>
2020-06-22 10:17:19 +00:00
2020-11-10 09:31:05 +00:00
// read API document
2020-12-09 00:33:08 +00:00
let apiurl = 'https://(API)/_/ansero.php';
let favurl = 'https://(API)/_/favicon.php?f=';
let mylang = 'en-US'; // e.g. 'fr'
let hide_domain = []; // e.g. ['google.com', 'google.fr']
let hide_fqdn = []; // e.g. ['en.wikipedia.org']
2020-03-18 10:28:19 +00:00
let removeMITMsites = false;
2020-06-22 10:17:19 +00:00
2020-12-09 00:33:08 +00:00
function searchFor(key) {
2020-03-18 10:28:19 +00:00
document.getElementById('what').value = key;
search();
}
2020-06-22 10:17:19 +00:00
2020-03-18 10:28:19 +00:00
function search() {
let answer = '',
keyword = document.getElementById('what').value;
if (keyword.length < 2) {
return false;
}
fetch(apiurl, {
method: 'POST',
mode: 'cors',
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
},
body: 't=json' + (removeMITMsites ? '&m' : '') + '&l=' + mylang + '&q=' + encodeURI(keyword)
}).then(r => r.json()).then(r => {
if (r.info.desc != undefined) {
answer += '<span class="srch_sect">';
answer += '' + r.info.desc + '<br>';
answer += '<a href="' + r.info.url + '" class="srch_link">' + r.info.title + '</a>';
answer += '</span><br><br>';
}
if (r.sgst.length > 0) {
answer += '<span class="srch_sect">Search other: <br>';
r.sgst.forEach(x => {
2020-12-09 00:33:08 +00:00
answer += '[<a class="srch_link" onclick="searchFor(\'' + x + '\');return false;">' + x + '</a>]<br>';
2020-03-18 10:28:19 +00:00
});
answer += '</span><br><br>';
}
2020-12-09 00:33:08 +00:00
if (r.crct.length > 0) {
answer += '<span class="srch_sect">Maybe: ';
answer += '[<a class="srch_link" onclick="searchFor(\'' + r.crct[0] + '\');return false;">' + r.crct[0] + '</a>]<br>';
answer += '</span><br><br>';
}
2020-03-18 10:28:19 +00:00
r.res.forEach(x => {
if (!hide_fqdn.includes(x.fqdn) && !hide_domain.includes(x.dom)) {
answer += '<span class="srch_sect">';
answer += '<img src="' + favurl + (x.url.startsWith('https:') ? '1-' : '0-') + x.fqdn + '"> ';
answer += '<a href="' + x.url + '" class="srch_link">' + (x.mitm == 1 ? '[MITM!!] ' : '') + x.title + '</a><br>';
answer += '' + x.desc + '<br>';
answer += '<span class="srch_url">' + x.url + '</span></span>';
answer += '<br><br>';
}
});
document.getElementById('resultarea').innerHTML = answer;
}).catch(e => console.log(e));
return false;
}
2020-06-22 10:17:19 +00:00
2020-03-18 10:28:19 +00:00
</script>
</head>
<body>
<form action="#" onsubmit="return search()">
<input type="text" id="what" placeholder="Search for..." minlength="2" required>
<input type="submit" value="Search">
</form>
<br>
<br>
<span id="resultarea"></span>
</body>
</html>