javascript - 灰色的 Chrome 扩展程序仅可用于登录后 manifest.json 中声明的站点,否则在所有其他站点上显示为灰色
问题描述
我需要仅当用户登录到父站点(即 www.flyship.com)以及 manifest.json 中提到的站点时才可以使用扩展程序。
"content_scripts": [
{
"matches": [
"*://*.flyship.com/*",
"*://app.yield.io/*",
"*://*.indeedjobs.com/*"
],
"js": ["scripts/content.js","scripts/index.js"]
}
],
在 background.js 中,我正在检查用户是否使用此代码登录到 flyship.com
chrome.runtime.onMessage.addListener(
function(request, sender, sendResponse){
if(request.login === "logged"){
checkUser(request, sender, sendResponse);
// checkforValidUrl();
}
return true;
}
function checkUser(request, sender, sendResponse){
chrome.cookies.get({url : "https://www.flyship.com/app", name: "csrftoken"}, function(cookie){
const CSRF = cookie.value;
sendResponse({token: CSRF});
console.log(CSRF);
});
}
除了 manifest.json 中提到的站点之外,我需要在所有其他站点上将扩展显示为灰色,只有当用户登录到 flyship.com 时。
PS:我已经尝试过 declarativeContent 但它似乎对我不起作用,或者至少我无法根据我的需要推断它。以下是我检查网址的代码
function checkforValidUrl(){
chrome.runtime.onInstalled.addListener(function() {
chrome.declarativeContent.onPageChanged.removeRules(undefined, function() {
chrome.declarativeContent.onPageChanged.addRules([
{
conditions: [
new chrome.declarativeContent.PageStateMatcher({
pageUrl: { urlContains: '*://*.flyship.com/*' },
}),
new chrome.declarativeContent.PageStateMatcher({
pageUrl: { urlContains: '*://app.yield.io/*' }
}),
new chrome.declarativeContent.PageStateMatcher({
pageUrl: { urlContains: 'https://www.indeedjobs.com/*' }
})
],
actions: [ new chrome.declarativeContent.ShowPageAction() ]
}
]);
});
});
}
自从 1 周以来,我一直在努力解决这个问题,阅读文档等等。在这方面有礼貌的帮助会非常有帮助。
解决方案
推荐阅读
- java - ExpectNew 没有被同一类调用两次
- c - C - 在循环中使用 fgets() 获取分段错误
- c++ - 我试图计算大写字符但它不起作用,我不想改变主要但如果你能帮我修复这个功能
- sql - 光标和过程/函数 pl sql 以显示员工姓名
- excel - 隐藏取消隐藏特定工作表慢
- python - 如何在 python 中获取我系统支持的所有屏幕分辨率
- php - 页面 (.php) 停止加载包含文件
- html - 保持文本区域旁边的下拉菜单不起作用
- mysql - 如果我的数据库中有一个空值,则颤振列表视图会显示无效的争论
- excel - 自动向 2000-3000 人发送电子邮件(通过 Outlook 365)?