我正在玩扩展。如果用户安装了扩展程序,我想捕获他们在网页上单击的链接。不太确定如何执行此操作,但看起来很简单。我可能会补充一点,只要安装并启用了插件,我希望这种情况发生,但不希望用户必须在工具栏中执行任何操作来“激活”它。
不知道如何开始。而且我认为我有一个太多的 JS 文件,但只是试图让其中一个登录到控制台。也不行。我的最终目标是,如果他们去某些地方,我想将他们重定向到 Intranet 页面。
背景.js
var redirectedSites = ["https://www.facebook.com/profile.php?id=<SOMEPROFILEID>"];
// when the browser tries to get to a page, check it against a list
chrome.webRequest.onBeforeRequest.addListener(
function(details) {
console.log('is this even getting hit?');
for(var i=0; i < redirectedSites.length; ++i) {
// if the attempt is to a listed site, redirect the request
if( details.url == redirectedSites[i] )
return {redirectUrl: "http://intranet/landing?from=" + details.url };
}
},
{urls: ["*://www.facebook.com/*"]},
["blocking"]
);
清单.json
{
"name": "Capture Click",
"version": "0.1",
"description": "Simple tool that logs clicked links.",
"permissions": [
"tabs",
"webRequest",
"webRequestBlocking",
"https://*.facebook.com/*"
],
"background": {
"scripts": ["background.js"]
},
"manifest_version": 2
}