-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathpyrunjs.py
More file actions
56 lines (45 loc) · 1.82 KB
/
Copy pathpyrunjs.py
File metadata and controls
56 lines (45 loc) · 1.82 KB
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# -*- coding:utf-8 -*-
from ctypes import (c_longlong,byref)
from .method import method
class PyRunJS():
def __init__(self,miniblink):
self.mb=miniblink
def run_js(self,webview,js_code):
es=self.mb.wkeGlobalExec(webview)
val=self.mb.wkeRunJSW(webview,js_code)
val=self.mb.jsToStringW(es,val)
if val=='undefined':
val=None
return val
def run_js_file(self,webview,file_name):
with open(file_name) as f:
js_code=f.read()
return self.run_js(webview,js_code)
def run_js_byframe(self,webview,frameId,js_code,isInClosure=True):
js_code=js_code.encode()
val=self.mb.wkeRunJsByFrame(webview,frameId,js_code,isInClosure)
es = self.mb.wkeGetGlobalExecByFrame(webview, frameId)
val=self.mb.jsToTempStringW(es, c_longlong(val))
return val
def run_js_global(self,webview,func_name,param_ls=[],this_func=0):
es=self.mb.wkeGlobalExec(webview)
if this_func==0:
func_name=func_name.encode()
func=self.mb.jsGetGlobal(es,func_name)
else:
...
argCount=len(param_ls)
args_ls=(c_longlong *argCount)()
for i,param in enumerate(param_ls):
if isinstance(param,str):
param=self.mb.jsStringW(es,param)
elif isinstance(param,int):
param=self.mb.jsInt(c_longlong(param))
elif isinstance(param,float):
param=self.mb.jsFloat(param)
elif isinstance(param,bool):
param=self.mb.jsBoolean(param)
args_ls[i]=param
callRet=self.mb.jsCall(es,c_longlong(func),c_longlong(this_func),byref(args_ls),c_longlong(argCount))
val=self.mb.jsToStringW(es,c_longlong(callRet))
return val