MCPcopy Index your code
hub / github.com/XIU2/UserScript / processElems

Function processElems

Autopage.user.js:1929–2066  ·  view source on GitHub ↗
(response)

Source from the content-addressed store, hash-verified

1927
1928 // XHR 后处理结果,插入、替换元素等(适用于翻页类型 1/3/6)
1929 function processElems(response) {
1930 if (!curSite.pager.insertP) {curSite.pager.insertP = [curSite.pager.pageE, 5]}
1931 let pageE = getAll(curSite.pager.pageE, response, response), toE;
1932 if (curSite.pager.insertP[1] === 5) { // 插入 pageE 列表最后一个元素的后面
1933 toE = toE5pop(getAll(curSite.pager.insertP[0]));
1934 } else {
1935 toE = getOne(curSite.pager.insertP[0]);
1936 }
1937 //console.log(curSite.pager.pageE, pageE, curSite.pager.insertP, toE)
1938
1939 if (pageE.length > 0 && toE) {
1940 // 如果有插入前函数就执行函数
1941 if (curSite.function && curSite.function.bF) {
1942 if (curSite.function.bFp) { // 如果指定了参数
1943 if (typeof(curSite.function.bF) == 'string') { // 如果是字符串,说明是自定义规则
1944 pageE = new Function('pageE', 'bFp', 'fun', curSite.function.bF)(pageE, curSite.function.bFp, window.autoPage)
1945 } else {
1946 pageE = curSite.function.bF(pageE, curSite.function.bFp);
1947 }
1948 } else {
1949 if (typeof(curSite.function.bF) == 'string') { // 如果是字符串,说明是自定义规则
1950 pageE = new Function('pageE', 'fun', curSite.function.bF)(pageE, window.autoPage)
1951 } else {
1952 pageE = curSite.function.bF(pageE);
1953 }
1954 }
1955 }
1956
1957 // 强制新标签页打开链接
1958 if (curSite.blank === 4 || curSite.blank === 5 || curSite.blank === 6) {pageE = forceTarget(pageE);}
1959
1960 // 插入位置
1961 let addTo = getAddTo(curSite.pager.insertP[1]);
1962
1963 // 插入新页面元素
1964 if (curSite.pager.insertP[1] === 6) { // 插入到目标内部末尾(针对文本,比如小说网页)
1965 let afterend = '';
1966 if (curSite.pager.insertP6Br === false) { // 这个基本上只有脚本内置的通用规则会用上,因为该通用规则匹配到的网站正文 <br> 是未知的,所以需要判断一下数量
1967 if (unsafeWindow.insertP6Br === true) {
1968 afterend += '<br/><br/>'
1969 } else if (unsafeWindow.insertP6Br === undefined) {
1970 if (getAll('br', getOne(curSite.pager.pageE)).length > 10) {
1971
1972 function checklastElementsBr(e) {
1973 const children = Array.from(e.childNodes).filter(node => {return node.nodeType === Node.ELEMENT_NODE || (node.nodeType === Node.TEXT_NODE && node.textContent.trim() !== '');}), lastElement = children[children.length - 1];
1974 if (lastElement.tagName === 'BR') { // 判断最后一个元素
1975 return true; // 最后一个元素是 <br>
1976 } else if (lastElement.tagName === 'P' && lastElement.classList.contains('readinline')) { // 判断倒数第二个元素
1977 return children[children.length - 2].tagName === 'BR'; // 倒数第二个元素是 <br>
1978 }
1979 return false; // 其他情况
1980 };
1981 // 如果正文末尾最后一个元素不是 <br> 且 倒数第二个元素也不是 <br> 时,才添加 <br/><br/>
1982 if (!checklastElementsBr(getOne(curSite.pager.pageE))) {
1983 unsafeWindow.insertP6Br = true;
1984 afterend += '<br/><br/>'
1985 } else {unsafeWindow.insertP6Br = false;}
1986 }

Callers 2

getPageEFunction · 0.85
insIframe_Function · 0.85

Calls 10

getAllFunction · 0.85
toE5popFunction · 0.85
getOneFunction · 0.85
forceTargetFunction · 0.85
getAddToFunction · 0.85
checklastElementsBrFunction · 0.85
pageNumIncrementFunction · 0.85
addHistoryFunction · 0.85
replaceElemsFunction · 0.85
insScriptFunction · 0.85

Tested by

no test coverage detected