aardio:用 WebView 模仿 mdict 界面

aardio:用 WebView 模仿 mdict 界面

javascript 复制代码
import win.ui;
/*DSG{{*/
mainForm = win.form(text="aardio2";right=889;bottom=467)
mainForm.add(
button={cls="button";text="go";left=335;top=22;right=399;bottom=41;z=2};
button2={cls="button";text="prefix";left=426;top=21;right=497;bottom=40;z=4};
button3={cls="button";text="sound";left=537;top=23;right=596;bottom=38;z=5};
custom={cls="custom";text="WebView2";left=165;top=55;right=889;bottom=469;z=3};
edit={cls="edit";left=17;top=19;right=317;bottom=43;edge=1;z=1};
listbox={cls="listbox";left=7;top=56;right=161;bottom=463;edge=1;items={};vscroll=1;z=6}
)
/*}}*/

import web.view;
var wb = web.view(mainForm.custom);

import web.json;
import console;
import win.dlg.message;
var $msg = win.dlg.message();

import io;
import sys;
import fsys.media;
import web.rest.jsonClient;
//创建 HTTP 客户端
var http = web.rest.jsonClient();

var basepath = "D:\mdict\data";
//导出本地函数给网页 JavaScript
wb.external = {
  mplay = function(url){
	if (string.startWith(url, "sound://")){
		if (string.endWith(txt, ".mp3")){
			var str = string.slice(txt,8,-1,true);
			var path = basepath + string.replace(str,"/",`\`);
			if(! io.exist(path)){
				$msg.ok(path+" not found.");
				return;
			}
			mediaFile = fsys.media(path);
			if(mediaFile){ mediaFile.play();}
		}
	}		
  }
}

var js = /**
  window.onload = function(){
    document.body.addEventListener('click', function(event){
        var target = event.target || event.srcElement;      // 兼容处理
        if (target.nodeName.toLocaleLowerCase() === "a") {  // 判断是否匹配目标元素
            if (event.preventDefault) {     // 对捕获到的 a 标签进行处理
                event.preventDefault();
                var addr = target.getAttribute('href');
                if (addr.indexOf('sound://')==0){
                    alert('href='+addr);
                } else {
                    alert('href='+addr);
                }
            }
        }       
    });
  }
**/

var baseurl = "http://localhost:8888/";
//响应按钮事件
mainForm.button.oncommand = function(id,event){
	var url = mainForm.edit.text ;
	if (string.startWith(url, "http://") or string.startWith(url, "https://")){
		wb.go(url);
	} else {
		url = baseurl + "trans?txt=" + string.trim(url)
		wb.go(url);
		//wb.doScript(js);
	}
}

mainForm.button2.oncommand = function(id,event){
	var txt = mainForm.edit.text;
	var str = string.trim(txt);
	if (string.startWith(str, "http://")){
		wb.go(str);
	} else {
		//url = baseurl + "prefix?txt=" + txt;
		//发送 GET 请求
		var ret = http.get(baseurl++"prefix",{ txt=str });
		//console.dumpJson(ret);
		mainForm.listbox.clear();		
		for( k,v in ret){
			mainForm.listbox.add(v);
		}
		mainForm.listbox.selIndex = 1;
	}
}

mainForm.button3.oncommand = function(id,event){
	var txt = mainForm.edit.text ;
	if (string.startWith(txt, "sound://")){
		if (string.endWith(txt, ".mp3")){
			var str = string.slice(txt,8,-1,true);
			var path = basepath + string.replace(str,"/",`\`);
			if(! io.exist(path)){
				$msg.ok(path+" not found.");
				return;
			}
			mediaFile = fsys.media(path);
			if(mediaFile) {
				mediaFile.play();
			}
		}
	}		
}

mainForm.listbox.oncommand = function(id,event){
	if( event == 0x1/*_LBN_SELCHANGE*/ ){
		str = mainForm.listbox.selText;
		url = baseurl + "trans?txt=" + str;
		wb.go(url);
	}
}

mainForm.show();
return win.loopMessage();
相关推荐
qq762118221 个月前
windows mfc webview2 接收html信息
c++·html·mfc·webview2·通信
IssacNew3 个月前
【原创软件】第7期:文件夹生成器V1.0-按照列表批量生成文件夹,简单小巧
aardio·列表·批量生成·记住文件夹·同名文件夹·文件夹
卢光庆3 个月前
aardio —— 今日减bug
aardio
djk88883 个月前
.net core 的 winform 的 浏览器控件 WebView2
ui·.netcore·webview2
卢光庆6 个月前
aardio - godking.json 【库】测试
aardio
卢光庆8 个月前
aardio - 调用C编写的dll时的不同参数类型处理方法
aardio
东明之羞8 个月前
五.Winform使用Webview2创建界面,配置Router管理界面窗体界面
windows·microsoft·c#·webview·winform·webview2