Remove Facebook Video Advertisements

Prevents Facebook advertisements playing while watching videos on facebook.

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Remove Facebook Video Advertisements
// @namespace    https://greasyfork.org/en/scripts/462105-remove-facebook-video-advertisements
// @version      1.0.1a
// @description  Prevents Facebook advertisements playing while watching videos on facebook.
// @author       Daile Alimo
// @match        https://www.facebook.com/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=facebook.com
// @license      MIT
// @grant        none
// ==/UserScript==

// Stops advertisements playing during a video.
// Hides the video overlay, this is done because since event doesn't propagate Facebook does not know the video has stopped buffering and will show a buffering icon over the video.
window.addEventListener('play', function(event) {
   event.stopImmediatePropagation();
   event.target.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.childNodes[1].childNodes[0].childNodes[0].setAttribute('hidden', 'hidden');
   event.target.parentNode.childNodes[1].childNodes[0].childNodes[0].setAttribute('hidden', 'hidden');
   document.querySelector('[aria-label="Unmute"]').click();
   event.target.muted = false;
}, true);

// Stops advertisements playing at the end of a video.
// Makes the video overlay visible again.
window.addEventListener('ended', function(event) {
   event.stopImmediatePropagation();
   event.target.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.childNodes[1].childNodes[0].childNodes[0].removeAttribute('hidden');
   event.target.parentNode.childNodes[1].childNodes[0].childNodes[0].removeAttribute('hidden', 'hidden');
   document.querySelector('[aria-label="Unmute"]').click();
   event.target.muted = false;
}, true);