igoist
2018-06-27 12:01:39 +08:00
content_scripts 自己加一个?
...
{
"matches": ["*://*.zhihu.com/*"],
"js": ["src/zhihu.js"]
}
...
(function() {
/**
* 屏蔽知乎热门推送
* 处理 .TopstoryItem 为主的以及其他可能包含'热门内容,'的 DOM
*/
function purify (nodes) {
for (let node of nodes) {
if (node.textContent.indexOf('热门内容, ') === 0) {
node.querySelector('.TopstoryItem-rightButton').click()
// node.parentNode.removeChild(node) // 做人留一线,先注释掉
console.log(node);
}
}
}
const mo = new MutationObserver(mutations => {
for (let mutation of mutations) {
if (mutation.type === 'childList') {
purify(mutation.addedNodes)
}
}
})
purify(document.querySelectorAll('.TopstoryItem'))
if (document.querySelector('.TopstoryMain > div')) {
mo.observe(document.querySelector('.TopstoryMain > div'), { childList: true })
}
/**
* 问题答案页
* .AdblockBanner 友情提示
* .Question-sideColumn 侧栏
* .Question-main 主要内容,对其排版样式重新自定义
*/
let AdblockBanner = document.querySelector('.AdblockBanner');
if (AdblockBanner) {
AdblockBanner.remove();
}
let QuestionSideColumn = document.querySelector('.Question-sideColumn');
if (QuestionSideColumn) {
QuestionSideColumn.remove();
}
let QuestionMain = document.querySelector('.Question-main');
if (QuestionMain) {
QuestionMain.style = `
margin: 0 auto;
margin-top: 10px;
margin-bottom: 10px;
width: 1170px;
`;
let QuestionMainColumn = document.querySelector('.Question-mainColumn');
QuestionMainColumn.style.width = '100%';
}
})();