1
0
mirror of https://shylinux.com/x/volcanos synced 2025-04-25 16:58:06 +08:00

opt chrome

This commit is contained in:
bergyu 2021-07-20 22:32:29 +08:00
parent 93cd46ec2a
commit 1eb74bed1f
3 changed files with 19 additions and 3 deletions

View File

@ -5,7 +5,7 @@
"browser_action": {"default_popup": "/publish/chrome/popup.html"}, "browser_action": {"default_popup": "/publish/chrome/popup.html"},
"content_scripts": [{"matches": ["<all_urls>"], "content_scripts": [{"matches": ["<all_urls>"],
"js": ["/proto.js", "/lib/base.js", "/lib/core.js", "/lib/misc.js", "/lib/page.js", "/lib/user.js", "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": [ "permissions": [

View File

@ -46,7 +46,7 @@ Volcanos("chrome", {
}) })
}, },
}, ["/lib/base.js", "/lib/core.js", "/lib/misc.js", "/lib/page.js", "/lib/user.js"], function(can) { }, ["/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) can.misc.Run(event, can, {names: "http://localhost:9020/code/chrome/"+cmds[0]}, cmds.slice(1), cb)
}, },
chrome.history.onVisited.addListener(function(item) { 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() }}) 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.contextMenus.create({title: "favor", onclick: function(event) {
chrome.tabs.query({currentWindow: true, active: true}, function(tabs) { chrome.tabs.query({currentWindow: true, active: true}, function(tabs) {
var msg = can.request(event); msg.detail = ["chrome", "", "", "favor"] var msg = can.request(event); msg.detail = ["chrome", "", "", "favor"]

View File

@ -34,12 +34,21 @@ Volcanos("chrome", {
msg.Push("link", item.src) msg.Push("link", item.src)
}) })
}, },
}, [], function(can) { can._load("chrome") }, [], function(can) { can._load("/frame.js")
chrome.extension.onMessage.addListener(function(req, sender, cb) { 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]) }) 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() { 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) 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)
}) })