forked from jdfwarrior/Workflows
-
Notifications
You must be signed in to change notification settings - Fork 0
/
yd.php
30 lines (26 loc) · 918 Bytes
/
yd.php
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
<?php
require_once('workflows.php');
require_once('ParserDom.php');
$wf = new Workflows();
$query = "{query}";
$query = str_replace('\\ ', ' ', trim($query));
$request = file_get_contents('http://dict.youdao.com/search?q='.urlencode($query).'&keyfrom=dict.top');
$html_dom = new \HtmlParser\ParserDom($request);
if(strstr($query, ' '))
{
$result = $html_dom->find('#fanyiToggle .trans-container p');
if(count($result) >= 3)
{
$result = $result[1];
$wf->result( $query, $query, $query, trim($result->getPlainText()), 'icon.png' );
}
}else{
$result = $html_dom->find('#phrsListTab .trans-container ul li');
foreach ($result as $value)
{
$value = explode('.', $value->getPlainText());
$type = trim(array_shift($value)," ");
$wf->result( $query, $query, $query.' - '.$type.'.', trim(implode(' ', $value)," "), 'icon.png' );
}
}
echo $wf->toxml();