페이지의 모든 앵커를 한 도메인에서 다른 도메인으로 변경하는 간단한 Chrome pageAction 확장을 작성하려고합니다.하지만 제대로 작동하지 않는 것 같습니다. 디버깅하는 데 문제가 있습니다.간단한 크롬 pageAction 확장이 작동하지 않습니다.
이러한 종류의 확장 프로그램을 어떻게 작성해야하는지 오해합니까? 아니면 API를 오용하고 있습니까?
manifest.json을 :
{
"name": "theirs2ours",
"version": "1.0",
"description": "Changes all 'their' URLs to 'our' URLs.",
"background_page": "background.html",
"permissions": [
"tabs"
],
"page_action": {
"default_icon": "cookie.png",
"default_title": "theirs2ours"
},
"content_scripts": [
{
"matches": ["http://*/*"],
"js": ["content.js"]
}
]
}
background.html :
<html>
<head>
<script type='text/javascript'>
chrome.tabs.onSelectionChanged.addListener(function(tabId) {
chrome.pageAction.show(tabId);
});
chrome.tabs.getSelected(null, function(tab) {
chrome.pageAction.show(tab.id);
});
chrome.pageAction.onClicked.addListener(function(tab) {
chrome.tabs.sendRequest(tab.id, {}, null);
});
</script>
</head>
<body>
</body>
</html>
content.js :
var transform = function() {
var theirs = 'http://www.yourdomain.com';
var ours = 'http://sf.ourdomain.com';
var anchors = document.getElementsByTagName('a');
for (var a in anchors) {
var link = anchors[a];
var href = link.href;
if (href.indexOf('/') == 0) link.href = ours + href;
else if (href.indexOf(theirs) == 0) link.href = href.replace(theirs, ours);
}
};
chrome.extension.onRequest.addListener(function(request, sender, sendResponse) {
transform();
});
주 입증 된 API를 이름과 서명에 의해 변경되었습니다 - 당신이 필요합니다 비슷한 효과를 위해 오늘 ['chrome.tabs.onActivated'] (http://developer.chrome.com/extensions/tabs. html # event-onActivated) 및 ['chrome.tabs.getCurrent'] (http://developer.chrome.com/extensions/tabs.html#method-getCurrent)를 참조하십시오. – Ronny