Skip to content

Commit

Permalink
RSS支持通过@语法设置返回哪篇文章
Browse files Browse the repository at this point in the history
  • Loading branch information
easychen committed Sep 17, 2022
1 parent 4152a54 commit e4a346d
Show file tree
Hide file tree
Showing 16 changed files with 121 additions and 29 deletions.
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@

## 最新版本

- 插件·Chrome/Edge:2022.09.06.22.57 [下载](ckc.zip) ([Github下载地址,无需注册](https://github.com/easychen/checkchan-dist/raw/master/ckc.zip))
- Docker镜像(云端+远程桌面二合一):2022.08.30.13.38 [Docker Hub](https://hub.docker.com/repository/docker/easychen/checkchan)
- 文档:2022.09.06.22.57
- 插件·Chrome/Edge:2022.09.17.21.32 [下载](ckc.zip) ([Github下载地址,无需注册](https://github.com/easychen/checkchan-dist/raw/master/ckc.zip))
- Docker镜像(云端+远程桌面二合一):2022.09.17.19.58 [Docker Hub](https://hub.docker.com/repository/docker/easychen/checkchan)
- 文档:2022.09.17.21.32
- 更新日志:[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 Expand Up @@ -186,6 +186,8 @@ checkchan://title=Server%E9%85%B1%E5%AE%98%E6%96%B9%E7%BD%91%E7%AB%99%E7%8A%B6%E

但如果这些元素不属于同一个父节点,那么以上方法会失效。这里添加了一个 selector@n 的语法,让我们可以从 Selector 返回的数组中指定某一个元素。如 `.booklist .item@0` 将返回 `document.querySelectorAll(.booklist .item)[0]`

> @语法除了使用在DOM selector上,还可以用来指定 RSS 监测结果。默认情况下,RSS 将返回整个Feed的第一篇文章,你可以用过在 Feed url 后边添加 @1 ,将其指定为监测第二篇文章(依然是从0开始计数)。
#### 通过%获得元素属性

Selector的最下一级返回一个元素,但有时候我们需要监测这个元素的某个属性值。比如监测一个链接的`href`。为了解决这个问题,我们扩展了 selector 语法,让用户可以通过 element%attribute 的方式来获取元素的某个属性值。如:`article#post-180 > div > div > p > a%href`。当 `%``@` 同时使用时, `%` 应紧跟元素后,如:`article#post-180 > div > div > p > a%href@0`
Expand Down
2 changes: 2 additions & 0 deletions README.tpl.md
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,8 @@ checkchan://title=Server%E9%85%B1%E5%AE%98%E6%96%B9%E7%BD%91%E7%AB%99%E7%8A%B6%E

但如果这些元素不属于同一个父节点,那么以上方法会失效。这里添加了一个 selector@n 的语法,让我们可以从 Selector 返回的数组中指定某一个元素。如 `.booklist .item@0` 将返回 `document.querySelectorAll(.booklist .item)[0]`

> @语法除了使用在DOM selector上,还可以用来指定 RSS 监测结果。默认情况下,RSS 将返回整个Feed的第一篇文章,你可以用过在 Feed url 后边添加 @1 ,将其指定为监测第二篇文章(依然是从0开始计数)。
#### 通过%获得元素属性

Selector的最下一级返回一个元素,但有时候我们需要监测这个元素的某个属性值。比如监测一个链接的`href`。为了解决这个问题,我们扩展了 selector 语法,让用户可以通过 element%attribute 的方式来获取元素的某个属性值。如:`article#post-180 > div > div > p > a%href`。当 `%``@` 同时使用时, `%` 应紧跟元素后,如:`article#post-180 > div > div > p > a%href@0`
Expand Down
2 changes: 1 addition & 1 deletion build.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
"2022.09.06.22.57"
"2022.09.17.21.32"
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.30.13.38"
"2022.09.17.19.58"
48 changes: 39 additions & 9 deletions docker/api/func.js
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,8 @@ exports.monitor_auto = async ( item, cookies ) =>
break;
case 'rss':
ret = await monitor_rss( item.url, (parseInt(item.delay)||0)*1000 );
return {status:!!(ret&&ret[item.rss_field]),value:ret[item.rss_field]||"",link:ret.link,type:item.type};
if( ret && ret['content'] ) ret['description'] = ret['content'];
return {status:!!(ret&&ret[item.rss_field]),value:ret[item.rss_field]||"",html:ret['content']||"",link:ret.link,type:item.type};
break;
case 'json':
// 特别注意,云端的json监测包含delay参数
Expand All @@ -269,7 +270,7 @@ exports.monitor_auto = async ( item, cookies ) =>

async function monitor_get(url,timeout=10000)
{
const response = await fetch( url, { signal: timeoutSignal(timeout<1?10000:timeout) } );
const response = await fetch( compile_url(url), { signal: timeoutSignal(timeout<1?10000:timeout) } );
return response.status;
}

Expand Down Expand Up @@ -305,7 +306,7 @@ async function monitor_json(url, query, header=false, body_string=false, format
if( headers ) opt.headers = headers;
if( method == 'POST' ) opt.body = body;

const response = await fetch( url, opt );
const response = await fetch( compile_url(url), opt );
const data = await response.json();
const ret = jsonQuery( query ,{data} );
console.log( ret );
Expand All @@ -330,9 +331,23 @@ async function monitor_json(url, query, header=false, body_string=false, format
// rssParser
async function monitor_rss(url,timeout=10000)
{
let index = 0;
let feed = compile_url(url);
let all = true;
let m;

if( ( m = /^(http(s)*:\/\/.+)@([0-9]+)$/is.exec(url)) !== null )
{
index = parseInt(m[3]);
feed = m[1];
all = false;
}

const parser = new rssParser({ timeout });
const site = await parser.parseURL( url );
const ret = site.items[0]||false;
const site = await parser.parseURL( feed );
const ret = site.items[index];
if( all ) ret.content = site.items.map( item => item.content ).join("\r\n<hr/>\r\n");

return ret;
}

Expand Down Expand Up @@ -380,11 +395,11 @@ async function monitor_dom_low(item, cookies)

['src','href'].forEach( field => {

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

if( item[field] )
{
if( item[field].substr(0,4) != 'http' ) { item[field] = new URL(url).origin +( item[field].substr(0,1) == '/' ? item[field] : '/'+ item[field] ) }
if( item[field]?.substr(0,4) != 'http' ) { item[field] = new URL(url).origin +( item[field]?.substr(0,1) == '/' ? item[field] : '/'+ item[field] ) }
};
} );

Expand Down Expand Up @@ -439,7 +454,7 @@ async function monitor_shell(item, cookies)

const result = await spawnAsync( command, [shell_file], {
env: {
'URL':url,
'URL':compile_url(url),
[cookie_name]:cookie_string,
...process.env,
}
Expand All @@ -454,7 +469,8 @@ async function monitor_shell(item, cookies)

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

console.log("in dom delay = ",delay);
Expand Down Expand Up @@ -726,3 +742,17 @@ function build_cookie_string( cookie_array )
return ret.length > 0 ? ret.join('; ') : false;
}

function compile_url( url )
{
// replace date in url
// {$_CKC_DATE}
const values = {};
values['date'] = dayjs().format('DD');
values['year'] = dayjs().format('YYYY');
values['month'] = dayjs().format('MM');
values['hour'] = dayjs().format('HH');
values['minute'] = dayjs().format('mm');
values['day_7'] = dayjs().subtract(7,'day').format('YYYY-MM-DD');
return url.replace( /\{\$_CKC_(.+?)}/isg, (m, g1,) => values[g1.toLowerCase()] || g1 );
}

2 changes: 1 addition & 1 deletion docker/src/chrome_extension/_locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"message": "Check酱"
},
"appDesc": {
"message": "监控页面变动,并发送异动到微信。 Build.2022.09.06.22.57",
"message": "监控页面变动,并发送异动到微信。 Build.2022.09.17.21.32",
"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.d6d007ad.chunk.css",
"main.js": "/static/js/main.f24d7747.chunk.js",
"main.js": "/static/js/main.47f9663c.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.6a38eae4.chunk.js": "/static/js/2.6a38eae4.chunk.js",
"static/js/2.5d1706aa.chunk.js": "/static/js/2.5d1706aa.chunk.js",
"index.html": "/index.html",
"precache-manifest.56bae04b2136531cbdc3594c456e6893.js": "/precache-manifest.56bae04b2136531cbdc3594c456e6893.js",
"precache-manifest.e71aa6692d1b8dd6d80e9d6dfcf34d56.js": "/precache-manifest.e71aa6692d1b8dd6d80e9d6dfcf34d56.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.6a38eae4.chunk.js",
"static/js/2.5d1706aa.chunk.js",
"static/css/main.d6d007ad.chunk.css",
"static/js/main.f24d7747.chunk.js"
"static/js/main.47f9663c.chunk.js"
]
}
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.d6d007ad.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.6a38eae4.chunk.js"></script><script src="/static/js/main.f24d7747.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.d6d007ad.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.5d1706aa.chunk.js"></script><script src="/static/js/main.47f9663c.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": "en",
"version": "0.9.12",
"version": "0.9.16",
"icons": {
"512": "logo.color.png"
},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
self.__precacheManifest = (self.__precacheManifest || []).concat([
{
"revision": "619e8ab0b190e3acfc71e6e7f31e8512",
"url": "/index.html"
},
{
"revision": "601d2dcdd2de48858de0",
"url": "/static/css/2.65280f5c.chunk.css"
},
{
"revision": "09b18ba31e5680fbefe1",
"url": "/static/css/main.d6d007ad.chunk.css"
},
{
"revision": "601d2dcdd2de48858de0",
"url": "/static/js/2.5d1706aa.chunk.js"
},
{
"revision": "09b18ba31e5680fbefe1",
"url": "/static/js/main.47f9663c.chunk.js"
},
{
"revision": "4d30565b04f5f2725c56",
"url": "/static/js/runtime-main.17191aad.js"
},
{
"revision": "05f1cdadfe476395f60e233b15c22155",
"url": "/static/media/icons-16.05f1cdad.eot"
},
{
"revision": "3c1c220e7a18286503fb431c7a7fe183",
"url": "/static/media/icons-16.3c1c220e.woff"
},
{
"revision": "3cde8748332d1de6b1ae1c2dc5850754",
"url": "/static/media/icons-16.3cde8748.ttf"
},
{
"revision": "0a5c76518a68c185baa2c6744456918c",
"url": "/static/media/icons-20.0a5c7651.eot"
},
{
"revision": "51ec31f302d0072808e1f83f85fea4cd",
"url": "/static/media/icons-20.51ec31f3.ttf"
},
{
"revision": "cef8cdbb9d0ba82e6e19fb0eeba2ac3d",
"url": "/static/media/icons-20.cef8cdbb.woff"
}
]);
2 changes: 1 addition & 1 deletion docker/src/chrome_extension/service-worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
importScripts("https://storage.googleapis.com/workbox-cdn/releases/4.3.1/workbox-sw.js");

importScripts(
"/precache-manifest.56bae04b2136531cbdc3594c456e6893.js"
"/precache-manifest.e71aa6692d1b8dd6d80e9d6dfcf34d56.js"
);

self.addEventListener('message', (event) => {
Expand Down
1 change: 1 addition & 0 deletions docker/src/chrome_extension/static/js/2.5d1706aa.chunk.js

Large diffs are not rendered by default.

Large diffs are not rendered by default.

9 changes: 6 additions & 3 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ <h2>开源声明</h2>
</ol>
<h2>最新版本</h2>
<ul>
<li>插件·Chrome/Edge:2022.09.06.22.57 <a href="ckc.zip">下载</a> (<a href="https://github.com/easychen/checkchan-dist/raw/master/ckc.zip">Github下载地址,无需注册</a>)</li>
<li>Docker镜像(云端+远程桌面二合一):2022.08.30.13.38 <a href="https://hub.docker.com/repository/docker/easychen/checkchan" rel="nofollow">Docker Hub</a></li>
<li>文档:2022.09.06.22.57</li>
<li>插件·Chrome/Edge:2022.09.17.21.32 <a href="ckc.zip">下载</a> (<a href="https://github.com/easychen/checkchan-dist/raw/master/ckc.zip">Github下载地址,无需注册</a>)</li>
<li>Docker镜像(云端+远程桌面二合一):2022.09.17.19.58 <a href="https://hub.docker.com/repository/docker/easychen/checkchan" rel="nofollow">Docker Hub</a></li>
<li>文档:2022.09.17.21.32</li>
<li>更新日志:<a href="https://github.com/easychen/checkchan-dist/commits/main">GitHub</a></li>
<li>生态:RSSHub浏览器插件整合版(<a href="https://github.com/easychen/RSSHub-Radar-with-checkchan">源码</a> | <a href="https://github.com/easychen/RSSHub-Radar-with-checkchan/releases/download/main/1.7.0.with-checkchan.zip">下载</a></li>
</ul>
Expand Down Expand Up @@ -126,6 +126,9 @@ <h3>Selector 扩展语法</h3>
<h4>通过@指定数组元素</h4>
<p>最新的版本支持了一个Selector扩展语法:由于底层通过 <code class="notranslate">document.querySelectorAll</code> 实现,因此会返回匹配的全部元素于一个数组。当这些元素属于同一个父节点我们可以用 <code class="notranslate">:nth-of-type(1)</code> 或者 <code class="notranslate">:nth-child(1)</code>来指定数组中的某一项。</p>
<p>但如果这些元素不属于同一个父节点,那么以上方法会失效。这里添加了一个 selector@n 的语法,让我们可以从 Selector 返回的数组中指定某一个元素。如 <code class="notranslate">.booklist .item@0</code> 将返回 <code class="notranslate">document.querySelectorAll(.booklist .item)[0]</code></p>
<blockquote>
<p>@语法除了使用在DOM selector上,还可以用来指定 RSS 监测结果。默认情况下,RSS 将返回整个Feed的第一篇文章,你可以用过在 Feed url 后边添加 <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/1/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/1">@1</a> ,将其指定为监测第二篇文章(依然是从0开始计数)。</p>
</blockquote>
<h4>通过%获得元素属性</h4>
<p>Selector的最下一级返回一个元素,但有时候我们需要监测这个元素的某个属性值。比如监测一个链接的<code class="notranslate">href</code>。为了解决这个问题,我们扩展了 selector 语法,让用户可以通过 element%attribute 的方式来获取元素的某个属性值。如:<code class="notranslate">article#post-180 &gt; div &gt; div &gt; p &gt; a%href</code>。当 <code class="notranslate">%</code><code class="notranslate">@</code> 同时使用时, <code class="notranslate">%</code> 应紧跟元素后,如:<code class="notranslate">article#post-180 &gt; div &gt; div &gt; p &gt; a%href@0</code></p>
<h3>日志查看和错误定位</h3>
Expand Down
9 changes: 6 additions & 3 deletions readme.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ <h2>开源声明</h2>
</ol>
<h2>最新版本</h2>
<ul>
<li>插件·Chrome/Edge:2022.09.06.22.57 <a href="ckc.zip">下载</a> (<a href="https://github.com/easychen/checkchan-dist/raw/master/ckc.zip">Github下载地址,无需注册</a>)</li>
<li>Docker镜像(云端+远程桌面二合一):2022.08.30.13.38 <a href="https://hub.docker.com/repository/docker/easychen/checkchan" rel="nofollow">Docker Hub</a></li>
<li>文档:2022.09.06.22.57</li>
<li>插件·Chrome/Edge:2022.09.17.21.32 <a href="ckc.zip">下载</a> (<a href="https://github.com/easychen/checkchan-dist/raw/master/ckc.zip">Github下载地址,无需注册</a>)</li>
<li>Docker镜像(云端+远程桌面二合一):2022.09.17.19.58 <a href="https://hub.docker.com/repository/docker/easychen/checkchan" rel="nofollow">Docker Hub</a></li>
<li>文档:2022.09.17.21.32</li>
<li>更新日志:<a href="https://github.com/easychen/checkchan-dist/commits/main">GitHub</a></li>
<li>生态:RSSHub浏览器插件整合版(<a href="https://github.com/easychen/RSSHub-Radar-with-checkchan">源码</a> | <a href="https://github.com/easychen/RSSHub-Radar-with-checkchan/releases/download/main/1.7.0.with-checkchan.zip">下载</a></li>
</ul>
Expand Down Expand Up @@ -115,6 +115,9 @@ <h3>Selector 扩展语法</h3>
<h4>通过@指定数组元素</h4>
<p>最新的版本支持了一个Selector扩展语法:由于底层通过 <code class="notranslate">document.querySelectorAll</code> 实现,因此会返回匹配的全部元素于一个数组。当这些元素属于同一个父节点我们可以用 <code class="notranslate">:nth-of-type(1)</code> 或者 <code class="notranslate">:nth-child(1)</code>来指定数组中的某一项。</p>
<p>但如果这些元素不属于同一个父节点,那么以上方法会失效。这里添加了一个 selector@n 的语法,让我们可以从 Selector 返回的数组中指定某一个元素。如 <code class="notranslate">.booklist .item@0</code> 将返回 <code class="notranslate">document.querySelectorAll(.booklist .item)[0]</code></p>
<blockquote>
<p>@语法除了使用在DOM selector上,还可以用来指定 RSS 监测结果。默认情况下,RSS 将返回整个Feed的第一篇文章,你可以用过在 Feed url 后边添加 <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/1/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/1">@1</a> ,将其指定为监测第二篇文章(依然是从0开始计数)。</p>
</blockquote>
<h4>通过%获得元素属性</h4>
<p>Selector的最下一级返回一个元素,但有时候我们需要监测这个元素的某个属性值。比如监测一个链接的<code class="notranslate">href</code>。为了解决这个问题,我们扩展了 selector 语法,让用户可以通过 element%attribute 的方式来获取元素的某个属性值。如:<code class="notranslate">article#post-180 &gt; div &gt; div &gt; p &gt; a%href</code>。当 <code class="notranslate">%</code><code class="notranslate">@</code> 同时使用时, <code class="notranslate">%</code> 应紧跟元素后,如:<code class="notranslate">article#post-180 &gt; div &gt; div &gt; p &gt; a%href@0</code></p>
<h3>日志查看和错误定位</h3>
Expand Down

0 comments on commit e4a346d

Please sign in to comment.