Just remove zhihu video
当前为
// ==UserScript==
// @name Remove zhihu video
// @namespace https://www.Removezhihuvideo.com
// @version 0.2
// @description Just remove zhihu video
// @author You
// @match https://www.zhihu.com/
// @icon http://zhihu.com/favicon.ico
// @grant none
// @run-at document-body
// ==/UserScript==
let inited = false;
function callback(mutationsList) {
for (let m of mutationsList) {
if (m.type == 'childList' && m.addedNodes.length > 0) {
for (let node of m.addedNodes) {
//console.log('addnodes:', node);
if (!inited && node.tagName === 'DIV')
{
for (let cnode of node.querySelectorAll('.TopstoryItem')) {
removeIfVideo(cnode);
}
inited = true;
}
if (node.tagName === 'DIV' && node.classList.contains('TopstoryItem')) {
removeIfVideo(node);
}
}
}
}
}
for (let node of document.querySelectorAll('.TopstoryItem')) {
removeIfVideo(node);
}
const observer = new MutationObserver(callback);
observer.observe(document.body, {
childList: true,
subtree: true
})
function removeIfVideo(node) {
let n = node.querySelector('.ZVideoItem');
if (n) {
let m = n.querySelector('iframe');
if (m && m.src &&
m.src.indexOf('www.zhihu.com/video/') >= 0 ||
m.src.indexOf('video.zhihu.com') >= 0
) {
const m2 = node.querySelector('.ZVideoItem-video');
if (m2 && n.children.length === 3) {
n.children[1].style.display = 'none';
n.children[2].style.display = 'none';
let div = document.createElement('div');
div.innerHTML = '<button class="Button">show video</button>'
n.appendChild(div);
div.addEventListener('click', function () {
n.children[1].style.display = '';
n.children[2].style.display = '';
div.remove();
});
}
}
}
}