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

opt chrome

This commit is contained in:
harveyshao 2022-12-14 13:41:55 +08:00
parent 73a1af3b46
commit dfd8a1221c
9 changed files with 95 additions and 106 deletions

View File

@ -141,6 +141,7 @@ Volcanos(chat.ONAPPEND, {_init: function(can, meta, list, cb, target, field) {
can.core.Item(meta.feature, function(key, cb) { cb.help && sub.user.trans(sub, kit.Dict(key, cb.help)) }) can.core.Item(meta.feature, function(key, cb) { cb.help && sub.user.trans(sub, kit.Dict(key, cb.help)) })
meta.inputs && sub.onappend._option(sub, meta, sub._option, meta.msg) meta.inputs && sub.onappend._option(sub, meta, sub._option, meta.msg)
if (meta.msg) { var msg = sub.request(); msg.Copy(can.base.Obj(meta.msg)), sub.onappend._output(sub, msg, meta.display||msg.Option(ice.MSG_DISPLAY)||meta.feature.display) } if (meta.msg) { var msg = sub.request(); msg.Copy(can.base.Obj(meta.msg)), sub.onappend._output(sub, msg, meta.display||msg.Option(ice.MSG_DISPLAY)||meta.feature.display) }
if (can._root && can._root.name == "popup") { can.onmotion.hidden(can, sub._action) }
can.core.Value(sub._legend, chat.ONMOUSEENTER, function(event) { can.core.Value(sub._legend, chat.ONMOUSEENTER, function(event) {
can.user.carte(event, sub, sub.onaction, sub.onaction.list.concat([[ctx.ACTION].concat(can.core.Item(meta.feature._trans))]), function(event, button, meta) { can.user.carte(event, sub, sub.onaction, sub.onaction.list.concat([[ctx.ACTION].concat(can.core.Item(meta.feature._trans))]), function(event, button, meta) {

View File

@ -1,7 +1,7 @@
{ {
"manifest_version": 2, "manifest_version": 2,
"name": "volcanos", "version": "0.0.1", "name": "volcanos", "version": "0.0.1",
"background": {"page": "/publish/chrome/chrome.html"}, "background": {"page": "/publish/chrome/daemon.html"},
"browser_action": {"default_popup": "/publish/chrome/popup.html"}, "browser_action": {"default_popup": "/publish/chrome/popup.html"},
"content_scripts": [{"matches": ["<all_urls>"], "permissions": [ "content_scripts": [{"matches": ["<all_urls>"], "permissions": [
"tabs", "history", "cookies", "bookmarks", "contextMenus", "notifications", "http://localhost:9020/*" "tabs", "history", "cookies", "bookmarks", "contextMenus", "notifications", "http://localhost:9020/*"

View File

@ -188,6 +188,7 @@ body.white fieldset.plugin { background-color:#ffffffa1; }
body.white fieldset.float { background-color:#0e3369; color:white; } body.white fieldset.float { background-color:#0e3369; color:white; }
body.white fieldset.full { background-color:#0e3369; color:white; } body.white fieldset.full { background-color:#0e3369; color:white; }
body.white div.output div.project div.zone>div.list>div.zone>div.name { background-color:#09466f66; color:black; } body.white div.output div.project div.zone>div.list>div.zone>div.name { background-color:#09466f66; color:black; }
body.white fieldset.full div.output div.project div.zone>div.list>div.zone>div.name { background-color:#09466f66; color:white; }
/* white hover */ /* white hover */
body.white legend:hover { background-color:skyblue; } body.white legend:hover { background-color:skyblue; }

View File

@ -256,11 +256,11 @@ function shy(help, meta, list, cb) { var args = arguments, i = 0; function next(
var Volcanos = shy({iceberg: "/chat/", volcano: "/frame.js", cache: {}, pack: {}}, function(name, can, libs, cb) { var Volcanos = shy({iceberg: "/chat/", volcano: "/frame.js", cache: {}, pack: {}}, function(name, can, libs, cb) {
var meta = arguments.callee.meta, list = arguments.callee.list; if (typeof name == lang.OBJECT) { var meta = arguments.callee.meta, list = arguments.callee.list; if (typeof name == lang.OBJECT) {
if (name.length > 0) { return Volcanos({panels: [{name: chat.HEADER, pos: html.HIDE, state: [aaa.USERNICK]}, {name: chat.ACTION, pos: html.MAIN, tool: name}]}) } if (name.length > 0) { return Volcanos({panels: [{name: chat.HEADER, pos: html.HIDE, state: [aaa.USERNICK]}, {name: chat.ACTION, pos: html.MAIN, tool: name}]}) }
var Config = name; name = Config.name||ice.CAN, kit.proto(meta, Config), _can_name = "", _can_path = "" var Config = name; name = Config.name||ice.CAN, _can_name = "", _can_path = ""
meta.iceberg = Config.iceberg||meta.iceberg, meta.libs = Config.libs||chat.libs, panels = Config.panels||chat.panel_list meta.iceberg = Config.iceberg||meta.iceberg, meta.libs = Config.libs||chat.libs, panels = Config.panels||chat.panel_list
libs = [], panels.forEach(function(p) { p && (libs = libs.concat(p.list = p.list||["/panel/"+p.name+nfs._JS, "/panel/"+p.name+nfs._CSS])) }), libs = libs.concat(Config.plugin||chat.plugin_list) libs = [], panels.forEach(function(p) { p && (libs = libs.concat(p.list = p.list||["/panel/"+p.name+nfs._JS, "/panel/"+p.name+nfs._CSS])) }), libs = libs.concat(Config.plugin||chat.plugin_list)
cb = can||function(can) { can.onengine._init(can, can.Conf(Config), panels, Config._init||meta._init, can._target) } cb = can||function(can) { can.onengine._init(can, can.Conf(Config), panels, Config._init||meta._init, can._target) }
can = {_follow: name, _target: Config.target||meta.target, _height: Config.height||meta._height, _width: Config.width||meta._width} can = Config, can._follow = name, can._target = Config.target||meta.target, can._height = Config.height||meta._height, can._width = Config.width||meta._width
} }
can = kit.proto(can||{}, kit.proto({_path: _can_path, _name: name, _load: function(name, cbs) { var cache = meta.cache[name]||[] can = kit.proto(can||{}, kit.proto({_path: _can_path, _name: name, _load: function(name, cbs) { var cache = meta.cache[name]||[]
for (list.reverse(); list.length > 0; list) { var sub = list.pop(); sub != can && cache.push(sub), sub._path = name } meta.cache[name] = cache for (list.reverse(); list.length > 0; list) { var sub = list.pop(); sub != can && cache.push(sub), sub._path = name } meta.cache[name] = cache

View File

@ -1,64 +0,0 @@
Volcanos({
chrome: function(can, msg, arg, cb) {
if (arg.length == 0 || arg[0] == "") { // 窗口列表
chrome.windows.getAll(function(wins) {
can.core.List(wins, function(win) { win.wid = win.id
msg.Push(win, ["wid", "state", html.LEFT, html.TOP, html.WIDTH, html.HEIGHT])
}), can.base.isFunc(cb) && cb(msg)
})
} else if (arg.length == 1 || arg[1] == "") { // 标签列表
chrome.tabs.getAllInWindow(parseInt(arg[0]), function(tabs) {
can.core.List(tabs, function(tab) { tab.tid = tab.id
msg.Push(tab, ["tid", "active", html.WIDTH, html.HEIGHT, "index", "title", "url"])
}), can.base.isFunc(cb) && cb(msg)
})
} else if (arg[1] == "current") { // 当前标签
chrome.tabs.query({currentWindow: true, active: true}, function(tabs) { arg[1] = tabs[0].id
chrome.tabs.sendMessage(parseInt(arg[1]), msg, function(res) {
can.base.isFunc(cb) && cb(msg.Copy(res))
})
})
} else { // 下发命令
chrome.tabs.sendMessage(parseInt(arg[1]), msg, function(res) {
can.base.isFunc(cb) && cb(msg.Copy(res))
})
}
},
_daemon: function(can) {
can.misc.WSS(can, {type: html.CHROME, name: html.CHROME}, function(event, msg, cmd, arg) {
if (msg.Option(ice.MSG_TARGET)) { msg.detail = ["", "", ""].concat(msg.detail)
chrome.tabs.sendMessage(parseInt(msg.Option(ice.MSG_TARGET)), msg, function(res) {
msg.Copy(res), msg.Reply()
})
return
}
can.core.CallFunc([can, cmd], {can: can, msg: msg, arg: arg, cb: function() { msg.Reply() }})
})
chrome.runtime.onMessage.addListener(function(req, sender, cb) {
var msg = can.request({}, {tid: sender.tab.id, url: sender.url})
can.core.List(req.option, function(key) { msg.Option(key, req[key][0]) })
msg.__daemon = can.core.Keys(html.CHROME, sender.tab.id)
can.run(msg, req.detail||[], cb)
return true
})
chrome.history.onVisited.addListener(function(item) {
can.run({}, ["sync", mdb.TYPE, "link", mdb.NAME, item.title, mdb.LINK, item.url, "tid", item.id])
})
},
_motion: function(can) {
can.user.toast = function(can, message, title) { chrome.notifications.create(null, {
message: message, title: title||can._name, iconUrl: "/favicon.ico", type: "basic",
})},
chrome.contextMenus.create({title: "volcanos", onclick: function(event) {
chrome.tabs.query({currentWindow: true, active: true}, function(tabs) {
var msg = can.request(event); msg.detail = [html.CHROME, "", "", "order"]
chrome.tabs.sendMessage(tabs[0].id, msg)
})
}})
},
}, function(can) {
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._daemon(can), can._motion(can)
})

View File

@ -1,42 +1,36 @@
setTimeout(function() { Volcanos({Option: function() { return [] }, setTimeout(function() { Volcanos({
spide: function(can, msg, _target) { Option: function() { return [] },
if (!_target) { spide: function(can, msg, target) {
if (!target) {
msg.Push(mdb.TYPE, mdb.LINK) msg.Push(mdb.TYPE, mdb.LINK)
msg.Push(mdb.NAME, document.title) msg.Push(mdb.NAME, document.title)
msg.Push(mdb.LINK, location.href) msg.Push(mdb.LINK, location.href)
} }
var has = {}; target = target||document.body
var has = {}; _target = _target||document.body can.page.Select(can, target, html.IFRAME, function(target) {
can.page.Select(can, _target, html.IFRAME, function(item) { if (!target.src || has[target.src]) { return } has[target.src] = true
if (!item.src || has[item.src]) { return } has[item.src] = true
msg.Push(mdb.TYPE, html.IFRAME) msg.Push(mdb.TYPE, html.IFRAME)
msg.Push(mdb.NAME, "") msg.Push(mdb.NAME, "")
msg.Push(mdb.LINK, item.src) msg.Push(mdb.LINK, target.src)
can.spide(can, msg, target.contentWindow.document.body)
can.spide(can, msg, item.contentWindow.document.body)
}) })
can.page.Select(can, _target, html.VIDEO, function(item) { can.page.Select(can, target, html.VIDEO, function(target) {
if (!item.src || has[item.src]) { return } has[item.src] = true if (!target.src || has[target.src]) { return } has[target.src] = true
var name = item.src.split("?")[0].split(ice.PT).pop() var name = target.src.split("?")[0].split(ice.PT).pop()
var p = can.page.Select(can, _target, "p.title")[0]
msg.Push(mdb.TYPE, html.VIDEO) msg.Push(mdb.TYPE, html.VIDEO)
msg.Push(mdb.NAME, (p && p.innerText || html.VIDEO)+ice.PT+name) msg.Push(mdb.NAME, html.VIDEO+ice.PT+name)
msg.Push(mdb.LINK, item.src) msg.Push(mdb.LINK, target.src)
}) })
can.page.Select(can, target, html.IMG, function(target) {
can.page.Select(can, _target, html.IMG, function(item) { if (!target.src || has[target.src]) { return } has[target.src] = true
if (!item.src || has[item.src]) { return } has[item.src] = true var name = target.src.split("?")[0].split(ice.PS).pop()
var name = item.src.split("?")[0].split(ice.PS).pop()
msg.Push(mdb.TYPE, html.IMG) msg.Push(mdb.TYPE, html.IMG)
if (item.src.indexOf("data:image") == 0) { if (target.src.indexOf("data:image") == 0) {
msg.Push(mdb.NAME, item.src.slice(item.src.length-20)) msg.Push(mdb.NAME, target.src.slice(target.src.length-20))
} else { } else {
msg.Push(mdb.NAME, name||"image.jpg") msg.Push(mdb.NAME, name||"image.jpg")
} }
msg.Push(mdb.LINK, item.src) msg.Push(mdb.LINK, target.src)
}) })
}, },
change: function(can, msg, arg) { change: function(can, msg, arg) {
@ -97,23 +91,24 @@ setTimeout(function() { Volcanos({Option: function() { return [] },
}) })
}, },
info: function(can, msg, arg) {
msg.Push("title", document.title)
msg.Push("url", location.href)
},
_daemon: function(can) { _daemon: function(can) {
chrome.extension.onMessage.addListener(function(req, sender, cb) { var msg = can.request(); msg.Copy(req); can.misc.Log(req.detail, msg) chrome.extension.onMessage.addListener(function(req, sender, cb) { var msg = can.request(); msg.Copy(req); can.misc.Log(req.detail, msg)
can.core.CallFunc([can, req.detail[3]||"spide"], {can: can, msg: msg, cmds: req.detail.slice(4), arg: req.detail.slice(4), cb: function() { can.core.CallFunc([can, req.detail[0]||"spide"], {can: can, msg: msg, cmds: req.detail.slice(1), arg: req.detail.slice(1), cb: function() {
delete(msg._event), delete(msg._can), cb(msg) delete(msg._event), delete(msg._can), cb(msg)
}}) }})
}) })
}, },
_motion: function(can) { can.onmotion.float.auto(can, document.body) _motion: function(can) { can.onmotion.story.auto(can, document.body)
document.body.ondblclick = function(event) { can.onengine.signal(can, "onselection") } document.body.ondblclick = function(event) { can.onengine.signal(can, "onselection") }
can.runAction({}, ctx.COMMAND, [], function(msg) { msg.result && msg.result[0] && can.field(can, msg, msg.result) })
can.runAction({}, ctx.COMMAND, [], function(msg) {
msg.result && msg.result[0] && can.field(can, msg, msg.result)
})
}, },
}, function(can) { }, function(can) {
can.run = function(event, cmds, cb) { if (cmds[0] == "_search") { return } can.run = function(event, cmds, cb) { if (cmds[0] == "_search") { return }
var msg = can.request(event, {host: location.host}); msg.detail = can.misc.concat(can, ["page"], cmds) var msg = can.request(event, {host: location.host}); msg.detail = can.misc.concat(can, ["page"], cmds)
chrome.runtime.sendMessage(msg, function(res) { can.base.isFunc(cb) && cb(msg.Copy(res)) }) chrome.runtime.sendMessage(msg, function(res) { can.base.isFunc(cb) && cb(msg.Copy(res)) })
}, can._daemon(can), can._motion(can) }, can._motion(can), can._daemon(can)
}) }, 1) }) }, 100)

View File

@ -3,7 +3,6 @@
<head><meta charset="utf-8"></head> <head><meta charset="utf-8"></head>
<body> <body>
<script src="/page/can.js"></script> <script src="/page/can.js"></script>
<script src="/publish/chrome/chrome.js"></script> <script src="/publish/chrome/daemon.js"></script>
</body> </body>
</html> </html>

57
publish/chrome/daemon.js Normal file
View File

@ -0,0 +1,57 @@
Volcanos({
chrome: function(can, msg, arg, cb) { msg.detail = msg.detail.slice(3)
if (arg.length == 0 || arg[0] == "") {
chrome.windows.getAll(function(wins) {
can.core.List(wins, function(win) { win.wid = win.id
msg.Push(win, ["wid", "type", "state", "focused", html.LEFT||"0", html.TOP||"0", html.WIDTH, html.HEIGHT])
}), can.base.isFunc(cb) && cb(msg)
})
} else if (arg.length == 1 || arg[1] == "") {
chrome.tabs.getAllInWindow(parseInt(arg[0]), function(tabs) {
can.core.Next(tabs, function(tab, next) { var _msg = can.request(); _msg.detail = ["info"]
can._tabsend(can, _msg, function(res) { tab.tid = tab.id
msg.Push(tab, ["tid", "active", html.WIDTH, html.HEIGHT, "index"])
msg.Push("title", res && res["title"][0] || "")
msg.Push("url", res && res["url"][0] || "")
next()
}, tab.id)
}, function() { can.base.isFunc(cb) && cb(msg) })
})
} else if (arg[1] == "current") {
chrome.tabs.query({currentWindow: true, active: true}, function(tabs) { arg[1] = tabs[0].id
can._tabsend(can, msg, null, arg[1])
})
} else {
can._tabsend(can, msg, null, arg[1])
}
},
_tabsend: function(can, msg, cb, target) {
chrome.tabs.sendMessage(parseInt(target||msg.Option(ice.MSG_TARGET)), msg, cb||function(res) { msg.Copy(res), msg.Reply() })
},
_daemon: function(can) {
can.misc.WSS(can, {type: html.CHROME, name: html.CHROME}, function(event, msg, cmd, arg, cb) {
msg.Option(ice.MSG_TARGET)? can._tabsend(can, msg): can.core.CallFunc([can, cmd], {can: can, msg: msg, arg: arg, cb: cb})
})
chrome.runtime.onMessage.addListener(function(req, sender, cb) {
var msg = can.request({}, {tid: sender.tab.id, url: sender.url}); can.core.List(req.option, function(key) { msg.Option(key, req[key][0]) })
return msg._source = [sender.tab.id], can.run(msg, req.detail||[], cb), true
})
chrome.history && chrome.history.onVisited.addListener(function(item) {
can.run({}, ["sync", mdb.TYPE, mdb.LINK, mdb.NAME, item.title, mdb.LINK, item.url, "tid", item.id])
})
},
_motion: function(can) {
can.user.toast = function(can, message, title) { chrome.notifications.create(null, {
message: message, title: title||can._name, iconUrl: "/favicon.ico", type: "basic",
})}
chrome.contextMenus && chrome.contextMenus.create({title: "volcanos", onclick: function(event) {
chrome.tabs.query({currentWindow: true, active: true}, function(tabs) {
var msg = can.request(event); msg.detail = ["order"], can._tabsend(can, msg, function() {})
})
}})
},
}, function(can) {
can.run = function(event, cmds, cb) { can.misc.Run(event, can, {names: "http://localhost:9020/code/chrome/"+cmds[0]}, cmds.slice(1), cb) }
can._motion(can), can._daemon(can)
})

View File

@ -3,7 +3,7 @@
<meta charset="utf-8"> <meta charset="utf-8">
<link rel="stylesheet" type="text/css" href="/page/can.css"> <link rel="stylesheet" type="text/css" href="/page/can.css">
</head> </head>
<body style="min-width:800px; min-height:600px; overflow:auto"> <body style="width:1200px; height:600px; overflow:auto">
<script src="/page/can.js"></script> <script src="/page/can.js"></script>
<script src="/publish/chrome/popup.js"></script> <script src="/publish/chrome/popup.js"></script>
</body> </body>