Remove zhihu video

Just remove zhihu video

Ekde 2021/12/05. Vidu La ĝisdata versio.

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         Remove zhihu video
// @namespace    https://www.Removezhihuvideo.com
// @version      0.3
// @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();
				});
			}
		}
	}
}