站点规则

站点规则可以是

我们更倾向于JSON dataopen in new window因为JSON可以实现热更新. 🌰 在文末.

规则的基本构成

name

  • type: String JSJSON
  • description: 站点名称

url

  • type: XPath StringJSJSON, XPathJS
  • description: 匹配站点的正则表达式

exampleUrl Optional

  • type: String JSJSON
  • description: 地址范例

enable

  • type: Boolean Optional
  • default: true
  • description: 规则开关

脚本依据nextLink寻找下一页的 URL,我们提供了多种方式:

  1. XPath selectoropen in new window:拥有href属性并指向下一页的元素 或 内容为下一页的元素

    • type: XPath String JSJSON, XPath JS
    • example: //div[@id="nav"]/a, //div[@id="nav"]/a/@href,两者等效
  2. CSS selectoropen in new window

    • type: String JSJSON
    • content: css;${CSS selector}
    • example: css;div#nav>a
  3. "auto;"脚本会自动寻找所有text()为“下一页”, “next page”等预定义的下一页文字且含有href属性的a的元素

    • type: String JSJSON
    • content: auto; 无选项
  4. function返回值为下一页链接的JS函数

    • type: JS function JS
    • content:
    function(currentDocument, currentWindow, currentPageURL) {
      // **** your function is here ****
      return urlOfNextPage
    }
    
  5. Array脚本会遍历所有元素并使用 以上方法 直至找到下一页链接地址

  6. Object复杂模式,参照函数hrefIncJSJSON

nextLink, 然而基本没什么时候需要😂

pageElement

脚本根据pageElement的定义查找自动翻页时拼接的元素。举个🌰,对于搜索引擎,pageElement应为搜索的结果。 我们同样提供了以下方式:

  1. XPath selectoropen in new window:拼接元素的XPath selector

    • type: XPath String JSJSON, XPath JS
    • example: //div[@id="content]
  2. CSS selectoropen in new window

    • type: String JSJSON
    • content: css;${CSS selector}
    • example: css;div#content
  3. function返回拼接元素的HTMLCollectionopen in new window的函数。 一个🌰是WordPress的规则, 通过JS函数我们可以判断一个页面是否是 post,如果不是就返回null跳出脚本逻辑,如果是就返回 post 的内容。再一个🌰是某些漫画网站,我们可以使用pageElement直接计算下一张图片的地址,从而避免加载无用的内容。

    • type: JS function JS
    • content:
    function(currentDocument, currentWindow, currentPageURL) {
      // **** your function is here ****
      return HTMLCollection
    }
    

规则的增强功能

除基本元素外,规则还可包含一个keyautopagerObject以实现增强功能。autopager可包含以下key。所有key都为Optional

useiframe

  • type: Boolean JSJSON
  • default: false
  • description: 使用 iframe 读取内容而不使用XHRopen in new window

iloaded

  • type: Boolean JSJSONuseriframe: true
  • default: false
  • description: 是否在 iframe 完全 load 后操作..否则在 DOM 完成后操作

itimeout

  • type: Number JSJSONuseriframe: true
  • default: 0
  • description: iloadedfalse时的延迟,单位为毫秒

newIframe

  • type: Boolean JSJSONuseriframe: true
  • default: false
  • description: 当翻当前页面+2 时是否新建一个iframe,在部分情况下有奇效

reload

  • type: Boolean JSJSONuseriframe: true
  • default: false
  • description: 强制重载iframe,在部分情况下有奇效

force_enable

  • type: Boolean JSJSON Not Recommend
  • default: false
  • description: 如果实在难以找出pageElement,开启该选项会使整个页面被拼接上去

headers

  • type: Object JSJSON
  • default: { Referer: <本页链接> }
  • description: 自定义请求下一页的 headers

remain

  • type: Number JSJSON
  • default: 1 总是预翻一页
  • description: 脚本会根据当前页面所剩余的高度决定是否翻页,当剩余高度 <= 页面高度 x remain 时开始翻页

maxpage

  • type: Number JSJSON
  • default: 99
  • description: 最多翻页次数

mutationObserver

iframe 监听选项,用来控制主页面和 iframe 之间的通讯,一个例子

{
  timeout: 1000,
  observers: {
    attributes: "//div[@class='x']",   // the node to monitor change of attributes
    addedNodes: "//div[@class='x']",   // the node to monitor MutationRecord.addedNodes
    removedNodes: "//div[@class='x']"  // the node to monitor MutationRecord.removedNodes
  }
}

timeout:

  • type: Int JSJSON
  • default: null
  • description: 延迟通讯时间

observer:

  • type: Array JSJSON
  • default: null
  • description: mutationObserver 监控的 element 的 selector

ipages

  • type: Array JSJSON
  • default: [false,2]
  • description: 立即翻页,第一项是控制是否在脚本加载的时候立即翻第二项(必须小于 maxpage)的页数,比如[true,3].就是说 JS 加载后.立即翻 3 页。对于图站可以有😂的体验

separator

  • type: Boolean JSJSON
  • default: true
  • description: 是否显示翻页导航栏

sepdivDom

  • type: JS function JS
  • description: 对于部分页面,脚本自动添加的导航栏可能造成页面格式错乱。sepdivDom定义了一个函数来生成合适的导航栏,该导航栏会被插入在最后一个pageElement之后。 一个例子是小木虫-帖子
  • example
function(currentDocument, sepdiv) {
  // currentDocument: 读取的下一页的DOM
  // sepdiv: 脚本生成的导航栏,tag为div
  const td = doc.createElement("td");
  td.appendChild(sepdiv);
  const tr = doc.createElement("tr");
  td.setAttribute("colspan", 2);
  tr.appendChild(td);
  const tbody = doc.createElement("tbody");
  return tbody;
},

startFilter

  • type: JS function JS
  • description: 一个作用于首页(i.e. 当前页面)的 js 函数,用于修正页面。接收currentDocument, currentWindow两个参数。 详情请查看documentFilter (1)

documentFilter

  1. JS function JS
    • description: 一个作用于预读内容整体的 js 函数,执行于预读内容被插入到当前页面前。可以用来修正预读内容(比如 csdn)、去除广告(比如很多 nsfw)、根据 XHR 结果生成页面内容而避免使用 iframe(比如 bl-novel)甚至生成新的内容(比如 m-team)。 理论上你可以用 js 实现对 DOM 静态内容的修改
    • content: function (currentDocument, nextPageLink) {return newDocument}
  2. "startFilter"

scriptFilter

  • type: String JSJSON
  • description: 在将预读内容插入到当前页面之前,脚本默认会移除所有的<script>元素。 如果你想保留某些<script>, 可以讲 scriptFilter 设置为一个匹配 inline code 或者 src 的正则表达式。 可以参考站点 kongregate

filter

  1. JS function JS
    • description: 一个作用预读内容 element 的 js 函数,执行于预读内容被插入到当前页面后。
    • content: function (pageElements) {return null}

stylish

replaceE

  • description: 类似pageElement, 选择用于替换导航栏的node

例子

https://github.com/machsix/Super-preloader/raw/master/dist/mydata.jsonopen in new window