Skip to content

Instantly share code, notes, and snippets.

@avaforvr
Last active November 4, 2020 09:17
Show Gist options
  • Save avaforvr/bc5d9dbf1000c5199c30e62ca4e2e3bc to your computer and use it in GitHub Desktop.
Save avaforvr/bc5d9dbf1000c5199c30e62ca4e2e3bc to your computer and use it in GitHub Desktop.
/*fixed元素*/
.is-fixed {
position: static !important;
display:none;
}
/*专栏页头*/
.ColumnPageHeader-Wrapper {
display:none;
}
/*头部logo*/
.ZhihuLogoLink {
display:none;
}
/*主体容器*/
.Topstory-container, .SearchMain, .Question-main {
width: 100%;
max-width: 1000px;
display:block;
}
/*右边栏*/
.GlobalSideBar, .SearchSideBar, .Question-sideColumn {
display:none;
}
/*左边栏*/
.Topstory-mainColumn, .Question-mainColumn {
margin-right: 0;
width: 100%;
max-width: 1000px;
}
/*整体容器*/
/*左边缩略图*/
.RichContent-cover {
display:none;
}
/*actions*/
.Topstory-container .ContentItem-actions, .SearchMain .ContentItem-actions {
display:none;
}
/*文章顶部全屏图片*/
.TitleImage--fullScreen{
display:none;
}
// ==UserScript==
// @name 屏蔽知乎首页推荐中的广告和肖战
// @namespace http://tampermonkey.net/
// @version 0.1
// @description 不知道为什么总是给我推荐标题特别恶心充满脑残气息的帖子,知乎推荐算法太垃圾了
// @author Ava
// @match https://www.zhihu.com/
// @grant none
// ==/UserScript==
(function () {
'use strict';
function hideCards (items) {
items.forEach(function (item) {
const title = item.querySelector('.ContentItem-title').innerHTML;
if (item.classList.contains('TopstoryItem--advertCard') || /余生请多指教|肖战/.test(title)) {
item.parentNode.removeChild(item);
}
});
}
function callback (mutationList, observer) {
mutationList.forEach((mutation) => {
if (mutation.type === 'childList') {
if (mutation.addedNodes.length) {
hideCards(mutation.addedNodes);
}
}
});
}
hideCards(document.querySelectorAll('#TopstoryContent .TopstoryItem'));
var targetNode = document.querySelector('#TopstoryContent .TopstoryItem').parentNode;
var observerOptions = {
childList: true
}
var observer = new MutationObserver(callback);
observer.observe(targetNode, observerOptions);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment