自定義瀏覽器擴展屏蔽百度百科自動播放視頻


使用css技術屏蔽,將目標元素的css選擇器值找出來,設置display屬性為none屏蔽元素
新建目錄AnnoyingElementsBlock,目錄下結構如下所示:

-css
|-BlockBaiduBaikeVideo.css
|-BlockBaiduJingyanVideo.css
-manifest.json

manifest.json內容

{
    "manifest_version": 2,
    "name": "tellw頁面元素屏蔽器",
    "version": "1.0",
    "description": "可以屏蔽網頁中不需要的元素",
    "content_scripts": [
        {
            "matches": ["https://baike.baidu.com/*"],
            "css": ["css/BlockBaiduBaikeVideo.css" ]
        },
        {
        	"matches": ["https://jingyan.baidu.com/*"],
        	"css": ["css/BlockBaiduJingyanVideo.css"]
        }
    ]
}

css/BlockBaiduBaikeVideo.css內容#sl-player-el { display: none; }
css/BlockBaiduJingyanVideo.css內容#feeds-video-play-container { display: none; }

在edge中打開開發者模式,加載該自定義插件目錄,再次訪問百度百科看到視頻元素處是一個黑塊。
參考鏈接:制作一個瀏覽器插件來屏蔽百度經驗的視頻

擴展

使用油猴腳本實現相同功能,安裝油猴腳本插件后創建自定義腳本內容如下

// ==UserScript==
// @name         block some elements I don't like
// @namespace    https://baidu.com
// @version      0.1
// @description  屏蔽網站中不想看到的元素
// @author       You
// @match        https://baike.baidu.com/*
// @match        https://jingyan.baidu.com/*
// @license      GPLv3 License
// ==/UserScript==

(function() {
    'use strict';
    var baiduBaikeVideoElement = document.getElementById("sl-player-el");
    var baiduJingyanVideoElement = document.getElementById("feeds-video-play-container");
    if(baiduBaikeVideoElement)baiduBaikeVideoElement.style.display = "none";
    if(baiduJingyanVideoElement)baiduJingyanVideoElement.style.display = "none";
    // Your code here...
})();

本文創建於2021年1月13日16點56分,修改於2021年 07月 11日 星期日 16:54:48 CST


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM