diff --git a/manifest.json b/manifest.json index e7afc774..98a605c2 100644 --- a/manifest.json +++ b/manifest.json @@ -4,10 +4,7 @@ "background": {"page": "/publish/chrome/chrome.html"}, "browser_action": {"default_popup": "/publish/chrome/popup.html"}, "content_scripts": [{"matches": [""], "css": ["/publish/chrome/contexts.css"], - "js": ["/proto.js", "/plugin/state.js", "/plugin/input.js", "/plugin/table.js", - "/lib/base.js", "/lib/core.js", "/lib/misc.js", "/lib/page.js", "/lib/user.js", - "/publish/chrome/contexts.js", "/frame.js" - ]} + "js": ["/proto.js", "/publish/chrome/contexts.js", "/page/cache.js", "/frame.js"]} ], "permissions": [ "tabs", diff --git a/proto.js b/proto.js index 2fa46e65..c2107814 100644 --- a/proto.js +++ b/proto.js @@ -167,9 +167,10 @@ var Volcanos = shy("火山架", {iceberg: "/chat/", volcano: "/frame.js", args: }; 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_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||{} @@ -190,6 +191,9 @@ var Volcanos = shy("火山架", {iceberg: "/chat/", volcano: "/frame.js", args: typeof cb == lang.FUNCTION && setTimeout(function() { cb(can) }, 10) return // 加载完成 } + + if (!libs[0]) { return can.require(libs.slice(1), cb, each) } + 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 (libs && libs.length > 0) { 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") } else if (libs[i][0] != "/" && libs[i].indexOf("http") != 0) { libs[i] = _can_path.slice(0, _can_path.lastIndexOf("/")+1)+libs[i] diff --git a/publish/chrome/chrome.html b/publish/chrome/chrome.html index 835d4294..7b8e0959 100644 --- a/publish/chrome/chrome.html +++ b/publish/chrome/chrome.html @@ -1,12 +1,8 @@ - - - - - + + - - + diff --git a/publish/chrome/chrome.js b/publish/chrome/chrome.js index 1e27258d..ff6e1e77 100644 --- a/publish/chrome/chrome.js +++ b/publish/chrome/chrome.js @@ -1,51 +1,36 @@ -Volcanos("chrome", { - pwd: function(can, msg, cmds, cb) { - console.log(cmds) - cb() +Volcanos({ + pwd: function(can, msg, arg) { + msg.Push("hi", "hello") + msg.Echo("hello") }, - chrome: function(can, msg, cmds, cb) { - if (cmds.length == 0) { // 窗口列表 + chrome: function(can, msg, arg, cb) { + if (arg.length == 0) { // 窗口列表 chrome.windows.getAll(function(wins) { can.core.List(wins, function(win) { win.wid = win.id msg.Push(win, ["wid", "state", "left", "top", "width", "height"]) }) can.base.isFunc(cb) && cb(msg) }) - return - } - if (cmds.length == 1) { // 标签列表 - chrome.tabs.getAllInWindow(parseInt(cmds[0]), function(tabs) { + } else if (arg.length == 1) { // 标签列表 + chrome.tabs.getAllInWindow(parseInt(arg[0]), function(tabs) { can.core.List(tabs, function(tab) { tab.tid = tab.id msg.Push(tab, ["tid", "active", "width", "height", "index", "title", "url"]) }) can.base.isFunc(cb) && cb(msg) }) - return - } - - 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), can.base.isFunc(cb) && cb(msg) + } 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) { + can.base.isFunc(cb) && cb(msg.Copy(res)) }) }) } 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)) }) } }, - 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"]) - 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) { +}, 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) }, @@ -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.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", })}, can.misc.WSS(can, {type: "chrome", name: "chrome"}, function(event, msg, cmd, arg) { @@ -63,7 +48,7 @@ Volcanos("chrome", { }) 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) { diff --git a/publish/chrome/contexts.css b/publish/chrome/contexts.css index 4420031b..aad39ba6 100644 --- a/publish/chrome/contexts.css +++ b/publish/chrome/contexts.css @@ -2,6 +2,9 @@ fieldset.contexts { color:white; position:fixed; background:radial-gradient(black, #00000073); + top:100px; + left:100px; + z-index:10; } fieldset.contexts legend { text-align:left; diff --git a/publish/chrome/contexts.js b/publish/chrome/contexts.js index 8de13456..004ad505 100644 --- a/publish/chrome/contexts.js +++ b/publish/chrome/contexts.js @@ -1,6 +1,4 @@ -setTimeout(function() { -Volcanos("chrome", { - _follow: "chrome", +setTimeout(function() { Volcanos({ pwd: function(can, msg, arg) { msg.Push("hi", "hello") msg.Echo("hello") @@ -10,14 +8,45 @@ Volcanos("chrome", { 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) { 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.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 = {} can.page.Select(can, document.body, html.VIDEO, function(item) { if (!item.src || has[item.src]) { return } has[item.src] = true @@ -49,47 +78,8 @@ Volcanos("chrome", { 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 [] }, -}, [], 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) 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) @@ -97,11 +87,10 @@ Volcanos("chrome", { }) 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)) }) } can.run({}, [ctx.ACTION, ctx.COMMAND], function(msg) { msg.result && msg.result[0] && can.field(can, msg, msg.result) }) -}) -}, 100) +}) }, 100) diff --git a/publish/chrome/popup.js b/publish/chrome/popup.js index 6d45bef2..0745f9aa 100644 --- a/publish/chrome/popup.js +++ b/publish/chrome/popup.js @@ -4,23 +4,7 @@ Volcanos({name: "popup", iceberg: "http://localhost:9020/chat/", panels: [ {name: "Action", help: "工作台", pos: chat.MAIN}, {name: "Search", help: "搜索框", pos: chat.AUTO}, {name: "Footer", help: "状态条", pos: chat.FOOT, state: ["ncmd"]}, - ], main: {name: "Header", list: ["/publish/order.js"]}, plugin: [ - "/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: { + ], main: {name: "Header", list: ["/publish/order.js"]}, plugin: [], river: { serivce: {name: "运营群", storm: { wx: {name: "公众号 wx", action: [ {name: "微信公众号", help: "wx", index: "web.wiki.word", args: ["usr/icebergs/misc/wx/wx.shy"]},