这是一片没有diao用的文章,没有任何技术含量。
看小说,因为太多广告,不过路由器拦截了大部分广告,其实体验也还好,不过还是想着自己做一个在线阅读器。
在线阅读器采用的是web.form、以及jq取文本的方式,因为这样用网页也行,用文本阅读也行。
网页效果:
进入阅读模式效果:
直接将jq的规则写在右侧了,方便自己更改!
//import fonts.fontAwesome;
import win.ui;
import win.dlg.message;
import win.ui;
import win.ui.statusbar;
/*DSG{{*/
var winform = win.form(text="设置";right=1154;bottom=648;bgcolor=16777215)
winform.add(
button={cls="button";text="开启阅读模式";left=972;top=389;right=1100;bottom=427;dr=1;dt=1;z=8};
button2={cls="button";text="上一章";left=973;top=445;right=1101;bottom=483;dr=1;dt=1;z=12};
button3={cls="button";text="下一章";left=974;top=494;right=1102;bottom=532;dr=1;dt=1;z=13};
button4={cls="button";text="章节目录";left=974;top=542;right=1102;bottom=580;dr=1;dt=1;z=14};
combobox={cls="combobox";left=936;top=347;right=1134;bottom=371;dr=1;dt=1;edge=1;items={};mode="dropdownlist";z=21};
custom={cls="custom";text="自定义控件";left=5;top=30;right=915;bottom=617;db=1;dl=1;dr=1;dt=1;z=3};
edit={cls="edit";text="Edit";left=3;top=1;right=893;bottom=24;dl=1;dr=1;dt=1;edge=1;multiline=1;z=4};
edit_baseurl={cls="edit";text="Edit";left=898;top=1;right=1149;bottom=24;dr=1;dt=1;edge=1;multiline=1;readonly=1;z=22};
edit_bt={cls="edit";text=".bookname > h1";left=934;top=74;right=1132;bottom=94;dr=1;dt=1;edge=1;z=7};
edit_content={cls="edit";text="#content";left=934;top=121;right=1132;bottom=141;dr=1;dt=1;edge=1;z=10};
edit_down={cls="edit";text=".bottem1>a:eq(3)";left=934;top=215;right=1132;bottom=235;dr=1;dt=1;edge=1;z=18};
edit_up={cls="edit";text=".bottem1>a:eq(1)";left=934;top=168;right=1132;bottom=188;dr=1;dt=1;edge=1;z=16};
edit_zhang={cls="edit";text=".bottem1>a:eq(2)";left=934;top=262;right=1132;bottom=282;dr=1;dt=1;edge=1;z=20};
groupbox={cls="groupbox";text="筛选规则";left=918;top=25;right=1154;bottom=625;db=1;dr=1;dt=1;edge=1;group=1;z=5};
lbTip={cls="static";left=63;top=523;right=695;bottom=572;db=1;dl=1;dr=1;transparent=1;z=2};
richedit={cls="richedit";text="RichEdit";left=6;top=87;right=911;bottom=622;autohscroll=false;bgcolor=16775913;db=1;dl=1;dr=1;dt=1;edge=1;font=LOGFONT(h=-35;name='微软雅黑');hide=1;multiline=1;readonly=1;vscroll=1;wrap=1;z=11};
static={cls="static";text="标题";left=933;top=51;right=1081;bottom=67;dr=1;dt=1;transparent=1;z=6};
static2={cls="static";text="正文规则";left=934;top=100;right=1082;bottom=116;dr=1;dt=1;transparent=1;z=9};
static3={cls="static";text="上一章";left=934;top=147;right=1082;bottom=163;dr=1;dt=1;transparent=1;z=15};
static4={cls="static";text="下一章规则:";left=934;top=194;right=1082;bottom=210;dr=1;dt=1;transparent=1;z=17};
static5={cls="static";text="章节目录规则:";left=934;top=241;right=1082;bottom=257;dr=1;dt=1;transparent=1;z=19};
static6={cls="static";text="切换站点:";left=934;top=325;right=1082;bottom=341;dr=1;dt=1;transparent=1;z=23};
static_title={cls="static";text="Static";left=6;top=32;right=911;bottom=88;align="center";bgcolor=10789024;center=1;color=8421376;dl=1;dr=1;dt=1;edge=1;font=LOGFONT(h=-56;name='微软雅黑');hide=1;z=1}
)
/*}}*/
import console;
import web.json;
import config;
winform.bindConfig( config.winform,{
edit = "text";
static = "text";
richedit = "text";
} );
web_config = {
{
url="https://www.xbiquwx.la/";
title = ".bookname > h1";
content = "#content";
up = ".bottem1>a:eq(1)";
down = ".bottem1>a:eq(3)";
zhang = ".bottem1>a:eq(2)";
};
{
url="https://www.bige7.com/";
title = ".content > h1";
content = "#chaptercontent";
up = ".Readpage.pagedown>a:eq(0)";
down = ".Readpage.pagedown>a:eq(2)";
zhang = ".Readpage.pagedown>a:eq(1)";
};
}
for(i=1;#web_config;1){
winform.combobox.add(web_config[i]['url']);
}
if(string.startWith(winform.edit.text,"http")=false){
winform.edit.text = "https://www.xbiquwx.la/";
}
bar = win.ui.statusbar( winform );
bar.addItem("", 200/*宽度*/)
bar.addItem("", 250/*宽度*/)
bar.addItem("", 250/*宽度*/)
bar.addItem("", 250/*宽度*/)
var mode_read = false;
var txt_article = {
web_url = "";
url="";
title="";
content="";
up_url="";
down_url="";
zhang_url="";
}
import web.blink.form;
var wb =web.blink.form(winform.custom);
var get_content = function(rule=""){
if(rule="")return false;
var bt = wb.jQuery(rule);
var html = bt.html();
if(html){
html = ..string.replace(html,"@<br>",'\r\n ')
html = ..string.replace(html,"@<br/>",'\r\n ')
html = ..string.replace(html,"@ ",' ')
return true, bt.text(),html;
}else{
return false;
}
}
var get_href = function(rule=""){
if(rule="")return false;
var bt = wb.jQuery(rule);
return true,bt.attr('href');
}
var get_txt = function(){
res,txt = get_content(winform.edit_bt.text);
if(res){
txt_article.title = txt;
}else {
txt_article.title = "";
}
res,txt,html = get_content(winform.edit_content.text);
if(res){
txt_article.content = html;
}
res,txt = get_href(winform.edit_up.text);
if(res){
txt_article.up_url = txt;
}
res,txt = get_href(winform.edit_down.text);
if(res){
txt_article.down_url = txt;
}
res,txt = get_href(winform.edit_zhang.text);
if(res){
txt_article.zhang_url = txt;
}
}
var dis_txt = function(){
if(txt_article.title)bar.setText(tostring(txt_article.title),1);
if(txt_article.url)bar.setText(tostring(txt_article.url),2);
if(txt_article.up_url)bar.setText(tostring(txt_article.up_url),3);
if(txt_article.down_url)bar.setText(tostring(txt_article.down_url),4);
import preg;
var regex = preg("(http[s]?://[\w\.]*)");
txt_article.web_url = regex.match(txt_article.url);
winform.edit_baseurl.text = txt_article.web_url;
//显示标题
winform.static_title.text = txt_article.title;
winform.richedit.text = "";
text = ..string.splitEx(txt_article.content,"。 ")
for(i=1;#text;1){
winform.richedit.appendText(text[i]+'。\r\n');
}
}
wb.go(winform.edit.text)
winform.edit.onOk = function(){
wb.go(winform.edit.text)
return true;
}
wb.onDocumentReady = function(pDisp,url) {
txt_article.url = wb.location;
winform.edit.text = wb.location;
get_txt();
if(txt_article.title?txt_article.title!=""){
dis_txt();
winform.msgInfo("完成加载章节:" + txt_article.title,800)
}
}
winform.button.oncommand = function(id,event){
if(mode_read){
mode_read = false;
winform.custom.hide = false;
winform.richedit.hide = true;
winform.static_title.hide = true;
owner.text = "开启阅读模式"
}else{
mode_read = true;
winform.custom.hide = true;
winform.richedit.hide = false;
winform.static_title.hide = false;
owner.text ="查看网页模式"
dis_txt()
}
}
winform.next = function(){
if(!txt_article.down_url){
return ;
}
if(string.startWith(txt_article.down_url,"http")){
url = txt_article.down_url;
}else{
url = txt_article.web_url + txt_article.down_url;
}
wb.go(url);
winform.msgInfo("请稍等 更新站点:" + url,1000)
}
winform.before = function(){
if(!txt_article.up_url){
return ;
}
if(string.startWith(txt_article.up_url,"http")){
url = txt_article.up_url;
}else{
url = txt_article.web_url + txt_article.up_url;
}
wb.go(url);
winform.msgInfo("请稍等 更新站点:" + url,1000)
}
winform.button2.oncommand = function(id,event){
winform.before();
}
winform.button3.oncommand = function(id,event){
winform.next()
}
var re_web = function(url){
mode_read = false;
winform.custom.hide = false;
winform.richedit.hide = true;
winform.static_title.hide = true;
winform.button4.text = "开启阅读模式"
wb.go(url)
};
winform.combobox.onListChange= function(){
var num = winform.combobox.selIndex;
winform.edit_bt.text = web_config[num]['title'];
winform.edit_content.text = web_config[num]['content'];
winform.edit_up.text = web_config[num]['up'];
winform.edit_down.text = web_config[num]['down'];
winform.edit_zhang.text = web_config[num]['zhang'];
winform.edit_baseurl.text = winform.combobox.selText;
re_web(winform.combobox.selText);
}
winform.button4.oncommand = function(id,event){
re_web(txt_article.zhang_url);
}
winform.show();
win.loopMessage();
return winform;