本文整理汇总了C#中ScriptEngine.CallGlobalFunction方法的典型用法代码示例。如果您正苦于以下问题:C# ScriptEngine.CallGlobalFunction方法的具体用法?C# ScriptEngine.CallGlobalFunction怎么用?C# ScriptEngine.CallGlobalFunction使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ScriptEngine
的用法示例。
在下文中一共展示了ScriptEngine.CallGlobalFunction方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetVideoUrl
public override string GetVideoUrl(string url)
{
if(!url.Contains("embed-"))
{
url = url.Replace("play.to/", "play.to/embed-");
}
if (!url.EndsWith(".html"))
{
url += ".html";
}
string data = GetWebData<string>(url);
Regex rgx = new Regex(@">eval(?<js>.*?)</script>", RegexOptions.Singleline);
Match m = rgx.Match(data);
if (m.Success)
{
ScriptEngine engine = new ScriptEngine();
string js = m.Groups["js"].Value;
engine.Execute("var player = " + js + ";");
engine.Execute("function getPlayer() { return player; };");
data = engine.CallGlobalFunction("getPlayer").ToString();
rgx = new Regex(@"file:""(?<url>http[^""]*?.mp4)""");
m = rgx.Match(data);
if (m.Success)
{
return m.Groups["url"].Value;
}
}
return "";
}
示例2: Process
public void Process(BundleContext context, BundleResponse response)
{
var coffeeScriptPath =
Path.Combine(
HttpRuntime.AppDomainAppPath,
"Scripts",
"coffee-script.js");
if (!File.Exists(coffeeScriptPath))
{
throw new FileNotFoundException(
"Could not find coffee-script.js beneath the ~/Scripts directory.");
}
var coffeeScriptCompiler =
File.ReadAllText(coffeeScriptPath, Encoding.UTF8);
var engine = new ScriptEngine();
engine.Execute(coffeeScriptCompiler);
// Initializes a wrapper function for the CoffeeScript compiler.
var wrapperFunction =
string.Format(
"var compile = function (src) {{ return CoffeeScript.compile(src, {{ bare: {0} }}); }};",
_bare.ToString(CultureInfo.InvariantCulture).ToLower());
engine.Execute(wrapperFunction);
var js = engine.CallGlobalFunction("compile", response.Content);
response.ContentType = ContentTypes.JavaScript;
response.Content = js.ToString();
}
示例3: GetVideoUrl
public override string GetVideoUrl(string url)
{
string url2 = url;
if (url.ToLower().Contains("view.php"))
{
url2 = url.Replace("view.php", "iframe.php");
}
else if (!url.ToLower().Contains("iframe.php"))
{
int p = url.IndexOf('?');
url2 = url.Insert(p, "iframe.php");
}
string webData = WebCache.Instance.GetWebData(url2);
Match m = Regex.Match(webData, @"eval\((?<js>.*)?\)$", RegexOptions.Multiline);
if (!m.Success)
return string.Empty;
string js = "var p = ";
js += m.Groups["js"].Value;
js += "; ";
js += "function packed(){return p;};";
ScriptEngine engine = new ScriptEngine();
engine.Execute(js);
string data = engine.CallGlobalFunction("packed").ToString();
m = Regex.Match(data, @"""(?<url>http[^""]*)");
if (!m.Success)
return String.Empty;
SetSub(webData);
return m.Groups["url"].Value;
}
示例4: Execute
public string Execute(string scriptValue)
{
var jsContext = new ScriptEngine();
jsContext.Evaluate("function __result__() {" + scriptValue + "}");
return jsContext.CallGlobalFunction("__result__").ToString();
}
示例5: DecryptWithCustomParser
private string DecryptWithCustomParser(string jsContent, string s)
{
try
{
// Try to get the functions out of the java script
JavaScriptParser javaScriptParser = new JavaScriptParser(jsContent);
FunctionData functionData = javaScriptParser.Parse();
StringBuilder stringBuilder = new StringBuilder();
foreach (var functionBody in functionData.Bodies)
{
stringBuilder.Append(functionBody);
}
ScriptEngine engine = new ScriptEngine();
engine.Global["window"] = engine.Global;
engine.Global["document"] = engine.Global;
engine.Global["navigator"] = engine.Global;
engine.Execute(stringBuilder.ToString());
return engine.CallGlobalFunction(functionData.StartFunctionName, s).ToString();
}
catch (Exception ex)
{
Log.Info("Signature decryption with custom parser failed: {0}", ex.Message);
}
return string.Empty;
}
示例6: GetPostTime
/// <summary>
/// 将页面上的脚本转换成时间
/// </summary>
/// <param name="postTime">格式是:1409710649 </param>
/// <returns></returns>
static string GetPostTime(string postTime)
{
string timeSpan = string.Empty;
var JSEngine = new ScriptEngine();
JSEngine.Evaluate("function vrTimeHandle552(time){ if (time) {var type = [\"1分钟前\", \"分钟前\", \"小时前\", \"天前\", \"周前\", \"个月前\", \"年前\"];"
+" var secs = (new Date().getTime())/1000 - time; if(secs < 60){ return type[0]; }else if(secs < 3600){ return Math.floor(secs/60) + type[1]; }else if(secs < 24*3600){"
+" return Math.floor(secs/3600) + type[2]; }else if(secs < 24*3600 *7){ return Math.floor(secs/(24*3600)) + type[3]; }else if(secs < 24*3600*31){"
+" return Math.round(secs/(24*3600*7)) + type[4]; }else if(secs < 24*3600*365){ return Math.round(secs/(24*3600*31)) + type[5]; }else if(secs >= 24*3600*365){"
+" return Math.round(secs/(24*3600*365)) + type[6]; }else { return ''; } } else { return ''; }}");
timeSpan = JSEngine.CallGlobalFunction<string>("vrTimeHandle552", int.Parse(postTime));
return timeSpan;
}