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:
IT 老营长 @云轩领航-创始人 2021-11-08 08:29:49 +08:00
parent 64bd055b37
commit 27ef61e30c
7 changed files with 71 additions and 111 deletions

View File

@ -4,10 +4,7 @@
"background": {"page": "/publish/chrome/chrome.html"}, "background": {"page": "/publish/chrome/chrome.html"},
"browser_action": {"default_popup": "/publish/chrome/popup.html"}, "browser_action": {"default_popup": "/publish/chrome/popup.html"},
"content_scripts": [{"matches": ["<all_urls>"], "css": ["/publish/chrome/contexts.css"], "content_scripts": [{"matches": ["<all_urls>"], "css": ["/publish/chrome/contexts.css"],
"js": ["/proto.js", "/plugin/state.js", "/plugin/input.js", "/plugin/table.js", "js": ["/proto.js", "/publish/chrome/contexts.js", "/page/cache.js", "/frame.js"]}
"/lib/base.js", "/lib/core.js", "/lib/misc.js", "/lib/page.js", "/lib/user.js",
"/publish/chrome/contexts.js", "/frame.js"
]}
], ],
"permissions": [ "permissions": [
"tabs", "tabs",

View File

@ -167,9 +167,10 @@ var Volcanos = shy("火山架", {iceberg: "/chat/", volcano: "/frame.js", args:
}; libs = libs.concat(Config.plugin, Config.main.list) }; libs = libs.concat(Config.plugin, Config.main.list)
// 根模块 // 根模块
name = Config.name, can = {_follow: Config.name, _target: Config.target||document.body}, cb = function(can) { _can_name = "", name = Config.name||"chat", cb = can||function(can) {
can.onengine._init(can, can.Conf(Config), Config.panels, Config._init, can._target) can.onengine._init(can, can.Conf(Config), Config.panels, Config._init, can._target)
}, _can_name = "", can._root = can }, can = {_follow: name, _target: Config.target||document.body}, can._root = can
for (var k in Config) { can[k] = Config[k] }
} }
can = can||{} can = can||{}
@ -190,6 +191,9 @@ var Volcanos = shy("火山架", {iceberg: "/chat/", volcano: "/frame.js", args:
typeof cb == lang.FUNCTION && setTimeout(function() { cb(can) }, 10) typeof cb == lang.FUNCTION && setTimeout(function() { cb(can) }, 10)
return // 加载完成 return // 加载完成
} }
if (!libs[0]) { return can.require(libs.slice(1), cb, each) }
libs[0] = libs[0].toLowerCase() libs[0] = libs[0].toLowerCase()
// 请求模块 // 请求模块
@ -236,7 +240,9 @@ var Volcanos = shy("火山架", {iceberg: "/chat/", volcano: "/frame.js", args:
if (can._follow) { libs = libs.concat(meta.libs, meta.volcano) } if (can._follow) { libs = libs.concat(meta.libs, meta.volcano) }
if (libs && libs.length > 0) { if (libs && libs.length > 0) {
for (var i = 0; i < libs.length; i++) { for (var i = 0; i < libs.length; i++) {
if (libs[i] == "") { if (libs[i] == undefined) {
} else if (libs[i] == "") {
libs[i] = _can_path.replace(".js", ".css") libs[i] = _can_path.replace(".js", ".css")
} else if (libs[i][0] != "/" && libs[i].indexOf("http") != 0) { } else if (libs[i][0] != "/" && libs[i].indexOf("http") != 0) {
libs[i] = _can_path.slice(0, _can_path.lastIndexOf("/")+1)+libs[i] libs[i] = _can_path.slice(0, _can_path.lastIndexOf("/")+1)+libs[i]

View File

@ -1,12 +1,8 @@
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<head> <head><meta charset="utf-8"></head>
<meta charset="utf-8"> <body><script src="/proto.js"></script>
</head>
<body>
<script src="/proto.js"></script>
<script src="/publish/chrome/chrome.js"></script> <script src="/publish/chrome/chrome.js"></script>
</body> </body>
<html> </html>

View File

@ -1,51 +1,36 @@
Volcanos("chrome", { Volcanos({
pwd: function(can, msg, cmds, cb) { pwd: function(can, msg, arg) {
console.log(cmds) msg.Push("hi", "hello")
cb() msg.Echo("hello")
}, },
chrome: function(can, msg, cmds, cb) { chrome: function(can, msg, arg, cb) {
if (cmds.length == 0) { // 窗口列表 if (arg.length == 0) { // 窗口列表
chrome.windows.getAll(function(wins) { chrome.windows.getAll(function(wins) {
can.core.List(wins, function(win) { win.wid = win.id can.core.List(wins, function(win) { win.wid = win.id
msg.Push(win, ["wid", "state", "left", "top", "width", "height"]) msg.Push(win, ["wid", "state", "left", "top", "width", "height"])
}) })
can.base.isFunc(cb) && cb(msg) can.base.isFunc(cb) && cb(msg)
}) })
return } else if (arg.length == 1) { // 标签列表
} chrome.tabs.getAllInWindow(parseInt(arg[0]), function(tabs) {
if (cmds.length == 1) { // 标签列表
chrome.tabs.getAllInWindow(parseInt(cmds[0]), function(tabs) {
can.core.List(tabs, function(tab) { tab.tid = tab.id can.core.List(tabs, function(tab) { tab.tid = tab.id
msg.Push(tab, ["tid", "active", "width", "height", "index", "title", "url"]) msg.Push(tab, ["tid", "active", "width", "height", "index", "title", "url"])
}) })
can.base.isFunc(cb) && cb(msg) can.base.isFunc(cb) && cb(msg)
}) })
return } else if (arg[1] == "") { // 当前标签
} chrome.tabs.query({currentWindow: true, active: true}, function(tabs) { arg[1] = tabs[0].id
chrome.tabs.sendMessage(parseInt(arg[1]), msg, function(res) {
if (cmds[1] == "") { // 当前标签 can.base.isFunc(cb) && cb(msg.Copy(res))
chrome.tabs.query({currentWindow: true, active: true}, function(tabs) { cmds[1] = tabs[0].id
chrome.tabs.sendMessage(parseInt(cmds[1]), msg, function(res) {
msg.Copy(res), can.base.isFunc(cb) && cb(msg)
}) })
}) })
} else { } else {
chrome.tabs.sendMessage(parseInt(cmds[1]), msg, function(res) { chrome.tabs.sendMessage(parseInt(arg[1]), msg, function(res) {
can.base.isFunc(cb) && cb(msg.Copy(res)) can.base.isFunc(cb) && cb(msg.Copy(res))
}) })
} }
}, },
bookmark: function(msg, cmds, cb) { }, function(can) {
chrome.bookmarks.getSubTree(cmds[0]||"0", function(labs) {
for (var i = 0; i < labs.length; i++) {labs[i].pid = labs[i].parentId
msg.Push("time", can.base.Time(labs[i].dateAdded))
msg.Push(labs[i], ["pid", "id", "index", "title", "url"])
labs = labs.concat(labs[i].children||[])
}
can.base.isFunc(cb) && cb(msg)
})
},
}, ["/lib/base.js", "/lib/core.js", "/lib/misc.js", "/lib/page.js", "/lib/user.js"], function(can) {
can.run = function(event, cmds, cb) { 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)
}, },
@ -53,7 +38,7 @@ Volcanos("chrome", {
can.run({}, ["sync", kit.MDB_TYPE, "link", kit.MDB_NAME, item.title, kit.MDB_TEXT, item.url, "tid", item.id]) can.run({}, ["sync", kit.MDB_TYPE, "link", kit.MDB_NAME, item.title, kit.MDB_TEXT, item.url, "tid", item.id])
}) })
can.user.toast = function(message, title) {chrome.notifications.create(null, { can.user.toast = function(can, message, title) { chrome.notifications.create(null, {
message: message, title: title||can._name, iconUrl: "/favicon.ico", type: "basic", message: message, title: title||can._name, iconUrl: "/favicon.ico", type: "basic",
})}, })},
can.misc.WSS(can, {type: "chrome", name: "chrome"}, function(event, msg, cmd, arg) { can.misc.WSS(can, {type: "chrome", name: "chrome"}, function(event, msg, cmd, arg) {
@ -63,7 +48,7 @@ Volcanos("chrome", {
}) })
return return
} }
can.core.CallFunc([can, cmd], {can: can, msg: msg, cmds: arg, cb: function() { msg.Reply() }}) can.core.CallFunc([can, cmd], {can: can, msg: msg, arg: arg, cb: function() { msg.Reply() }})
}) })
chrome.runtime.onMessage.addListener(function(req, sender, cb) { chrome.runtime.onMessage.addListener(function(req, sender, cb) {

View File

@ -2,6 +2,9 @@ fieldset.contexts {
color:white; color:white;
position:fixed; position:fixed;
background:radial-gradient(black, #00000073); background:radial-gradient(black, #00000073);
top:100px;
left:100px;
z-index:10;
} }
fieldset.contexts legend { fieldset.contexts legend {
text-align:left; text-align:left;

View File

@ -1,6 +1,4 @@
setTimeout(function() { setTimeout(function() { Volcanos({
Volcanos("chrome", {
_follow: "chrome",
pwd: function(can, msg, arg) { pwd: function(can, msg, arg) {
msg.Push("hi", "hello") msg.Push("hi", "hello")
msg.Echo("hello") msg.Echo("hello")
@ -10,14 +8,45 @@ Volcanos("chrome", {
can.page.Modify(can, target, can.base.Obj(arg[1])) can.page.Modify(can, target, can.base.Obj(arg[1]))
}) })
}, },
field: function(can, msg, arg) {
can.onappend.plugin(can, {type: "contexts", index: arg[0], args: can.base.Obj(arg[1])}, function(sub, meta) {
can.page.Modify(can, sub._target, {style: {left: msg.Option("left"), top: msg.Option("top"), right: msg.Option("right"), bottom: msg.Option("bottom")}})
can.page.Modify(can, sub._output, {style: {"max-height": window.innerHeight, "max-width": window.innerWidth}})
can.onmotion.move(can, sub._target, {})
sub._legend.onclick = function(event) {
can.onmotion.toggle(can, sub._option)
can.onmotion.toggle(can, sub._action)
can.onmotion.toggle(can, sub._output)
can.onmotion.toggle(can, sub._status)
}, msg.Option("selection")||sub._legend.onclick()
can.onmotion.float.auto(can, sub._target, chat.CARTE)
sub.run = function(event, cmds, cb) {
can.run(event, can.misc.Concat([ctx.ACTION, cli.RUN, meta.index], cmds), cb)
}
msg.Option("selection") && (document.body.ondblclick = function(event) {
sub.Option(msg.Option("selection"), window.getSelection()), sub.Update()
})
sub.onaction["保存参数"] = function(event) {
can.request(event, {zone: location.host, id: msg.Option(kit.MDB_ID)})
can.run(event, [chat.FIELD, mdb.MODIFY, "top", sub._target.offsetTop])
can.run(event, [chat.FIELD, mdb.MODIFY, "left", sub._target.offsetLeft])
can.run(event, [chat.FIELD, mdb.MODIFY, "args", JSON.stringify(sub.Input([], true))])
can.user.toast(can, "保存成功")
}
}, document.body)
},
order: function(can, msg, arg) { order: function(can, msg, arg) {
var ui = can.user.input(event, can, ["index", "args", "selection"], function(event, button, data, list, args) { var ui = can.user.input(event, can, ["index", "args", "selection"], function(event, button, data, list, args) {
can.run(event, [chat.FIELD, mdb.INSERT, kit.MDB_ZONE, location.hostname].concat(args), function(res) { can.run(event, [chat.FIELD, mdb.INSERT, kit.MDB_ZONE, location.host].concat(args), function(res) {
can.user.toast(can, "添加成功") can.user.toast(can, "添加成功")
}) })
}) }); can.page.Modify(can, ui._target, {style: {left: 200, top: 200}})
can.page.Modify(can, ui._target, {style: {left: 200, top: 200}})
}, },
spide: function(can, msg, arg) { var has = {} spide: function(can, msg, arg) { var has = {}
can.page.Select(can, document.body, html.VIDEO, function(item) { can.page.Select(can, document.body, html.VIDEO, function(item) {
if (!item.src || has[item.src]) { return } has[item.src] = true if (!item.src || has[item.src]) { return } has[item.src] = true
@ -49,47 +78,8 @@ Volcanos("chrome", {
msg.Push(kit.MDB_LINK, item.src) msg.Push(kit.MDB_LINK, item.src)
}) })
}, },
field: function(can, msg, arg) {
can.onappend.plugin(can, {index: arg[0], arg: can.base.Obj(arg[1])}, function(sub, meta) {
can.page.ClassList.add(can, sub._target, "contexts")
var top = msg.Option("top")||400
var left = msg.Option("left")||0
can.onmotion.float.auto(can, sub._output, "carte")
can.onmotion.float.auto(can, document.body, "carte")
can.page.Modify(can, sub._target, {style: {"top": top, "left": left}})
can.page.Modify(can, sub._output, {style: {
"max-height": window.innerHeight-top-80,
"max-width": window.innerWidth,
}})
sub._legend.onclick = function(event) {
can.onmotion.toggle(can, sub._option)
can.onmotion.toggle(can, sub._action)
can.onmotion.toggle(can, sub._output)
can.onmotion.toggle(can, sub._status)
}, msg.Option("selection")||sub._legend.onclick()
sub.run = function(event, cmds, cb) { if (cmds[0] == "_search") { return }
can.run(event, can.misc.Concat([ctx.ACTION, cli.RUN, meta.index], cmds), cb)
}
can.onmotion.move(can, sub._target, {})
msg.Option("selection") && (document.body.ondblclick = function(event) {
sub.Option(msg.Option("selection"), window.getSelection())
sub.Update()
})
sub.onaction["保存参数"] = function(event) {
can.request(event, {zone: location.hostname, id: msg.Option(kit.MDB_ID)})
can.run(event, [chat.FIELD, mdb.MODIFY, "top", sub._target.offsetTop])
can.run(event, [chat.FIELD, mdb.MODIFY, "left", sub._target.offsetLeft])
can.run(event, [chat.FIELD, mdb.MODIFY, "args", JSON.stringify(sub.Input([], true))])
can.user.toast(can, "保存成功")
}
}, document.body)
},
Option: function() { return [] }, Option: function() { return [] },
}, [], function(can) { }, 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, 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)
@ -97,11 +87,10 @@ Volcanos("chrome", {
}) })
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, {hostname: location.hostname}); msg.detail = can.misc.Concat(["page"], cmds) var msg = can.request(event, {host: location.host}); msg.detail = can.misc.Concat(["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.run({}, [ctx.ACTION, ctx.COMMAND], function(msg) { can.run({}, [ctx.ACTION, ctx.COMMAND], function(msg) {
msg.result && msg.result[0] && can.field(can, msg, msg.result) msg.result && msg.result[0] && can.field(can, msg, msg.result)
}) })
}) }) }, 100)
}, 100)

View File

@ -4,23 +4,7 @@ Volcanos({name: "popup", iceberg: "http://localhost:9020/chat/", panels: [
{name: "Action", help: "工作台", pos: chat.MAIN}, {name: "Action", help: "工作台", pos: chat.MAIN},
{name: "Search", help: "搜索框", pos: chat.AUTO}, {name: "Search", help: "搜索框", pos: chat.AUTO},
{name: "Footer", help: "状态条", pos: chat.FOOT, state: ["ncmd"]}, {name: "Footer", help: "状态条", pos: chat.FOOT, state: ["ncmd"]},
], main: {name: "Header", list: ["/publish/order.js"]}, plugin: [ ], main: {name: "Header", list: ["/publish/order.js"]}, plugin: [], river: {
"/plugin/state.js",
"/plugin/input.js",
"/plugin/table.js",
"/plugin/input/key.js",
"/plugin/input/date.js",
"/plugin/story/spide.js",
"/plugin/story/trend.js",
"/plugin/local/code/inner.js",
"/plugin/local/code/vimer.js",
"/plugin/local/wiki/draw/path.js",
"/plugin/local/wiki/draw.js",
"/plugin/local/wiki/word.js",
"/plugin/local/chat/div.js",
"/plugin/local/team/plan.js",
"/plugin/input/province.js",
], river: {
serivce: {name: "运营群", storm: { serivce: {name: "运营群", storm: {
wx: {name: "公众号 wx", action: [ wx: {name: "公众号 wx", action: [
{name: "微信公众号", help: "wx", index: "web.wiki.word", args: ["usr/icebergs/misc/wx/wx.shy"]}, {name: "微信公众号", help: "wx", index: "web.wiki.word", args: ["usr/icebergs/misc/wx/wx.shy"]},