두 개의 다른 콘텐츠 스크립트로 Safari 확장 프로그램을 구축하고 있습니다. 하나의 스크립트를 모든 http 페이지에 삽입해야합니다 (https 페이지는 제외). 다른 하나는 구성표와 상관없이 google.com 페이지에만 주입됩니다. 이것은 높은 수준에서, 내 확장 콘텐츠 스크립트가 모든 페이지에 액세스 할 수 있어야한다는 것을 의미한다콘텐츠 스크립트 삽입을위한 다중 허용 목록/블랙리스트?
이를 달성하기 위해
, 나는 Extension Website Access
에 설정했습니다.
더 세분화 된 제어권을 얻기 위해 콘텐츠 패턴을 프로그래밍 방식으로 내 패턴과 일치하는 URL에 삽입합니다.
App = {
content: {
// Inject into unsecure pages.
whitelist: ['http://*/*'],
// But not into secure pages.
blackList: ['https://*/*'],
loc: safari.extension.baseURI + 'data/content.js'
},
results: {
// Inject this script into all google.com pages
whiteList: ['http://*.google.com/*', 'https://*.google.com/*'],
// Surely I don't need a blacklist if I specify a whitelist?
blacklist: undefined,
loc: safari.extension.baseURI + 'data/results.js',
}
};
// Inject the first content script.
safari.extension.addContentScriptFromURL(App.content.loc,
App.content.whitelist, App.content.blacklist, false);
// Inject the second content script.
safari.extension.addContentStyleSheetFromURL(App.results.cssLoc,
App.results.whitelist, App.results.blacklist, false);
두 스크립트가 모든 페이지에 주입되는 것이 문제입니다. 마치 내 백인과 블랙리스트가 아무 것도하지 않는 것과 같습니다. 내가 도대체 뭘 잘못하고있는 겁니까?
App = {
content: {
blackList: ['https://*/*'],
},
results: {
whiteList: ['http://*.google.com/*', 'https://*.google.com/*']
}
};
을하지만 스크립트 분사 기능으로 목록을 통과 할 때 그 변수의 비 대문자 버전을 사용 :
이것이 문제의 원인인지는 모르겠지만 두 세트가 공간을 완전히 채우므로 첫 번째 분사 명령에 화이트리스트와 블랙리스트가 모두 필요하지는 않습니다. – canisbos