Remove zhihu video

Just remove zhihu video

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Remove zhihu video
// @namespace    https://www.Removezhihuvideo.com
// @version      0.4
// @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('.VideoAnswerPlayer');
	if (n) {
		let c = document.createElement('div');
		c.innerHTML = 'removed video';
		n.parentElement.replaceChild(c,n);
	}
}