我一直试图制作一个基本的Chrome扩展程序,它将根据链接搜索Wayback Machine。我试图对其进行设置,以便当我右键单击某个链接时,上下文菜单中会出现一个' go to wayback machine'选项。这就是我所拥有的:
的manifest.json:
{
"name" : "Archive Right Click",
"manifest_version" : 2,
"version" : "1.0",
"description" : "Adds Go to Archive to right-click context menu.",
"icons" : {
"16" : "icon-16.png",
"48" : "icon-48.png"
},
"browser_action" : {
"default_icon": "icon-16.png",
"default_title" : "Go to Archive"
},
"permissions" : [
"tabs",
"contextMenus"
],
"background" : {
"scripts" : ["script.js"]
}
}
的script.js:
function searchArchive(info,tab) {
var url = info.linkUrl;
var archiveURL = "https://web.archive.org/web/*/" + url;
chrome.tabs.create({
url : archiveURL,
});
}
chrome.contextMenus.create(
{
"context" : ["link"],
"title" : "Open link in Archive",
"onclick" : searchArchive
});
问题在于它甚至不会出现在上下文菜单中,更不用说打开我想要的标签了。
让我知道有关Chrome扩展程序的任何有用教程。我还没有找到一个提供好例子的初学者资源。
答案 0 :(得分:1)
您应该在script.js中更改context
contexts
function searchArchive(info,tab) {
var url = info.linkUrl;
var archiveURL = "https://web.archive.org/web/*/" + url;
chrome.tabs.create({
url : archiveURL,
});
}
chrome.contextMenus.create({
"contexts" : ["link"]
"title" : "Open link in Archive",
"onclick" : searchArchive
});