徒手创建一个chrome扩展-屏蔽广告插件

  • 2020 年 2 月 18 日
  • 筆記

创建一个文件夹,创建以下文件 maniftest.json background.js和 icon图片

maniftest.json文件设置如下

{    "name": "DevSage Adblocker",    "version": "1.0",    "description": "Lilugir Adblocker Tutorial",    "permissions": [      "webRequest",      "webRequestBlocking",      "<all_urls>"    ],    "background": {      "scripts": [        "background.js"      ]    },    "icons": {      "16": "icons/logo_16x16.png",      "48": "icons/logo_48x48.png",      "128": "icons/logo_128x128.png"    },    "manifest_version": 2  }

background.js文件内容如下

const defaultFilters = [    "*://*.doubleclick.net/*",    "*://partner.googleadservices.com/*",    "*://*.googlesyndication.com/*",    "*://*.google-analytics.com/*",    "*://creative.ak.fbcdn.net/*",    "*://*.adbrite.com/*",    "*://*.exponential.com/*",    "*://*.quantserve.com/*",    "*://*.scorecardresearch.com/*",    "*://*.zedo.com/*",  ]    chrome.webRequest.onBeforeRequest.addListener(function (details) {    return {      cancel: true    }  }, {    urls: defaultFilters  }, ["blocking"])

打开chrome浏览器 输入地址 chrome://extensions/ ,确保开发者模式打开 ,点击“加载已解压的扩展程序” ,选择你的项目文件夹 点击确认。

然后尝试在chrome浏览器上输入被屏蔽的广告地址之一看看是否其效果 https://www.zedo.com/