()
| 2635 | } |
| 2636 | // 自定义翻页规则 |
| 2637 | function customRules() { |
| 2638 | if (getCSS('#Autopage_customRules')) return |
| 2639 | |
| 2640 | let customRules = customStringify(GM_getValue('menu_customRules', {})) |
| 2641 | if (customRules == '{}') customRules = '{\n \n}'; // 引导用户插入规则的位置 |
| 2642 | let _html = `<style>* {font-family: system-ui !important;}</style><div style="left: 0; right: 0; top: 0; bottom: 0; width: 100%; height: 100%; margin: auto; padding: 25px 10px 10px 10px; position: fixed; opacity: 0.95; z-index: 9999999; background-color: #eee; color: #222; font-size: 14px; overflow: scroll; text-align: left;-webkit-touch-callout: text !important;-webkit-user-select: text !important;-khtml-user-select: text !important;-moz-user-select: text !important;-ms-user-select: text !important;user-select: text !important;"> |
| 2643 | <h3 style="font-size: 22px;overflow: hidden;text-overflow: ellipsis;white-space: nowrap;"><strong># 自定义翻页规则(优先级最高,会覆盖同名的外置翻页规则)-【将规则插入默认的 <code>{ }</code> 中间】</strong></h3> |
| 2644 | <details><summary style="cursor: pointer;overflow: hidden;text-overflow: ellipsis;white-space: nowrap;"><kbd><strong>「 点击展开 查看规则示例 」(为了避免需要的时候还要找,我干脆把常用规则都一股脑塞进去了)</strong></kbd></summary> |
| 2645 | <ul style="list-style: disc; margin-left: 35px;"> |
| 2646 | <li>翻页规则为 JSON 格式,因此大家需要多少<strong>了解一点 JSON 的基本格式</strong>(主要就是末尾逗号、转义、双引号等)。</li> |
| 2647 | <li>具体的翻页规则说明、示例,为了方便更新及补充,我都写到 <strong><a href="https://github.com/XIU2/UserScript/issues/176" target="_blank">Github Issues</a></strong> 里面了。</li> |
| 2648 | <li>脚本会自动格式化规则,因此<strong>无需手动缩进、换行</strong>,只需把规则<strong>插入默认的 { } 中间</strong>即可。</li> |
| 2649 | </ul> |
| 2650 | <pre class="notranslate" style="white-space: pre-wrap;user-select: auto;"> |
| 2651 | // 下面示例是把所有规则都塞进去了,但实际上大部分都用不上,大多数网站只需要像第一个 "aaa" 这样的规则(下方 示例一 中 url、replaceE、scrollD 均可按需省略): |
| 2652 | |
| 2653 | // "aaa" 是规则名,唯一,因为 自定义翻页规则 优先级最高,所以会覆盖同名的 外置翻页规则 |
| 2654 | // "host" 是域名,支持正则表达式(如 示例四),也可以像这样 示例三 那样写多个域名或正则表达式(当然也可以混用),如果省略,则默认匹配所有域名(会对所有域名匹配 url 规则判断,可以当成一个简单的外置/自定义通用规则的方案) |
| 2655 | // "url" 是用来控制哪些网站中页面适用该规则,省略后代表该规则应用于全站(如果不知道写什么,那么就写 return fun.isPager() 这样脚本会默认自动匹配当前网站下存在 nextL 及 pageE 元素的网页,大部分网站是没问题的,如果改为匹配 replaceE 或者其他组合,那么请去上面的 Github Issues 里的 内置函数 中查看具体使用方法;另外,url 规则中可通过操作 rule 这个对象变量来修改当前网页实际应用的规则,如 rule.pager.pageE='#a' 具体示例也见 Github Issues 里) |
| 2656 | |
| 2657 | // "nextL" 是用来指定含有下一页地址的元素选择器(CSS 或 XPath 都行,一般都是 <a> 元素) |
| 2658 | // "pageE" 是指定要从下一页获取的元素选择器(也就是网页主体内容),并将其插入当前网页中同样元素的末尾 |
| 2659 | // "replaceE" 用于将当前网页中的页码元素替换为下一页的页码元素选择器(这样才能无限翻页下去),省略后将会自动判断是替换 nextL 元素自身还是 nextL 元素的父元素(当 nextL 元素后面或前面有其自身 <a> 元素的相邻兄弟元素时脚本会替换其父元素,反之没有相邻兄弟元素则替换其自身,仅限模式1/3/6,且 "js;" 开头的 nextL 规则除外),值为空 "" 时则完全不替换 |
| 2660 | // "scrollD" 是用来指定触发翻页的滚动条与底部之间的距离,当滚动条底部距离网页底部之间的距离等于或小于该值时,将触发翻页,因此值越大就越早触发翻页,访问速度慢的网站需要调大,可省略(记得移除上一行末尾逗号),省略后默认 2000 |
| 2661 | |
| 2662 | // "inherits" 是继承标识,当你只需要对某个外置规则中 增删改 部分规则内容时(比如只是修改域名),那么就可以像下面第二个 "aaa" 规则一样写一个同名规则,规则内只需要有要修改的 host 内容,以及 inherits 标识,这样脚本就会将这个自定义翻页规则中的 host 覆盖掉外置翻页规则中的 host,而该翻页规则内的其他规则内容则不变。即更灵活了,无需每次为了修改部分规则而去复制全部规则了,也不用担心我后续更新这个外置规则后,你还需要再次复制一遍来修改。。。 |
| 2663 | |
| 2664 | { |
| 2665 | "aaa": { |
| 2666 | "host": "aaaa", |
| 2667 | "url": "return fun.isPager()", |
| 2668 | "pager": { |
| 2669 | "nextL": "xxxx", |
| 2670 | "pageE": "xxxx", |
| 2671 | "replaceE": "xxxx", |
| 2672 | "scrollD": 2000 |
| 2673 | } |
| 2674 | }, |
| 2675 | "aaa": { |
| 2676 | "host": "cccc", |
| 2677 | "inherits": true |
| 2678 | }, |
| 2679 | "bbb": { |
| 2680 | "host": ["bbb1.com", "bbb2.com"], |
| 2681 | "url": "/^\\\\/s$/", |
| 2682 | "style": ".aaaa {xxx: xxx}(如果只是为了单纯屏蔽隐藏某些元素,那么这里只需要写 CSS 选择器即可,脚本会自动在末尾加上 {display: none !important;} 的)", |
| 2683 | "blank": 3, |
| 2684 | "hiddenPN": true, |
| 2685 | "history": false, |
| 2686 | "thread": true, |
| 2687 | "iframe": true, |
| 2688 | "pager": { |
| 2689 | "type": 1, |
| 2690 | "nextL": "id('page')//a[contains(text(),'下一页')] || id('page2')//a[text()='下一页']", |
| 2691 | "pageE": "aaa", |
| 2692 | "insertP": [".bbb",3], |
| 2693 | "replaceE": ".page", |
| 2694 | "scriptT": 1, |
no test coverage detected