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

Function checklastElementsBr

Autopage.user.js:1972–1980  ·  view source on GitHub ↗
(e)

Source from the content-addressed store, hash-verified

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;

Callers 1

processElemsFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected