一年多前 google 自己推出的右鍵搜圖 Search by Image 套件,
沒想到今天已經變成內建的了(新版Chrome 按右鍵找圖)
所以今天就來寫一下右鍵選單(ContextMenus)吧
manifest.json
{
"manifest_version": 2,
"name": "ironman6",
"version": "1.0",
"background": {
"scripts": ["background.js"]
},
"permissions": [
"contextMenus"
]
}
background.js
for (var i = 1; i < 7; i++) {
chrome.contextMenus.create({
"title": "Day " + i,
"contexts":["all"],
"onclick": genericOnClick
});
}
function genericOnClick(info, tab) {
var output = [];
for(item in info){
output.push(item + ' : ' + info[item]);
}
for(item in tab){
output.push(item + ' : ' + tab[item]);
}
chrome.tabs.create({
url: 'data:text/html;charset=utf-8,' + '<p>' + output.join('<p/><p>') + '</p>'
})
}