我做了一个 chrome 扩展来搜索网站 dev.bukkit.org,它适用于以下代码:
<script>
function onLoad() {
document.getElementById("mytextfield").focus();
}
function onKeyPress(e) {
if (e.keyCode == 13) {
openResults();
}
}
function openHomePage() {
window.open("http://dev.bukkit.org/");
}
function openResults() {
window.open("http://dev.bukkit.org/search/?search=" + encodeURIComponent(document.getElementById("mytextfield").value));
}
</script>
</head>
<body onload="onLoad();">
<img src="png-3.png" onclick="openHomePage();" style="border-width: 0px; cursor: pointer" /><br>
<div name="myFormDiv" style="center: 6px;">
<br>
<center><input type="search" id="mytextfield" name="mytextfield" placeholder="Search..." onkeypress="onKeyPress(event);" /></center>
</div>
我现在想选择搜索 forum.bukkit.org。不幸的是,它需要一个令牌来搜索论坛。一位朋友给了我一个 php 片段,可以让您搜索论坛,但我无法将其集成到原始代码中以搜索 dev.bukkit.org。帮助将不胜感激,我迷路了!PHP论坛搜索代码:
<?php
$q=$_GET['q'];
echo do_post_request("http://forums.bukkit.org/search/search",'keywords='.$q.'&_xfToken=10000%2C1333276150%2C1b8a644c97b33e9cfda0e15170ca5185cf15bc3a');
function do_post_request($url, $data, $optional_headers = null)
{
$params = array('http' => array(
'method' => 'POST',
'content' => $data
));
if ($optional_headers !== null) {
$params['http']['header'] = $optional_headers;
}
$ctx = stream_context_create($params);
$fp = @fopen($url, 'rb', false, $ctx);
if (!$fp) {
throw new Exception("Problem with $url, $php_errormsg");
}
$response = @stream_get_contents($fp);
if ($response === false) {
throw new Exception("Problem reading data from $url, $php_errormsg");
}
return $response;
}
?>
谢谢:)