(pageE, o = curSite.pager.replaceE, r = curSite.pager.replaceE)
| 2269 | } |
| 2270 | // 替换元素 |
| 2271 | function replaceElems(pageE, o = curSite.pager.replaceE, r = curSite.pager.replaceE) { |
| 2272 | let oE,rE; |
| 2273 | |
| 2274 | if (curSite.pager.replaceE === undefined && curSite.pager.nextL && curSite.pager.nextL.search(/^js;/i) !== 0) { // 如果 replaceE 不存在,且 nextL 存在,且不是 js 代码 |
| 2275 | let a = getOne(curSite.pager.nextL) // 获取 nextL 元素,并判断该元素后面或前面是否有同类型的相邻兄弟元素 |
| 2276 | if ((a.nextElementSibling && a.nextElementSibling.tagName === a.tagName) || (a.previousElementSibling && a.previousElementSibling.tagName === a.tagName)) { |
| 2277 | // nextL 元素后面或前面有同类型的相邻兄弟元素,则可以替换 nextL 的父元素 |
| 2278 | // 当 nextL 选择器为 xpath 时,直接末尾追加 /.. 即可选择其父元素 |
| 2279 | if (curSite.pager.nextL.slice(0,1) === '/' || curSite.pager.nextL.slice(0,2) === './' || curSite.pager.nextL.slice(0,2) === '(/' || curSite.pager.nextL.slice(0,3) === 'id(') { |
| 2280 | o = r = curSite.pager.nextL + '/..' |
| 2281 | } else { // 当 nextL 选择器为 css 时,则需要寻找所有 nextL 元素的父元素 |
| 2282 | oE = getAllParentElement(curSite.pager.nextL) |
| 2283 | rE = getAllParentElement(curSite.pager.nextL, pageE, pageE) |
| 2284 | } |
| 2285 | } else { // 如果 nextL 元素后面或前面没有同类型的相邻兄弟元素,那么就只替换 nextL 元素 |
| 2286 | o = r = curSite.pager.nextL |
| 2287 | } |
| 2288 | } |
| 2289 | |
| 2290 | if (!oE && !rE && o && r) { |
| 2291 | oE = getAll(o) |
| 2292 | rE = getAll(r, pageE, pageE) |
| 2293 | } |
| 2294 | |
| 2295 | if (oE && rE && oE.length != 0 && rE.length != 0 && oE.length === rE.length) { |
| 2296 | for (let i = 0; i < oE.length; i++) { |
| 2297 | oE[i].outerHTML = rE[i].outerHTML; |
| 2298 | } |
| 2299 | return true |
| 2300 | } else if (curSite.pager.replaceE !== undefined) {console.log(pageE,oE,rE)} |
| 2301 | return false |
| 2302 | } |
| 2303 | // 添加历史记录 |
| 2304 | function addHistory(pageE, title, url) { |
| 2305 | if (!curSite.pageUrl) return |
no test coverage detected