1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140
| chrome.storage.local.get(['Enabled', 'Auto_expand', 'Enable_copy', 'Clear_doms'], function(value) { if (value.Enabled) { console.log("扩展开始执行");
if (value.Enable_copy) { console.log("执行破解复制"); enableCopy2(); }
console.log("执行破解关注"); if (value.Auto_expand) { expand(); } else { modify(); }
if (value.Clear_doms) { console.log("执行清除弹窗"); removeDoms();
let observer = new MutationObserver((mutationsList) => { for (let mutation of mutationsList) { if (mutation.type == 'childList') { removeDoms(); } } }); observer.observe(document.body, { childList: true }); } } else { console.log("未启用扩展功能"); } });
function modify() { let follow_text = document.getElementsByClassName('follow-text'); if (follow_text.length == 0) { return; } follow_text = follow_text[0]; if (follow_text.textContent == "关注博主即可阅读全文") { follow_text.addEventListener("click", (event) => { event.stopPropagation(); expand(); }); let img = document.getElementsByClassName('chevrondown')[0]; img.addEventListener("click", (event) => { event.stopPropagation(); expand(); }); follow_text.textContent = "关注限制已解锁"; console.log("关注限制已解锁"); } else { console.log("没有找到\"关注博主即可阅读全文\""); } }
function expand() { let article_content = document.getElementById("article_content"); let hide_article_box = document.getElementsByClassName('hide-article-box')[0]; article_content.removeAttribute("style"); hide_article_box.parentElement.removeChild(hide_article_box); console.log("全文展开成功"); }
function removeDoms() { let classes = ['passport-login-tip-container false', 'passport-login-container', 'tool-active-list', 'article-search-tip', 'hljs-button signin active', 'csdn-side-toolbar', 'box-shadow mb8', 'blog-footer-bottom']; let infos = ['右下角弹窗', '登录弹窗', '一键收藏', '黑色提示框', '登录复制提示', '侧边工具栏', '左侧广告', '底部备案信息']; let boxs, box; for (i = 0; i < classes.length; i++) { boxs = document.getElementsByClassName(classes[i]); if (boxs.length > 0) { box = boxs[0]; box.parentElement.removeChild(box); console.log("移除" + infos[i]); } }
let ids = ['toolbarBox', 'asideWriteGuide', 'asideNewNps', 'recommendNps']; let names = ["顶部栏", '左侧广告', '左侧是否推荐','底部是否推荐']; for (i = 0; i < ids.length; i++) { box = document.getElementById(ids[i]); if(box == null) continue; box.parentElement.removeChild(box); console.log("移除" + names[i]); } }
function enableCopy() { function setAllSelect(el = document.body) { for (let index = 0; index < el.children.length; index++) { const e = el.children.item(index); e.style.userSelect = 'text'; setAllSelect(e); } } setAllSelect();
document.body.onkeydown = function(e) { if (e.ctrlKey && e.keyCode == 67) { const pasteText = window.getSelection().toString(); if (null === pasteText || undefined === pasteText || '' === pasteText.trim()) { return; } navigator.clipboard.writeText(pasteText).then(() => { console.log("复制成功!"); }).catch(() => { console.log("复制失败!"); }); } } }
function enableCopy2() { window.oncontextmenu = document.oncontextmenu = document.oncopy = null; var hea = document.getElementsByClassName('toolbar-advert')[0]; if (hea) { hea.remove() }; [...document.querySelectorAll('body')].forEach(dom => dom.outerHTML = dom.outerHTML); [...document.querySelectorAll('body, body *')].forEach(dom => { ['onselect', 'onselectstart', 'onselectend', 'ondragstart', 'ondragend', 'oncontextmenu', 'oncopy'].forEach(ev => dom.removeAttribute(ev)); dom.style['user-select'] = 'auto'; }); }
|