论坛潜水机 部分源码
原文地址:http://www.ecranesoft.com/bbs/showtopic-9124.aspx
功能:1.定时提示新贴或回复(好处:纯后台操作不会影响正常电脑使用,而有能及时了解论坛动态)
2.自动登录论坛
3.集成lujjjh的多窗口浏览器功能
大家可根据需要,自行把常用的工具集成进来,做成一个真正的工具包...
源码请查看SVN最新版本
https://svn.ecranesoft.com/svn/aauto/Tools/%e4%b8%80%e9%b9%a4%e8%ae%ba%e5%9d%9b%e8%be%85%e5%8a%a9%e5%b7%a5%e5%85%b7/main.aau
批注:所有代码都做了详细的注释,新手应该可以看得懂吧,想了解多线程,托盘图标,菜单,web处理,界面处理可以看下源码,高手自行飘过...
下载发布后可直接用的版本:一鹤论坛辅助工具包(论坛潜水机)
*/
//部分源码如下:
/*监测新贴多线程处理开始{{*/
//////////////////监测新贴处理开始///////////////////////
winform.addtimer(1000,function(id){ //定时器
var addWebPageUrl=thread.get("addWebPageUrl")
if(addWebPageUrl){
thread.set("addWebPageUrl", null);
addWebPage(addWebPageUrl); //打开弹窗中的帖子
}
} )
Tthreads={};
thread.limit = function(h,max = 10){//限制线程数目
if(!h and #Tthreads>0){
thread.waitAll(Tthreads);
Tthreads ={};
}
else{
..table.push( Tthreads,h);
if( #Tthreads >= max){
var re = thread.waitOne(Tthreads);
if( Tthreads[re] ){
table.remove(Tthreads,re );
}
}
}
}
listenNewPost=function(){//建一个监测新贴定时器
var timenum=page2.ed_time.text;
timenum=tonumber(timenum);
if(!timenum or timenum<1){timenum=1;}
timenum=timenum*60;
return winform.addtimer(timenum*1000,function(id){
h,tid=thread.create(startThreadNewPost) //创建一个监测线程
//thread.limit(h,1); //限制线程数目 (同步处理请不要加这句 否则点击弹窗将卡S)
} )
}
startThreadNewPost=function(){ //启动一个线程
import win.ui;
import web.form;
import inet.whttp;
_bbsUrl=thread.get("_bbsUrl");
searchNewPost=function(){ //查找新贴
tabOldP=thread.get("tabOldP");
tabNewP={};
tabform={};//弹出的所有窗体
var newUrl=_bbsUrl + "showtopiclist.aspx?type=newtopic";
http=inet.whttp();
html,errmsg=http.down(newUrl);
http.close();
if(html){
html=string.fromto(html,65001,0);
for str in string.gmatch(html,"\<tbody(.+?)\</tbody\>") {
id,subject=string.match(str,"\<th class=""subject""\>.*?showtopic\-(\d+).*?\>(.*?)\</a")
author=string.match(str,"userinfo\-.*?\>(.*?)\</a");
nums=string.match(str,"\<td class=""nums""\>\<em\>(\d+)\</em\>");
lastposturl,postime=string.match(str,"\<td class=""lastpost.*?href=""(.*?)""\>(.*?)\</a\>");
lastby=string.match(str,"\<cite\>by.*?\>(.*?)\</a");
if(id and subject and postime){
subject=string.trim(subject);
postime=string.trim(postime);
id=tonumber(id);
tabNewP[id]=subject + '\t' + author + '\t' + nums + '\t' + lastposturl + '\t' + postime + '\t' + lastby;
//io.print(tabNewP[id])
}
win.delay(1);
}
}
if(table.count(tabOldP) and table.count(tabNewP)){
for(i,newstr in tabNewP){
t1=string.split(newstr,'\t');
if(!tabOldP[ i ]){
str=newstr;
isNew = t1[3]=="0" ? true : false; //新发表或有回复的贴子
forms=showPostChildWinform(newstr,isNew);
table.push(tabform,forms);
}
else {
t2=string.split(tabOldP[ i ],'\t');
if(t1[3]!=t2[3]){ //贴子有新的回复
forms=showPostChildWinform(newstr,false);
table.push(tabform,forms);
}
}
win.delay(1);
}
}
if(table.count(tabNewP)){
/*调试用
for(i,newstr in tabNewP){
forms=showPostChildWinform(newstr,false);
table.push(tabform,forms);
break ;
}
*/
tabOldP=tabNewP;
thread.set("tabOldP",tabOldP);
}
closeChildForm(tabform);
}
showPostChildWinform=function(str,state){//桌面右下脚本弹出提示窗口
//io.print(str)
var x,y,w,h=getChildwindow(); //弹窗的坐标
var t=string.split(str,'\t');
var subject=t[1] or "";
subject="<font color=green>标题:</font>" + subject + "<br>"
var author=t[2] or "";
var nums=t[3] or "";
var lastposturl=t[4] or "";
var postime=t[5] or "";
var lastby=t[6] or "";
var title="";
var bodystr=subject;
var downurl=_bbsUrl + string.replace(lastposturl,"@#lastpost","");
if(state){
title=author + "发表新的贴子";
bodystr += "<font color=green>" + author + "问:</font>"
}
else {
title=lastby + "回复贴子";
bodystr += "<font color=green>" + lastby + "回复:</font>"
}
http=inet.whttp();
html,errmsg=http.down(downurl);
http.close();
if(html){
html=string.fromto(html,65001,0);
if(state){
bodystr += string.match(html,"\<div id=""firstpost""\>(.*?)\</div\>") or "";
}
else {
bodystr += string.match(html,"\<div id=""message.+\<div id=""message.+?\>(.*?)\</div\>") orstring.match(html,"\<div id=""message.+?\>(.*?)\</div\>") or "";
}
}
var wbchild=win.form.loadcode($"\res\child.aau");
wbchild.show(false);
if(x){::MoveWindow(wbchild.hwnd,x,y,w,h,0x1);} //移到屏幕右下角
wbchild.text=title;
var wb=web.form(wbchild.st_web,0x4/*_UIFLAG_NO3DBORDER*/ ,0x40000000/*_DLCTL_SILENT*/ );
wb.external = {
aauto_func = function( ){
thread.set("addWebPageUrl",_bbsUrl + lastposturl )
hwnd=thread.get("winformHwnd")
::ShowWindow(hwnd,0x5/*_SW_SHOW*/)
}
}
wb.write(_wbchildHtml);
wb.getEle("bodystr").innerHTML=bodystr;
wbchild.show(true);
return wbchild;
}
closeChildForm=function(tabform){ //等待30秒 关闭所有弹出窗体
if(#tabform){
for(i=30;0;-1){
var th=tabform;
for(k,form in tabform){
if(!::IsWindow(form.hwnd)){
table.remove(th,k);
}
else {
form.st_web.web.getEle("sec").innerHTML= i + "秒后关闭"
}
}
if(!#th){break ;}
win.delay(1000);
}
for(i,form in tabform){//关闭所有弹出窗体
if(::IsWindow(form.hwnd)){form.close();}
}
}
//io.print("关闭所有弹出窗体")
}
getChildwindow=function(){//返回设置弹窗的坐标
var hwnd=win.find("Shell_TrayWnd");//查找任务栏句柄
if(hwnd){
var rc=::RECT();
::GetWindowRect(hwnd,rc)
w=245;h=145; //弹窗大小
x=rc.right - w - 25;
y=rc.top - h;
return x,y,w,h;
}
}
begin
_wbchildHtml=/*
<html><head><style>
body{cursor:default;font:12;font-family: "宋体"}table{font:12;font-family: "宋体"}
</style></head>
<body bgcolor="#cde9f7"><table width="200px" bgcolor="#cde9f7"onClick="external.aauto_func();">
<tr>
<td align="right"><span id="sec"></span> <font color="#0000FF">查看</font></td>
</tr>
<tr>
<td align="left" id="bodystr"> </td>
</tr>
</table>
</body>
</html>
*/
end;
searchNewPost();
thread.stop();
}
//////////////////监测新贴处理结束///////////////////////
/*}}*/