Skip to content

Commit

Permalink
优化RSS相关细节
Browse files Browse the repository at this point in the history
  • Loading branch information
easychen committed Aug 9, 2022
1 parent bc6cf4f commit b95b06d
Show file tree
Hide file tree
Showing 17 changed files with 147 additions and 67 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@

## 最新版本

- 插件·Chrome/Edge:2022.08.01.15.59 [下载](ckc.zip) ([Github下载地址,无需注册](https://github.com/easychen/checkchan-dist/raw/master/ckc.zip))
- Docker镜像(云端+远程桌面二合一):2022.08.01.15.50 [Docker Hub](https://hub.docker.com/repository/docker/easychen/checkchan)
- 文档:2022.08.01.15.59
- 插件·Chrome/Edge:2022.08.10.01.22 [下载](ckc.zip) ([Github下载地址,无需注册](https://github.com/easychen/checkchan-dist/raw/master/ckc.zip))
- Docker镜像(云端+远程桌面二合一):2022.08.10.00.19 [Docker Hub](https://hub.docker.com/repository/docker/easychen/checkchan)
- 文档:2022.08.10.01.22
- 更新日志:[GitHub](https://github.com/easychen/checkchan-dist/commits/main)
- 生态:RSSHub浏览器插件整合版([源码](https://github.com/easychen/RSSHub-Radar-with-checkchan) | [下载](https://github.com/easychen/RSSHub-Radar-with-checkchan/releases/download/main/1.7.0.with-checkchan.zip)

Expand Down
2 changes: 1 addition & 1 deletion build.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
"2022.08.01.15.59"
"2022.08.10.01.22"
Binary file modified ckc.zip
Binary file not shown.
2 changes: 1 addition & 1 deletion docker.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
"2022.08.01.15.50"
"2022.08.10.00.19"
13 changes: 7 additions & 6 deletions docker/api/cron.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ for( const item of to_checks )
let check_content = "";
let check_html = "";
let check_link = "";
let check_data = "";

logit("checking..."+item.title, dayjs().format('YYYY-MM-DD HH:mm:ss'));

Expand All @@ -65,11 +66,12 @@ for( const item of to_checks )
check_content = ret.value;

// 添加正则替换
if( item.replace_from_regex && item.replace_from_regex ) check_content = check_content.replace( new RegExp(item.replace_from_regex), item.replace_to_regex );
if( item.replace_from_regex && item.replace_to_regex ) check_content = check_content.replace( new RegExp(item.replace_from_regex), item.replace_to_regex );


if( ret.html ) check_html = ret.html;
if( ret.link ) check_link = ret.link;
if( ret.data ) check_data = ret.data;
check_status = 1;

}
Expand All @@ -87,7 +89,7 @@ for( const item of to_checks )
if( retry_times >= item.retry )
{
// 发送通知
await send_notify( '监测点['+item.title+']多次重试失败', "已暂停执行,请检查登录状态或页面结构变动。点击任务的监测按钮可以解除暂停\r\n\r\n[点此查看]("+item.url+")" , item.sendkey, item.send_channel||-1);
await send_notify( '监测任务['+item.title+']多次重试失败', "已暂停执行,请检查登录状态或页面结构变动。点击任务的监测按钮可以解除暂停\r\n\r\n[点此查看]("+item.url+")" , item.sendkey, item.send_channel||-1);
}
check_update_field( item.id, 'retry_times', retry_times+1, json_data );

Expand Down Expand Up @@ -138,7 +140,6 @@ for( const item of to_checks )

if( item.compare_value == '*上次监测返回值*' ) the_value = last_content;


if( item.compare_op == 'ne' && !(check_content != the_value)) can_send_notice = false;

if( item.compare_op == 'eq' && !(check_content == the_value)) can_send_notice = false;
Expand All @@ -163,11 +164,11 @@ for( const item of to_checks )
{
logit( '已发送通知' );

await do_webhook( item.id, item.url, check_content, check_html, check_link || item.page || item.url );
await do_webhook( item.id, item.url, check_content, check_html, check_link || item.page || item.url, check_data );

if( item.sendkey )
{
const title = '监测点['+item.title+']有新通知';
const title = '监测任务['+item.title+']有新通知';

let desp = short(check_content,50) + (last_content && item.when == 'change' ? ('←' + short(last_content,50)):"");

Expand All @@ -186,7 +187,7 @@ for( const item of to_checks )
}
}

// const title = check_content.length > 50 ? '监测点['+item.title+']有新通知' : ( '监测点['+item.title+']有新通知: ' + check_content + (item.last_content ? ('←' + item.last_content):"") );
// const title = check_content.length > 50 ? '监测任务['+item.title+']有新通知' : ( '监测任务['+item.title+']有新通知: ' + check_content + (item.last_content ? ('←' + item.last_content):"") );

// const desp = check_content.length > 50 ? (check_html ? to_markdown(check_html) : check_content) : check_content + (item.last_content ? ('←' + item.last_content):"") ;

Expand Down
15 changes: 8 additions & 7 deletions docker/api/func.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ exports.get_cookies = () =>
return json_data.cookies;
}

exports.do_webhook = async( id, url, value, html, link ) =>
exports.do_webhook = async( id, url, value, html, link, data ) =>
{
// 因为webhook的内容更多,所以不能放到 show_notice 里边处理,这里单独处理
if( process.env.WEBHOOK_URL )
Expand All @@ -186,6 +186,7 @@ exports.do_webhook = async( id, url, value, html, link ) =>
form.append( 'value',value );
form.append( 'html',html );
form.append( 'link',link );
form.append( 'data',data );

try {
const response = await fetch( process.env.WEBHOOK_URL , {
Expand Down Expand Up @@ -335,7 +336,7 @@ async function monitor_rss(url,timeout=10000)

async function monitor_dom_low(item, cookies)
{
const { url, path, delay, ignore_path,click_path,scroll_down } = item;
const { url, path, delay, ignore_path,click_path,data_path,scroll_down } = item;
console.log("in low dom");
try {
const response = await fetch( url, { signal: timeoutSignal(delay<1?10000:delay) } );
Expand Down Expand Up @@ -436,7 +437,7 @@ async function monitor_shell(item, cookies)

async function monitor_dom(item , cookies)
{
const { url, path, id, ignore_path,click_path,scroll_down } = item;
const { url, path, id, ignore_path,click_path,data_path,scroll_down } = item;
const delay = (parseInt(item.delay)||0)*1000;

console.log("in dom delay = ",delay);
Expand Down Expand Up @@ -513,7 +514,7 @@ async function monitor_dom(item , cookies)
await sleep(1000);
}

ret = await page.evaluate( async (path,browser_code,ignore_path,click_path,scroll_down ) => {
ret = await page.evaluate( async (path,browser_code,ignore_path,click_path,data_path,scroll_down ) => {

// 滚动的页面底部
if( scroll_down && parseInt(scroll_down) > 0 )
Expand Down Expand Up @@ -554,13 +555,13 @@ async function monitor_dom(item , cookies)
html += item.outerHTML ? item.outerHTML + "<br/>" : "";
}
return {html,text:path.indexOf(",") >= 0 ? texts.join("\n") :texts[0]||"","all":window.document.documentElement.innerHTML};
},path,browser_code,ignore_path,click_path,scroll_down);
},path,browser_code,ignore_path,click_path,data_path,scroll_down);

if( !ret )
{
console.log("sleep",1000*5);
await sleep(1000*5);
ret = await page.evaluate( async (path,browser_code,ignore_path,click_path,scroll_down) => {
ret = await page.evaluate( async (path,browser_code,ignore_path,click_path,data_path,scroll_down) => {
// 滚动的页面底部
if( scroll_down && parseInt(scroll_down) > 0 )
{
Expand Down Expand Up @@ -600,7 +601,7 @@ async function monitor_dom(item , cookies)
html += item.outerHTML ? item.outerHTML + "<br/>" : "";
}
return {html,text:path.indexOf(",") >= 0 ? texts.join("\n") :texts[0]||"","all":window.document.documentElement.innerHTML};
},path,browser_code,ignore_path,click_path,scroll_down);
},path,browser_code,ignore_path,click_path,data_path,scroll_down);

}
const { all,html, ...ret_short } = ret;
Expand Down
2 changes: 1 addition & 1 deletion docker/src/chrome_extension/_locales/zh_CN/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"message": "Check酱"
},
"appDesc": {
"message": "监控页面变动,并发送异动到微信。 Build.2022.08.01.15.59",
"message": "监控页面变动,并发送异动到微信。 Build.2022.08.10.01.22",
"description":"亦支持http status、json和rss监测。配合自架云端,关电脑后也能运行。"
}
}
10 changes: 5 additions & 5 deletions docker/src/chrome_extension/asset-manifest.json
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
{
"files": {
"main.css": "/static/css/main.0e42becb.chunk.css",
"main.js": "/static/js/main.82b4e77e.chunk.js",
"main.js": "/static/js/main.b985a5e4.chunk.js",
"runtime-main.js": "/static/js/runtime-main.17191aad.js",
"static/css/2.65280f5c.chunk.css": "/static/css/2.65280f5c.chunk.css",
"static/js/2.75a81e0e.chunk.js": "/static/js/2.75a81e0e.chunk.js",
"static/js/2.465e7d2f.chunk.js": "/static/js/2.465e7d2f.chunk.js",
"index.html": "/index.html",
"precache-manifest.0e5126865f008783ee373adbb649d9fd.js": "/precache-manifest.0e5126865f008783ee373adbb649d9fd.js",
"precache-manifest.0fd7de5395cfc4062a9344bfcc8632d5.js": "/precache-manifest.0fd7de5395cfc4062a9344bfcc8632d5.js",
"service-worker.js": "/service-worker.js",
"static/media/index.scss": "/static/media/icons-20.cef8cdbb.woff"
},
"entrypoints": [
"static/js/runtime-main.17191aad.js",
"static/css/2.65280f5c.chunk.css",
"static/js/2.75a81e0e.chunk.js",
"static/js/2.465e7d2f.chunk.js",
"static/css/main.0e42becb.chunk.css",
"static/js/main.82b4e77e.chunk.js"
"static/js/main.b985a5e4.chunk.js"
]
}
94 changes: 60 additions & 34 deletions docker/src/chrome_extension/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,39 +10,46 @@ async function show_inspector( tabid,inspector )
maxZIndex: 9999,
onClick: async (path) => {

var getFavicon = function(){
var favicon = undefined;
var nodeList = document.getElementsByTagName("link");
for (var i = 0; i < nodeList.length; i++)
{
if((nodeList[i].getAttribute("rel") == "icon")||(nodeList[i].getAttribute("rel") == "shortcut icon"))
if( window.confirm( "选择器为"+path+",是否转向到任务添加页面?" ) )
{
var getFavicon = function(){
var favicon = undefined;
var nodeList = document.getElementsByTagName("link");
for (var i = 0; i < nodeList.length; i++)
{
favicon = nodeList[i].getAttribute("href");
if((nodeList[i].getAttribute("rel") == "icon")||(nodeList[i].getAttribute("rel") == "shortcut icon"))
{
favicon = nodeList[i].getAttribute("href");
}
}
return favicon;
}
return favicon;
}

let icon_url = getFavicon() || "/favicon.ico";
if( icon_url.substring(0,4) != 'http' )
{
if( icon_url.substring(0,2) == '//' )
{
icon_url = window.location.protocol + icon_url;
}else

let icon_url = getFavicon() || "/favicon.ico";
if( icon_url.substring(0,4) != 'http' )
{
if( icon_url.substring(0,1) != '/' ) icon_url = window.origin+ '/' + icon_url;
else icon_url = window.origin + icon_url;
if( icon_url.substring(0,2) == '//' )
{
icon_url = window.location.protocol + icon_url;
}else
{
if( icon_url.substring(0,1) != '/' ) icon_url = window.origin+ '/' + icon_url;
else icon_url = window.origin + icon_url;
}
}

const url = 'index.html#/check/add?path='+encodeURIComponent(path)+'&title='+encodeURIComponent(window.document.title)+'&url='+encodeURIComponent(window.location.href)+'&icon='+encodeURIComponent(icon_url);



// 这里是 content script 同等权限,发送消息来调整网页
const ret = await chrome.runtime.sendMessage({action: "redirect","url":url,"tabid":tabid},);
console.log( "ret" , ret, inspector );
// 因为给元素注入了onclick,这里还是要reload才行
}else
{
window.location.reload();
}

const url = 'index.html#/check/add?path='+encodeURIComponent(path)+'&title='+encodeURIComponent(window.document.title)+'&url='+encodeURIComponent(window.location.href)+'&icon='+encodeURIComponent(icon_url);

// 这里是 content script 同等权限,发送消息来调整网页
const ret = await chrome.runtime.sendMessage({action: "redirect","url":url,"tabid":tabid},);
console.log( "ret" , ret, inspector );
// 因为给元素注入了onclick,这里还是要reload才行
window.location.reload();
}
});
inspector.enable();
Expand All @@ -54,7 +61,7 @@ async function show_inspector( tabid,inspector )
}

// javascript-obfuscator:disable
async function ck_get_content( path,delay=3000, ignore_path = "",click_path = "",scroll_down="0" )
async function ck_get_content( path,delay=3000, ignore_path = "",click_path = "",data_path="",scroll_down="0" )
{
function sleep(ms) {
return new Promise((resolve) => {
Expand All @@ -77,7 +84,7 @@ async function ck_get_content( path,delay=3000, ignore_path = "",click_path = ""
});
}

async function dom_mul_select( path, ignore_path = "",click_path = "",scroll_down="0" )
async function dom_mul_select( path, ignore_path = "",click_path = "",data_path="",scroll_down="0" )
{
// 滚动到页面底部
if( scroll_down && parseInt(scroll_down) > 0 )
Expand Down Expand Up @@ -113,17 +120,36 @@ async function ck_get_content( path,delay=3000, ignore_path = "",click_path = ""
for( let item of ret )
{
item.querySelectorAll("[src]").forEach( item => { if( item.src.substr(0,4) != 'http' ) { item.src = window.origin +( item.src.substr(0,1) == '/' ? item.src : '/'+ item.src ) } } );

item.querySelectorAll("[href]").forEach( item => { if( item.href.substr(0,4) != 'http' ) { item.href = window.origin +( item.href.substr(0,1) == '/' ? item.href : '/'+ item.href ) } } );

if( item.innerText ) texts.push(item.innerText?.trim());
html += item.outerHTML ? item.outerHTML + "<br/>" : "";
}
return {text:path.indexOf(",") >= 0 ? texts.join("\n") :texts[0]||"",html};

let data_ret = "";
if( data_path )
{
const data_path_items = data_path.split(",");
for( let item of data_path_items )
{
const data_items = window.document.querySelectorAll(item);
for( let data_item of data_items ){
if( data_item )
{
data_ret += data_item.outerHTML ? data_item.outerHTML+"<br/>" : "";
}
}

}
}
return {text:path.indexOf(",") >= 0 ? texts.join("\n") :texts[0]||"",html,"data":data_ret};
}

// await sleep(delay);
await dom_ready();
if( delay > 0 ) await sleep(delay);
const ret = await dom_mul_select(path,ignore_path,click_path,scroll_down);
const ret = await dom_mul_select(path,ignore_path,click_path,data_path,scroll_down);
// 直接提取
if( ret )
{
Expand All @@ -133,7 +159,7 @@ async function ck_get_content( path,delay=3000, ignore_path = "",click_path = ""
{
// 失败的话,先延迟再尝试一次
await sleep(3000);
const ret2 = await dom_mul_select(path,ignore_path,click_path,scroll_down);
const ret2 = await dom_mul_select(path,ignore_path,click_path,data_path,scroll_down);
if( ret2 )
{
return ret2;
Expand All @@ -142,7 +168,7 @@ async function ck_get_content( path,delay=3000, ignore_path = "",click_path = ""
{
await sleep(3000);
// 再来一次
const ret3 = await dom_mul_select(path,ignore_path,click_path,scroll_down);
const ret3 = await dom_mul_select(path,ignore_path,click_path,data_path,scroll_down);
if( ret3 ) return ret;
}

Expand Down Expand Up @@ -211,7 +237,7 @@ chrome.runtime.onMessage.addListener( (request, sender, sendResponse) => {
{
target: {tabId: tab.id},
function: ck_get_content,
args: [request.path,request.delay,request.ignore_path,request.click_path,request.scroll_down]
args: [request.path,request.delay,request.ignore_path,request.click_path,request.data_path,request.scroll_down]
});
// console.log( r );

Expand Down
2 changes: 1 addition & 1 deletion docker/src/chrome_extension/index.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<!doctype html><html lang="zh-cn"><head><meta charset="utf-8"/><link rel="icon" href="/logo.color.png"/><meta name="viewport" content="width=device-width,initial-scale=1"/><meta name="theme-color" content="#000000"/><meta name="description" content="web content monitor"/><link rel="apple-touch-icon" href="logo.color.png"/><link rel="manifest" href="/manifest.json"/><title>...</title><link rel="stylesheet" href="/tailwind.min.css"><link href="/static/css/2.65280f5c.chunk.css" rel="stylesheet"><link href="/static/css/main.0e42becb.chunk.css" rel="stylesheet"></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div><script src="/static/js/runtime-main.17191aad.js"></script><script src="/static/js/2.75a81e0e.chunk.js"></script><script src="/static/js/main.82b4e77e.chunk.js"></script></body></html>
<!doctype html><html lang="zh-cn"><head><meta charset="utf-8"/><link rel="icon" href="/logo.color.png"/><meta name="viewport" content="width=device-width,initial-scale=1"/><meta name="theme-color" content="#000000"/><meta name="description" content="web content monitor"/><link rel="apple-touch-icon" href="logo.color.png"/><link rel="manifest" href="/manifest.json"/><title>...</title><link rel="stylesheet" href="/tailwind.min.css"><link href="/static/css/2.65280f5c.chunk.css" rel="stylesheet"><link href="/static/css/main.0e42becb.chunk.css" rel="stylesheet"></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div><script src="/static/js/runtime-main.17191aad.js"></script><script src="/static/js/2.465e7d2f.chunk.js"></script><script src="/static/js/main.b985a5e4.chunk.js"></script></body></html>
2 changes: 1 addition & 1 deletion docker/src/chrome_extension/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"name": "__MSG_appTitle__",
"description": "__MSG_appDesc__",
"default_locale": "zh_CN",
"version": "0.9.5",
"version": "0.9.6",
"icons": {
"512": "logo.color.png"
},
Expand Down
Loading

0 comments on commit b95b06d

Please sign in to comment.