()
| 1336 | |
| 1337 | // 移除登录弹窗 |
| 1338 | function removeLogin() { |
| 1339 | const removeLoginModal = (mutationsList, observer) => { |
| 1340 | for (const mutation of mutationsList) { |
| 1341 | for (const target of mutation.addedNodes) { |
| 1342 | if (target.nodeType != 1) return |
| 1343 | if (target.querySelector('.signFlowModal')) { |
| 1344 | let button = target.querySelector('.Button.Modal-closeButton.Button--plain'); |
| 1345 | if (button) button.click(); |
| 1346 | } else if (getXpath('//button[text()="立即登录/注册"]',target)) { |
| 1347 | target.remove(); |
| 1348 | } |
| 1349 | } |
| 1350 | } |
| 1351 | }; |
| 1352 | |
| 1353 | // 未登录时才会监听并移除登录弹窗 |
| 1354 | if(location.hostname === 'zhuanlan.zhihu.com') { // 如果是文章页 |
| 1355 | if (!document.querySelector('.ColumnPageHeader-profile>.AppHeader-menu')) { // 未登录 |
| 1356 | const observer = new MutationObserver(removeLoginModal); |
| 1357 | observer.observe(document, { childList: true, subtree: true }); |
| 1358 | if (getXpath('//button[text()="登录/注册"]')) getXpath('//button[text()="登录/注册"]').outerHTML = '<a class="Button AppHeader-login Button--blue" href="https://www.zhihu.com/signin" target="_blank">登录/注册</a>'; // [登录] 按钮跳转至登录页面 |
| 1359 | } |
| 1360 | } else { // 不是文章页 |
| 1361 | if (!document.querySelector('.AppHeader-profile>.AppHeader-menu')) { // 未登录 |
| 1362 | const observer = new MutationObserver(removeLoginModal); |
| 1363 | observer.observe(document, { childList: true, subtree: true }); |
| 1364 | document.lastElementChild.appendChild(document.createElement('style')).textContent = '.Question-mainColumnLogin, button.AppHeader-login {display: none !important;}'; // 屏蔽问题页中间的登录提示 |
| 1365 | if (getXpath('//button[text()="登录/注册"]')) getXpath('//button[text()="登录/注册"]').outerHTML = '<a class="Button AppHeader-login Button--blue" href="https://www.zhihu.com/signin" target="_blank">登录/注册</a>'; // [登录] 按钮跳转至登录页面 |
| 1366 | } |
| 1367 | } |
| 1368 | } |
| 1369 | |
| 1370 | // 净化标题消息 |
| 1371 | function cleanTitles() { |
no test coverage detected