Remove Facebook Video Advertisements

Prevents Facebook advertisements playing while watching videos on facebook.

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

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

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

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

你需要先安裝一款使用者腳本管理器擴展,比如 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);