diff --git a/manifest.json b/manifest.json index 7d541d34..b99c8ed3 100644 --- a/manifest.json +++ b/manifest.json @@ -5,7 +5,7 @@ "browser_action": {"default_popup": "/publish/chrome/popup.html"}, "content_scripts": [{"matches": [""], "js": ["/proto.js", "/lib/base.js", "/lib/core.js", "/lib/misc.js", "/lib/page.js", "/lib/user.js", - "/publish/chrome/contexts.js" + "/frame.js", "/publish/chrome/contexts.js" ]} ], "permissions": [ diff --git a/publish/chrome/chrome.js b/publish/chrome/chrome.js index dc23d906..4e9139aa 100644 --- a/publish/chrome/chrome.js +++ b/publish/chrome/chrome.js @@ -46,7 +46,7 @@ Volcanos("chrome", { }) }, }, ["/lib/base.js", "/lib/core.js", "/lib/misc.js", "/lib/page.js", "/lib/user.js"], function(can) { - can.run = function(event, cmds, cb, silent) { var msg = can.request(event) + can.run = function(event, cmds, cb) { var msg = can.request(event) can.misc.Run(event, can, {names: "http://localhost:9020/code/chrome/"+cmds[0]}, cmds.slice(1), cb) }, chrome.history.onVisited.addListener(function(item) { @@ -60,6 +60,13 @@ Volcanos("chrome", { can.core.CallFunc([can, cmd], {can: can, msg: msg, cmds: arg, cb: function() { msg.Reply() }}) }) + chrome.runtime.onMessage.addListener(function(req, sender, cb) { + var msg = can.request(); can.core.List(req.option, function(key) { msg.Option(key, req[key][0]) }) + can.run(msg._event, req.detail||[], function(msg) { + cb(msg) + }) + }) + chrome.contextMenus.create({title: "favor", onclick: function(event) { chrome.tabs.query({currentWindow: true, active: true}, function(tabs) { var msg = can.request(event); msg.detail = ["chrome", "", "", "favor"] diff --git a/publish/chrome/contexts.js b/publish/chrome/contexts.js index 58b04055..9f4b82d4 100644 --- a/publish/chrome/contexts.js +++ b/publish/chrome/contexts.js @@ -34,12 +34,21 @@ Volcanos("chrome", { msg.Push("link", item.src) }) }, -}, [], function(can) { can._load("chrome") +}, [], function(can) { can._load("/frame.js") chrome.extension.onMessage.addListener(function(req, sender, cb) { var msg = can.request(); can.core.List(req.option, function(key) { msg.Option(key, req[key][0]) }) can.core.CallFunc([can, req.detail[3]||"spide"], {can: can, msg: msg, arg: req.detail.slice(4), cb: function() { delete(msg._event), delete(msg._can), cb(msg) }}) }) + + can.run = function(event, cmds, cb) { var msg = can.request(event); msg.detail = ["page"].concat(cmds) + chrome.runtime.sendMessage(msg, function(res) { + can.base.isFunc(cb) && cb(msg.Copy(res)) + }) + } + can.onappend.plugin(can, {index: "cli.system"}, function(msg) { + + }, document.body) })