From 6d3e088f3ae2f6a224364a776defc34be074e6ae Mon Sep 17 00:00:00 2001 From: shaoying Date: Sun, 27 Dec 2020 03:41:42 +0800 Subject: [PATCH] add share --- frame.js | 26 +++++------ index.css | 21 +++++++-- index.html | 1 + lib/core.js | 10 ++++- lib/misc.js | 2 +- lib/user.js | 16 ++++--- manifest.json | 6 --- page/share.css | 17 ------- page/share.html | 6 +-- page/share.js | 12 +++-- pane/Action.js | 34 +++++++++++--- pane/River.js | 25 ++++++----- plugin/local/code/inner.js | 20 ++++----- plugin/story/trend.js | 13 ++++-- proto.js | 11 +++-- publish/chrome/chrome.html | 3 +- publish/chrome/chrome.js | 92 +++++++++++++++----------------------- publish/chrome/contexts.js | 29 +++--------- publish/chrome/popup.html | 2 +- 19 files changed, 167 insertions(+), 179 deletions(-) diff --git a/frame.js b/frame.js index e6bae3fa..6f4263ce 100644 --- a/frame.js +++ b/frame.js @@ -35,6 +35,8 @@ Volcanos("onengine", {help: "解析引擎", list: [], _init: function(can, meta, }, search: function(event, can, msg, pane, cmds, cb) { + can.base.Log(can._name, "search", cmds) + var sub, mod = can, fun = can, key = ""; can.core.List(cmds[1].split("."), function(value) { fun && (sub = mod, mod = fun, fun = mod[value], key = value) }); if (!sub || !mod || !fun) { can.base.Warn("not found", cmds[1]); return } @@ -101,9 +103,6 @@ Volcanos("onengine", {help: "解析引擎", list: [], _init: function(can, meta, }}, "project": {name: "研发群", storm: { "studio": {name: "研发 studio", action: [ - {name: "route", help: "路由器", index: "web.route"}, - {name: "tmux", help: "命令行", index: "web.code.tmux.session"}, - {name: "inner", help: "编辑器", index: "web.code.inner", args: ["src/", "main.go"]}, {name: "vimer", help: "编辑器", index: "web.code.vimer", args: ["src/", "main.go"]}, {name: "repos", help: "代码库", index: "web.code.git.status"}, {name: "total", help: "统计量", index: "web.code.git.total"}, @@ -420,27 +419,24 @@ Volcanos("onlayout", {help: "页面布局", list: [], _init: function(can, targe }) can.page.Select(can, target, ["fieldset.left", "fieldset.right"], function(field, index) { - var border = field.offsetHeight - field.clientHeight - can.page.Modify(can, field, {style: {height: height-4}}) + can.page.Modify(can, field, {style: {height: height}}) can.page.Select(can, field, "div.output", function(output) { - var border = output.offsetHeight - output.clientHeight - can.page.Modify(can, output, {style: {height: height-26}}) + can.page.Modify(can, output, {style: {height: height-32}}) }) - width -= field.offsetWidth }) + can.onengine.trigger(can, can.request(event, {width: width, height: height}), "resize") + can.Action._width = width, can.Action._height = height if (can.user.isMobile) { return } can.page.Select(can, target, ["fieldset.middle"], function(field, index) { - var border = field.offsetHeight - field.clientHeight - can.page.Modify(can, field, {style: {height: height-border*2}}) + can.page.Modify(can, field, {style: {height: height}}) }) can.page.Select(can, target, ["fieldset.middle>div.output"], function(output) { - var border = output.offsetHeight - output.clientHeight - can.page.Modify(can, output, {style: {height: height-border*2-14}}) + can.page.Modify(can, output, {style: {height: height}}) }) can.core.List(can.onlayout.resize.list, function(item) { @@ -498,11 +494,15 @@ Volcanos("onkeypop", {help: "键盘交互", list: [], _init: function(can, targe }, _mode: { normal: { - j: function(event, can, target) { target.scrollBy(0, 30) }, + j: function(event, can, target) { target.scrollBy(0, event.ctrlKey? 300: 30) }, k: function(event, can, target) { target.scrollBy(0, -30) }, + b: function(event, can, target) { can.run(event, ["search", "Header.onaction.black"]) }, w: function(event, can, target) { can.run(event, ["search", "Header.onaction.white"]) }, + s: function(event, can, target) { can.run(event, ["search", "River.ondetail.添加应用"]) }, + t: function(event, can, target) { can.run(event, ["search", "River.ondetail.添加工具"]) }, + " ": function(event, can, target) { can.page.Select(can, document.body, "fieldset.pane.Header div.search input", function(target) { target.focus() diff --git a/index.css b/index.css index e14b86c8..7c292487 100644 --- a/index.css +++ b/index.css @@ -5,6 +5,9 @@ body.mobile fieldset.Header.head { background-color:#000000b8; z-index:10; } +body.mobile fieldset.Header.head>div.output { + height:48px; +} body.mobile fieldset.Footer.foot { position:fixed; bottom:0px; width:-webkit-fill-available; @@ -28,6 +31,9 @@ body.mobile select { body.mobile input { font-size:18px; } +body.mobile div.carte { + font-size:24px; +} body { margin:0; padding:0; @@ -91,6 +97,9 @@ table td { table td:hover { background-color:red; } +table td.select { + background-color:red; +} h1 { margin:0; @@ -178,20 +187,21 @@ fieldset>div.output div.project div.list { fieldset.input { background-color:#30a7a93d; position:fixed; - z-index:9; + z-index:100; } fieldset.input.key { - z-index:10; + z-index:90; } fieldset.input.date { - z-index:11; + z-index:80; } div.carte { - position:absolute; + position:fixed; background:#295b61; color:white; padding:4px; + z-index:100; } div.carte div.item { padding:3px 12px; @@ -238,6 +248,9 @@ div.toast div.progress div.current { height:10px; } +body.black a { + color:yellow; +} body.white { background-color:#2f3638; color:white; diff --git a/index.html b/index.html index f04bd182..f60dd445 100644 --- a/index.html +++ b/index.html @@ -3,6 +3,7 @@ volcanos + diff --git a/lib/core.js b/lib/core.js index 7c5bd457..708a1215 100644 --- a/lib/core.js +++ b/lib/core.js @@ -74,9 +74,9 @@ Volcanos("core", {help: "核心模块", var ls = func.toString(); ls = ls.split(")")[0], ls = ls.split("(")[1] - var msg = args["msg"], echo = false + var msg = args["msg"], can = args["can"], echo = false var list = []; this.List(ls.split(","), function(item) { item = item.trim() - list.push(args[item]||msg&&msg.Option(item)||args) + list.push(args[item] || msg&&msg.Option(item) || can&&can.Conf(item) || args) if (item == "cb") { echo = true } }) @@ -159,6 +159,12 @@ Volcanos("core", {help: "核心模块", setTimeout(function() { loop(timer, 0) }, interval.value||interval[0]) return timer }), + Delay: function(list, interval, cb, cbs) { + list.push(cb); this.Timer(interval, function() { + var cb = list.pop(); list.length = 0 + typeof cb == "function" && cb() + }, cbs) + }, Copy: function(to, from, fields) { var list = [] diff --git a/lib/misc.js b/lib/misc.js index 6a1cb836..d7c867a6 100644 --- a/lib/misc.js +++ b/lib/misc.js @@ -120,7 +120,7 @@ Volcanos("misc", {help: "工具模块", Message: function(event, can) { var msg var socket = new WebSocket(can.base.URLMerge(url, args)) socket.onclose = function() { can.base.Log("wss", "close", args) typeof onclose == "function"? onclose(socket): can.core.Timer(1000, function() { - can.misc.WSS(can, url, args, cb, onopen, onerror, onclose) + can.misc.WSS(can, args, cb, onopen, onerror, onclose) }) }, socket.onerror = function() { can.base.Log("wss", "error", args) typeof onerror == "function"? onerror(socket): socket.close() diff --git a/lib/user.js b/lib/user.js index 5f2f3442..f2f74955 100644 --- a/lib/user.js +++ b/lib/user.js @@ -48,6 +48,9 @@ Volcanos("user", {help: "用户模块", agent: { }, trans: function(can, text) { + if (typeof text == "function") { + text = text.name || "" + } return can._trans && can._trans[text] || text }, topic: function(can, name) { @@ -80,10 +83,11 @@ Volcanos("user", {help: "用户模块", agent: { share: function(can, msg, cmd) { can.run(msg._event, cmd||["action", "share"], function(msg) { var src = can.user.Share(can, {_path: "/share/"+msg.Result()}, true) - var ui = can.user.toast(can, {title: can.page.Format("a", "/?share="+msg.Result(), "share"), text: can.page.Format("img", src+"/share"), - width: 300, height: 300, duration: 100000, button: [{button: ["确定", function(event) { - ui.Close() - }]}] }) + var ui = can.user.toast(can, { + title: can.page.Format("a", "/share?share="+msg.Result(), "share"), + text: can.page.Format("img", src+"/share"), width: 300, height: 300, duration: 100000, + button: [{button: ["确定", function(event) { ui.Close() }]}], + }) }) }, login: function(can, cb) { @@ -118,6 +122,7 @@ Volcanos("user", {help: "用户模块", agent: { can.page.Remove(can, ui.first) }, list: can.core.List(list, function(item) { return {view: "item", list: [typeof item == "string"? /* button */ {text: item, click: function(event) { + can.user.isMobile && can.page.Remove(can, ui.first) typeof cb == "function" && cb(event, item, meta) }}: item.args? /* input */ {text: item.name, click: function(event) { can.user.input(event, can, item.args, cb) @@ -141,8 +146,9 @@ Volcanos("user", {help: "用户模块", agent: { } var msg = can.request(event) - var x = event.clientX, y = event.clientY; y += 10; if (x > 600) { x -= 160 } + var x = event.clientX||200, y = event.clientY||48; y += 10; if (x > 600) { x -= 160 } if (can.user.isMobile) { x = 100, y = 100 } + var button; var ui = can.page.Append(can, document.body, [{view: ["input", "fieldset"], style: {left: x+"px", top: y+"px"}, list: [ {view: ["option", "table"], list: can.core.List(form, function(item) { if (item.button) { button = can.core.List(item.button, function(item) { diff --git a/manifest.json b/manifest.json index e7324870..3e2a53ce 100644 --- a/manifest.json +++ b/manifest.json @@ -2,14 +2,8 @@ "manifest_version": 2, "name": "volcanos", "version": "0.0.1", - "icons": { - "16": "favicon.png", - "48": "favicon.png", - "128": "favicon.png" - }, "background": {"page": "/publish/chrome/chrome.html"}, "browser_action": { - "default_icon": "/favicon.png", "default_popup": "/publish/chrome/popup.html" }, "content_scripts": [ diff --git a/page/share.css b/page/share.css index 112b0aa5..e69de29b 100644 --- a/page/share.css +++ b/page/share.css @@ -1,17 +0,0 @@ -body { - background:black; - padding:0; - margin:0; -} -fieldset { - color:cyan; - padding:2px; -} -legend { - margin-left:10px; -} -div.hidden { - display:none; -} - - diff --git a/page/share.html b/page/share.html index c565d338..8e4bc2d1 100644 --- a/page/share.html +++ b/page/share.html @@ -1,15 +1,15 @@ + - volcanos - + - + diff --git a/page/share.js b/page/share.js index 772f1146..d91d7b51 100644 --- a/page/share.js +++ b/page/share.js @@ -1,13 +1,11 @@ -Volcanos({name: "demo", volcano: "/frame.js", iceberg: "/chat/", intshell: "plug.sh", - libs: ["/lib/base", "/lib/core", "/lib/misc", "/lib/page", "/lib/user"], panes: [ - {type: "pane", name: "Action", help: "工作台", pos: "middle", list: ["/pane/Action.js", "/pane/Action.css"]}, +Volcanos({name: "chat", iceberg: "/chat/", volcano: "/frame.js", + libs: ["/lib/base.js", "/lib/core.js", "/lib/misc.js", "/lib/page.js", "/lib/user.js"], panes: [ + {name: "Action", help: "工作台", pos: "middle"}, ], main: {name: "Action", engine: "remote", list: ["/publish/order.js"]}, plugin: [ "/plugin/state.js", "/plugin/input.js", "/plugin/table.js", - "/plugin/input/key", - "/plugin/input/date", - "/plugin/input/upload", - "/plugin/input/province", + "/plugin/input/key.js", + "/plugin/input/date.js", ], }) diff --git a/pane/Action.js b/pane/Action.js index 650ae88b..3d55a947 100644 --- a/pane/Action.js +++ b/pane/Action.js @@ -1,8 +1,5 @@ (function() { const RIVER = "river", STORM = "storm", ACTION = "action" Volcanos("onimport", {help: "导入数据", list: [], _init: function(can, msg, list, cb, target) { - can._target.ontouchstart = function(event) { - can.run({}, ["search", "River.onmotion.hidden"]) - } var river = can.Conf(RIVER), storm = can.Conf(STORM) can.onmotion.clear(can), can.core.Next(msg.Table(), function(value, next) { value.feature = can.base.Obj(value.feature||value.meta||"{}", {}) @@ -19,10 +16,10 @@ Volcanos("onimport", {help: "导入数据", list: [], _init: function(can, msg, }, _plugin: function(can, target, river, storm, value) { value.name = value.name.split(" ")[0] value.action = value.id || value.index || value.key+"."+value.name - value.width = can._target.offsetWidth value.type = "plugin" // 添加插件 + value.width = parseInt(can.Conf("width")), value.height = parseInt(can.Conf("height")) can.onappend._init(can, value, ["/plugin/state.js"], function(plugin) { can._plugins = (can._plugins||[]).concat([plugin]) plugin.run = function(event, cmds, cb, silent) { var msg = plugin.request(event); cmds = cmds || [] @@ -55,6 +52,27 @@ Volcanos("onengine", {help: "解析引擎", list: [], }, }) Volcanos("onaction", {help: "交互操作", list: [], _init: function(can, msg, list, cb, target) { + var share = can.user.Search(can, "share"); if (share) { + can.run({}, ["_share", share], function(msg) { + can.user.title(msg.Option("title")) + can.Conf(RIVER, "_share"), can.Conf(STORM, share) + can.onimport._init(can, msg, [], cb, can._output) + }) + } + + can.Conf({width: can._output.offsetWidth-32, height: window.innerHeight}) + can.onengine.listen(can, "resize", function(width, height) { + can.Conf({width: width, height: height}) + }) + + + can._target.ontouchstart = function(event) { + can.run({}, ["search", "River.onmotion.hidden"]) + can.page.Select(can, document.body, "div.carte", function(item) { + can.page.Remove(can, item) + }) + } + can.onengine.listen(can, "storm.select", function(msg, river, storm) { can.page.Cache(can.Conf(RIVER)+"."+can.Conf(STORM), can._output, can._output.scrollTop+1) can.Conf(RIVER, river), can.Conf(STORM, storm) @@ -63,9 +81,15 @@ Volcanos("onaction", {help: "交互操作", list: [], _init: function(can, msg, if (position) { can._output.scrollTo(0, position-1); return } can.run({}, [river, storm], function(msg) { - can.onimport._init(can, msg, list, cb, can._output) + if (msg.append && msg[msg.append[0]] && msg[msg.append[0]].length > 0) { + can.onimport._init(can, msg, list, cb, can._output) + } else { + var msg = can.request({}, {river: river, storm: storm}) + can.run(msg._event, ["search", "River.ondetail.添加工具"]) + } }) }) + can.onengine.listen(can, "search", function(msg, word) { if (word[0] != "*" && word[0] != "fieldset") { return } diff --git a/pane/River.js b/pane/River.js index d24145fe..3a6a35d3 100644 --- a/pane/River.js +++ b/pane/River.js @@ -1,9 +1,12 @@ (function() { const RIVER = "river", STORM = "storm", POD = "pod" Volcanos("onimport", {help: "导入数据", list: [], _init: function(can, msg, list, cb, target) { can._main_river = can.user.Search(can, RIVER) || (can.user.isMobile||can.user.isExtension? "product": "project") - can._main_storm = can.user.Search(can, STORM) || (can.user.isMobile||can.user.isExtension? "office": "studio") + can._main_storm = can.user.Search(can, STORM) || (can.user.isMobile? "office": can.user.isExtension? "chrome": "studio") - can.run({}, ["search", "Header.onimport.menu", ["群组", "添加用户", "添加设备", "添加应用"], ["应用", "添加工具"]], function(event, item) { + can.run({}, ["search", "Header.onimport.menu", + ["添加", "创建群组", "添加用户", "添加设备", "添加应用", "添加工具"], + ["共享", "共享群组", "共享应用", "共享工具"], + ], function(event, item) { var cb = can.ondetail[item]; typeof cb == "function" && cb(event, can, item, can.Conf(RIVER), can.Conf(STORM)) }) @@ -57,7 +60,7 @@ Volcanos("onaction", {help: "控件交互", list: [], _init: function(can, msg, can.user.title(can.user.Search(can, POD) || storm.name) // 右键点击 var ui = can.user.carte(event, can, can.ondetail, ["共享应用", "添加工具", "保存参数", "重命名应用", "删除应用"], function(ev, item, meta) { - can.ondetail[item](event, can, item, storm.hash, river) + can.ondetail[item](event, can, item, river, storm.hash) }); can.page.Modify(can, ui.first, {style: {left: can._target.offsetWidth}}) }} }) }]).first, list.children.length > 0 && list.children[select].click() @@ -90,6 +93,8 @@ Volcanos("onaction", {help: "控件交互", list: [], _init: function(can, msg, "刷新": function(event, can) { can.user.Search(can, {river: can.Conf(RIVER), storm: can.Conf(STORM)}) }, }) Volcanos("ondetail", {help: "菜单交互", list: ["共享群组", "添加用户", "添加设备", "添加应用", "重命名群组", "删除群组"], + "创建群组": function(event, can) { can.onaction.create(event, can) }, + "共享群组": function(event, can, button, river) { can.user.input(event, can, [ {_input: "text", name: "name", value: river}, @@ -138,20 +143,18 @@ Volcanos("ondetail", {help: "菜单交互", list: ["共享群组", "添加用户 }) }, - "共享应用": function(event, can, button, storm, river) { + "共享应用": function(event, can, button, river, storm) { can.user.input(event, can, [ {_input: "text", name: "name", value: storm}, - {_input: "text", name: "username", value: "@key=hi"}, - {_input: "text", name: "userrole", value: "@key=void"}, ], function(event, button, meta, list) { var msg = can.request(event) can.user.share(can, msg, [river, "action", "share", "type", "storm", "name", meta.name, - "storm", storm, "username", meta.username, "userrole", meta.userrole, + "storm", storm, ]) return true }) }, - "添加工具": function(event, can, button, storm, river) { + "添加工具": function(event, can, button, river, storm) { can.user.select(event, can, "command", "pod,name,text", function(item, next) { can.run({}, [river, "tool", "action", "insert", "hash", storm].concat(["pod", item[0], "ctx", item[2], "cmd", item[1]]), function(msg) { next() @@ -160,7 +163,7 @@ Volcanos("ondetail", {help: "菜单交互", list: ["共享群组", "添加用户 can.user.Search(can, {river: river, storm: storm}) }) }, - "保存参数": function(event, can, button, storm, river) { + "保存参数": function(event, can, button, river, storm) { can.run(event, ["search", "Action.onexport.args"], function(item, next) { var msg = can.request({}, {hash: storm, id: item.dataset.id}) can.run({}, [river, "tool", "action", "modify", "arg", item.dataset.args], function(msg) { @@ -168,7 +171,7 @@ Volcanos("ondetail", {help: "菜单交互", list: ["共享群组", "添加用户 }) }) }, - "重命名应用": function(event, can, button, storm, river) { + "重命名应用": function(event, can, button, river, storm) { can.user.input(event, can, ["name"], function(event, button, meta, list) { var msg = can.request(event, {hash: storm}) can.run(event, [river, "tool", "action", "modify", "name", meta.name], function(msg) { @@ -176,7 +179,7 @@ Volcanos("ondetail", {help: "菜单交互", list: ["共享群组", "添加用户 }) }) }, - "删除应用": function(event, can, button, storm, river) { + "删除应用": function(event, can, button, river, storm) { var msg = can.request(event, {hash: storm}) can.run(event, [river, "tool", "action", "remove"], function(msg) { can.user.Search(can, {river: river}) diff --git a/plugin/local/code/inner.js b/plugin/local/code/inner.js index 098a343f..99441c36 100644 --- a/plugin/local/code/inner.js +++ b/plugin/local/code/inner.js @@ -1,19 +1,17 @@ Volcanos("onimport", {help: "导入数据", _init: function(can, msg, list, cb, target) { - var width = can.Conf("width"), height = can.Conf("height") + var list = []; can.onengine.listen(can, "resize", function(width, height) { + can.Conf({width: width, height: height}), can.core.Delay(list, 100, function() { + can.onimport._init(can, msg, list, cb, target) + }) + }) + var width = can.Conf("width"), height = can.Conf("height") can.ui = can.page.Appends(can, target, [ {type: "table", list: [{type: "tr", list: [ - {type: "td", list: [{view: "project", style: {"max-height": height-480, display: "none"}} ]}, - {type: "td", list: [{view: "profile", style: {"max-height": height-480}, list: [ + {type: "td", list: [{view: "project", style: {"max-height": height-240, display: "none"}} ]}, + {type: "td", list: [{view: "profile", style: {"max-height": height-240}, list: [ {view: ["content", "table"]}, - ]}], style: {"min-width": width-120, "max-width": width-60}, _init: function(item) { - can.onlayout.resize(function(width, height) { - width = can.Conf("width", width), height = can.Conf("height", height) - can.page.Modify(can, item, {style: { - "min-width": width-120, "max-width": width-60, - }}) - }) - }}, + ]}], style: {"min-width": width-60, "max-width": width-30}}, ]}, ]}, {view: "search", style: {display: "none"}, list: [{view: "action", list: [ {input: ["word", function(event) { diff --git a/plugin/story/trend.js b/plugin/story/trend.js index d8f6b5a2..8556c1df 100644 --- a/plugin/story/trend.js +++ b/plugin/story/trend.js @@ -1,5 +1,10 @@ -Volcanos("onimport", {help: "导入数据", list: [], - _init: function(can, msg, list, cb, target) { can._output.innerHTML = "" +Volcanos("onimport", {help: "导入数据", list: [], _init: function(can, msg, list, cb, target) { can._output.innerHTML = "" + var list = []; can.onengine.listen(can, "resize", function(width, height) { + can.Conf({width: width, height: height}), can.core.Delay(list, 100, function() { + can.onimport._init(can, msg, list, cb, target) + }) + }) + if (msg.Option("_display") == "table") { can.onappend.table(can, msg, can._target, "table", function(value, key) { return {text: [value, "td"], click: function(event) { @@ -84,7 +89,7 @@ Volcanos("onaction", {help: "组件菜单", list: ["编辑", "清空", ["view", var space = 10 var view = parseInt(can.Action("height")) - var max = parseInt(can.Conf("width"))-100 + var max = parseInt(can.Conf("width"))-120 var step = parseInt(max / can.list.length)||2 var width = can.list.length * step + space * 2 @@ -135,7 +140,7 @@ Volcanos("onaction", {help: "组件菜单", list: ["编辑", "清空", ["view", "趋势图": function(event, can, value, cmd, target) {var sub = can.sub, data = can.data; var space = 10 var view = parseInt(can.Action("height")) - var max = parseInt(can.Conf("width"))-100 + var max = parseInt(can.Conf("width"))-120 var step = parseInt(max / can.list.length)||2 var width = can.list.length * step + space * 2 diff --git a/proto.js b/proto.js index 9ce47396..cebc4af2 100644 --- a/proto.js +++ b/proto.js @@ -22,14 +22,13 @@ var Volcanos = shy("火山架", {libs: [], cache: {}}, [], function(name, can, l }); Preload = Preload.concat(Config.plugin) // 根模块 - name = Config.name, can = {_follow: Config.name, - _target: document.body, _width: window.innerWidth, _height: window.innerHeight, - }, libs = Preload.concat(Config.volcano), cb = function(can) { + name = Config.name, can = {_follow: Config.name, _target: document.body} + libs = Preload.concat(Config.volcano), cb = function(can) { can.onengine._init(can, can.Conf(Config), Config.panes, function(msg) { can.base.Log(name, "run", window.can = can) - document.body.onresize = function(event) { - can.onlayout._init(can, can._target, window.innerWidth, window.innerHeight) - }, can.onlayout._init(can, can._target, window.innerWidth, window.innerHeight-8) + var list = []; document.body.onresize = function(event) { can.core.Delay(list, 100, function() { + can.onlayout._init(can, can._target, can._width = window.innerWidth, can._height = window.innerHeight) + }) }, document.body.onresize() }, can._target) } } diff --git a/publish/chrome/chrome.html b/publish/chrome/chrome.html index 4ea6fceb..835d4294 100644 --- a/publish/chrome/chrome.html +++ b/publish/chrome/chrome.html @@ -2,11 +2,10 @@ - - + diff --git a/publish/chrome/chrome.js b/publish/chrome/chrome.js index 3b9a129a..ef7957b4 100644 --- a/publish/chrome/chrome.js +++ b/publish/chrome/chrome.js @@ -1,49 +1,39 @@ -var can = Volcanos("chrome", { - chrome: function(msg, cmd, cb) { - if (cmd.length == 0) { - // 窗口列表 +Volcanos("chrome", { + chrome: function(can, msg, cmds, cb) { + if (cmds.length == 0) { // 窗口列表 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"]) }) typeof cb == "function" && cb(msg) }) return } - if (cmd.length == 1) { - // 标签列表 - chrome.tabs.getAllInWindow(parseInt(cmd[0]), function(tabs) { - can.core.List(tabs, function(tab) {tab.tid = tab.id + if (cmds.length == 1) { // 标签列表 + chrome.tabs.getAllInWindow(parseInt(cmds[0]), function(tabs) { + can.core.List(tabs, function(tab) { tab.tid = tab.id msg.Push(tab, ["tid", "active", "width", "height", "index", "title", "url"]) }) typeof cb == "function" && cb(msg) }) return } - - delete(msg._can) - delete(msg._event) - if (cmd[1] == "") { - chrome.tabs.query({ active: true, currentWindow: true }, function (tabs) { - cmd[1] = tabs[0].id - chrome.tabs.sendMessage(parseInt(cmd[1]), msg, function (res) { + if (cmds[1] == "") { // 当前标签 + 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), typeof cb == "function" && cb(msg) }) }) - } else { - chrome.tabs.sendMessage(parseInt(cmd[1]), msg, function (res) { - msg.Copy(res), typeof cb == "function" && cb(msg) - }) + return } - return - // 新建标签 - chrome.tabs.create({windowId: parseInt(cmd[0]), url: cmd[1], selected: false}, function() { - can.chrome(msg, [cmd[0]], cb) + chrome.tabs.sendMessage(parseInt(cmds[1]), msg, function(res) { + msg.Copy(res), typeof cb == "function" && cb(msg) }) }, - bookmark: function(msg, cmd, cb) { - chrome.bookmarks.getSubTree(cmd[0]||"0", function(labs) { + bookmark: function(msg, cmds, cb) { + 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"]) @@ -52,45 +42,33 @@ var can = Volcanos("chrome", { typeof cb == "function" && cb(msg) }) }, -}, ["/lib/base", "/lib/core", "/lib/misc", "/lib/page", "/lib/user"], function(can) {can.Conf({iceberg: "http://localhost:9020/"}) +}, ["/lib/base", "/lib/core", "/lib/misc", "/lib/page", "/lib/user"], function(can) { + can.Conf({iceberg: "http://localhost:9020/"}) can.user.toast = function(message, title) {chrome.notifications.create(null, { - message: message, title: title||"volcanos", iconUrl: "/favicon.ico", type: "basic", + message: message, title: title||can._name, iconUrl: "/favicon.ico", type: "basic", })}, - can.misc.WSS(can, "ws://localhost:9020/space/", {name: "chrome", type: "chrome"}, function(event, msg) { - if (msg.Option("_handle")) { return can.user.toast(msg.result.join("")) } + can.misc.WSS(can, {type: "chrome", name: "chrome"}, function(event, msg, cmd, arg) { + can.core.CallFunc(can.core.Value(can, cmd), {can: can, msg: msg, cmds: arg, cb: function() { + msg.Reply() + }}) + }) - // can.user.toast(msg.detail.join(" ")) - try { - switch (msg.detail[0]) { - case "space": can._share = msg.detail[2]; break - case "pwd": msg.Echo("hello world"); break - default: (can[msg.detail[0]]||can.chrome[msg.detail[0]])(msg, msg.detail.slice(1), function(msg) { - msg.Reply(msg) - }); return - } - } catch (e) { - can.user.toast(e) - } - msg.Reply(msg) - }, function() {can.user.toast("wss connect", "iceberg")}) - - can.run = function(event, cmd, cb, silent) { var msg = can.request(event) - can.misc.Run(event, can, {names: "code/chrome/crx"}, cmd, cb) + can.run = function(event, cmds, cb, silent) { var msg = can.request(event) + can.misc.Run(event, can, {names: "code/chrome/crx"}, cmds, cb) }, chrome.history.onVisited.addListener(function(item) { can.run({}, ["history", item.id, item.title, item.url]) }) - chrome.contextMenus.create({ - title: "favor", - onclick: function(event) { - chrome.tabs.query({ active: true}, function (tabs) { - chrome.tabs.sendMessage(tabs[0].id, { action: "copy" }, function (response) { - console.log(response) - can.run({}, ["history", "id", response.title, response.src]) - }) + + 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"] + chrome.tabs.sendMessage(tabs[0].id, msg, function(res) { + return + can.run({}, ["history", "id", response.title, response.src]) }) - }, - }) + }) + }, }) }) diff --git a/publish/chrome/contexts.js b/publish/chrome/contexts.js index bfb96d67..132dd6f0 100644 --- a/publish/chrome/contexts.js +++ b/publish/chrome/contexts.js @@ -1,4 +1,4 @@ -var can = Volcanos("chrome", { +Volcanos("chrome", { spide: function(can, msg) { can.page.Select(can, document.body, "video", function(item) { var p = can.page.Select(can, document.body, "p.title")[0] @@ -28,29 +28,10 @@ var can = Volcanos("chrome", { msg.Push("link", item.src) }) }, -}, [], function(can) { - can.user = user - can.page = page - can.misc = misc - can.core = core - can.base = base - - chrome.extension.onMessage.addListener( function (msg, sender, cb) { var action = can[msg.detail[3]||"spide"] - msg = can.request({}, msg) - delete(msg._event) - delete(msg._can) - typeof action == "function" && action(can, msg) || typeof cb == "function" && cb(msg) - }) - return - - chrome.extension.onMessage.addListener( function (request, sender, sendResponse) { - var title = can.page.Select(can, document.body, "p.title", function(item) { - return item.innerText - }).join("-") - can.page.Select(can, document.body, "video", function(item) { - sendResponse({poster: item.poster, src: item.src, title: title}) - console.log(item) - }) +}, [], function(can) { can._load("chrome") + 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.core.Value(can, req.detail[3]||"spide"), {can: can, msg: msg, cmds: req.detail.slice(4), cb: cb}) }) }) diff --git a/publish/chrome/popup.html b/publish/chrome/popup.html index 36ca8697..3edca3ce 100644 --- a/publish/chrome/popup.html +++ b/publish/chrome/popup.html @@ -6,7 +6,7 @@ - +