mirror of
https://github.com/microsoft/PowerToys.git
synced 2024-12-14 19:49:15 +08:00
ba1e22955e
1. suggestion is async 2. if ping time of domain less than 300ms, then suggestion is still sync 3. #578 #539
40 lines
1.2 KiB
C#
40 lines
1.2 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using Newtonsoft.Json;
|
|
using Newtonsoft.Json.Linq;
|
|
using Wox.Infrastructure.Http;
|
|
|
|
namespace Wox.Plugin.WebSearch.SuggestionSources
|
|
{
|
|
public class Google : SuggestionSource
|
|
{
|
|
public override string Domain { get; set; } = "www.google.com";
|
|
public override List<string> GetSuggestions(string query)
|
|
{
|
|
var result = HttpRequest.Get("https://www.google.com/complete/search?output=chrome&q=" + Uri.EscapeUriString(query), Proxy);
|
|
if (string.IsNullOrEmpty(result)) return new List<string>();
|
|
|
|
try
|
|
{
|
|
JContainer json = JsonConvert.DeserializeObject(result) as JContainer;
|
|
if (json != null)
|
|
{
|
|
var results = json[1] as JContainer;
|
|
if (results != null)
|
|
{
|
|
return results.OfType<JValue>().Select(o => o.Value).OfType<string>().ToList();
|
|
}
|
|
}
|
|
}
|
|
catch { }
|
|
|
|
return new List<string>();
|
|
}
|
|
|
|
public Google(IHttpProxy httpProxy) : base(httpProxy)
|
|
{
|
|
}
|
|
}
|
|
}
|