From e6aa35715df0dc309ac5d7e1fa1f7eb1231f5007 Mon Sep 17 00:00:00 2001 From: bergyu Date: Wed, 29 Dec 2021 17:22:59 +0800 Subject: [PATCH] opt chrome --- manifest.json | 4 +- page/index.css | 2 + page/index.js | 1 + panel/cmd.css | 3 - panel/river.js | 5 +- proto.js | 1 + publish/chrome/chrome.html | 9 +-- publish/chrome/chrome.js | 86 +++++++++++------------- publish/chrome/contexts.css | 4 +- publish/chrome/contexts.js | 128 +++++++++++++++++++----------------- publish/chrome/popup.html | 2 + publish/chrome/popup.js | 49 -------------- 12 files changed, 130 insertions(+), 164 deletions(-) diff --git a/manifest.json b/manifest.json index 98a605c2..966a80ee 100644 --- a/manifest.json +++ b/manifest.json @@ -3,7 +3,9 @@ "name": "volcanos", "version": "0.0.1", "background": {"page": "/publish/chrome/chrome.html"}, "browser_action": {"default_popup": "/publish/chrome/popup.html"}, - "content_scripts": [{"matches": [""], "css": ["/publish/chrome/contexts.css"], + "content_scripts": [{"matches": [""], "css": [ + "/page/cache.css", "/publish/chrome/contexts.css" + ], "js": ["/proto.js", "/publish/chrome/contexts.js", "/page/cache.js", "/frame.js"]} ], "permissions": [ diff --git a/page/index.css b/page/index.css index 69d79b5e..c80b9f52 100644 --- a/page/index.css +++ b/page/index.css @@ -195,6 +195,8 @@ table.content th:hover { table.content td { padding:2px 6px; overflow:auto; + max-width:800px; + white-space:break-spaces; } table.content td.done { background-color:green; diff --git a/page/index.js b/page/index.js index 7a0ff982..3d2f4d4f 100644 --- a/page/index.js +++ b/page/index.js @@ -44,6 +44,7 @@ Volcanos({name: "chat", panels: [ }}, {name: "cached", help: "爬虫缓存", index: "web.code.chrome.cache", args: []}, {name: "spided", help: "网页爬虫", index: "web.code.chrome.spide", args: location && location.protocol && location.protocol=="chrome-extension:"? ["1", "", "spide"]: ["1"]}, + {name: "modify", help: "编辑页面", index: "web.code.chrome.modify", args: []}, ]}, }}, project: {name: "研发群", storm: { diff --git a/panel/cmd.css b/panel/cmd.css index 7b849c30..7bb1aacf 100644 --- a/panel/cmd.css +++ b/panel/cmd.css @@ -13,9 +13,6 @@ fieldset.panel.cmd>div.output>fieldset.plugin>div.legend { background-color:darkcyan; cursor:pointer; } -fieldset.plugin>legend { - display:none; -} body.white fieldset.panel.cmd>div.output>fieldset.plugin>div.legend { background-color:honeydew; } diff --git a/panel/river.js b/panel/river.js index b25134e3..1d5753ab 100644 --- a/panel/river.js +++ b/panel/river.js @@ -67,15 +67,18 @@ Volcanos("onengine", {help: "解析引擎", list: [], _engine: function(event, c }, }) Volcanos("onaction", {help: "控件交互", list: [], _init: function(can, msg, list, cb, target) { + can.onengine.plugin(can, "info", shy("信息", {}, ["text", "list", "back"], function(msg, cmds) { + msg.Echo(JSON.stringify(can)) + })) can.onengine.plugin(can, "log", shy("日志", {}, ["text", "list", "back"], function(msg, cmds) { console.log(cmds[0]) msg.Option(ice.MSG_DISPLAY, "/plugin/story/pie.js") })) can.onengine.plugin(can, "pie", shy("比例图", {}, ["list", "back"], function(msg, cmds) { + msg.Option(ice.MSG_DISPLAY, "/plugin/story/pie.js") msg.Push("value", 200) msg.Push("value", 300) msg.Push("value", 400) - msg.Option(ice.MSG_DISPLAY, "/plugin/story/pie.js") })) can.base.isFunc(cb) && cb() }, diff --git a/proto.js b/proto.js index 96beb23e..8f6e8529 100644 --- a/proto.js +++ b/proto.js @@ -189,6 +189,7 @@ var html = { WSS: "wss", SVG: "svg", MAX_HEIGHT: "max-height", MAX_WIDTH: "max-width", MAX_HEIGHT: "max-height", + CHROME: "chrome", } var lang = { STRING: "string", NUMBER: "number", diff --git a/publish/chrome/chrome.html b/publish/chrome/chrome.html index 7b8e0959..e7089c5e 100644 --- a/publish/chrome/chrome.html +++ b/publish/chrome/chrome.html @@ -1,8 +1,9 @@ - - - - + + + + + diff --git a/publish/chrome/chrome.js b/publish/chrome/chrome.js index ff6e1e77..897c1f16 100644 --- a/publish/chrome/chrome.js +++ b/publish/chrome/chrome.js @@ -1,69 +1,63 @@ Volcanos({ - pwd: function(can, msg, arg) { - msg.Push("hi", "hello") - msg.Echo("hello") - }, chrome: function(can, msg, arg, cb) { - if (arg.length == 0) { // 窗口列表 + 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", "left", "top", "width", "height"]) - }) - can.base.isFunc(cb) && cb(msg) + msg.Push(win, ["wid", "state", html.LEFT, html.TOP, html.WIDTH, html.HEIGHT]) + }), can.base.isFunc(cb) && cb(msg) }) - } else if (arg.length == 1) { // 标签列表 + } 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", "width", "height", "index", "title", "url"]) - }) - can.base.isFunc(cb) && cb(msg) + msg.Push(tab, ["tid", "active", html.WIDTH, html.HEIGHT, "index", "title", "url"]) + }), can.base.isFunc(cb) && cb(msg) }) - } else if (arg[1] == "") { // 当前标签 + } 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 { + } 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}); msg.__daemon = can.core.Keys(html.CHROME, sender.tab.id) + can.core.List(req.option, function(key) { msg.Option(key, req[key][0]) }) + can.run(msg._event, req.detail||[], cb) + return true + }) + chrome.history.onVisited.addListener(function(item) { + can.run({}, ["sync", kit.MDB_TYPE, "link", kit.MDB_NAME, item.title, kit.MDB_TEXT, 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) - }, - chrome.history.onVisited.addListener(function(item) { - can.run({}, ["sync", kit.MDB_TYPE, "link", kit.MDB_NAME, item.title, kit.MDB_TEXT, item.url, "tid", item.id]) - }) - - 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) { - if (msg.Option("_target")) { msg.detail = ["", "", ""].concat(msg.detail) - chrome.tabs.sendMessage(parseInt(msg.Option("_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}) - msg.__daemon = "chrome."+sender.tab.id - can.core.List(req.option, function(key) { msg.Option(key, req[key][0]) }) - can.run(msg._event, req.detail||[], cb) - return true - }) - - chrome.contextMenus.create({title: "field", onclick: function(event) { - chrome.tabs.query({currentWindow: true, active: true}, function(tabs) { - var msg = can.request(event); msg.detail = ["chrome", "", "", "order"] - chrome.tabs.sendMessage(tabs[0].id, msg) - }) - }}) + }, can._daemon(can), can._motion(can) }) diff --git a/publish/chrome/contexts.css b/publish/chrome/contexts.css index dc8498d2..d4b10d3d 100644 --- a/publish/chrome/contexts.css +++ b/publish/chrome/contexts.css @@ -71,7 +71,9 @@ fieldset.contexts div.code { overflow:auto; clear:both; } - +div.input.contexts input { + color:black; +} table.content { border:0; white-space:pre; diff --git a/publish/chrome/contexts.js b/publish/chrome/contexts.js index a8e0e263..51f7b472 100644 --- a/publish/chrome/contexts.js +++ b/publish/chrome/contexts.js @@ -1,20 +1,54 @@ setTimeout(function() { Volcanos({ - pwd: function(can, msg, arg) { - msg.Push("hi", "hello") - msg.Echo("hello") - }, - style: function(can, msg, arg) { - can.core.List(arg[0].split(ice.FS), function(item) { - can.page.Select(can, document.body, item, function(target) { - can.page.Modify(can, target, can.base.Obj(arg[1])) - }) + 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 + var p = can.page.Select(can, document.body, "p.title")[0] + var ls = item.src.split("?") + var ls = ls[0].split(ice.PT) + + msg.Push(kit.MDB_TIME, can.base.Time()) + msg.Push(kit.MDB_TYPE, html.VIDEO) + msg.Push(kit.MDB_NAME, (p && p.innerText || html.VIDEO)+ice.PT+ls[ls.length-1]) + msg.Push(kit.MDB_TEXT, item.src) + msg.Push(kit.MDB_LINK, item.src) + }) + + can.page.Select(can, document.body, html.IMG, function(item) { + if (!item.src || has[item.src]) { return } has[item.src] = true + var ls = item.src.split("?") + var ls = ls[0].split(ice.PS) + + msg.Push(kit.MDB_TIME, can.base.Time()) + msg.Push(kit.MDB_TYPE, html.IMG) + if (item.src.indexOf("data:image") == 0) { + msg.Push(kit.MDB_NAME, item.src.slice(item.src.length-20)) + } else { + msg.Push(kit.MDB_NAME, ls[ls.length-1]||"image.jpg") + } + msg.Push(kit.MDB_TEXT, item.src) + msg.Push(kit.MDB_LINK, item.src) }) }, - field: function(can, msg, arg) { - can.onmotion.float.auto(can, document.body) - document.body.ondblclick = function(event) { - can.onengine.signal(can, "onselection") + change: function(can, msg, arg) { + if (arg.length > 1) { + can.page.Modify(can, arg[0], can.base.Obj(arg[1])) } + if (arg.length > 0) { + can.page.Select(can, document.body, arg[0], function(item) { + msg.Push(kit.MDB_TEXT, item.outerHTML) + }) + } + }, + + order: function(can, msg, arg) { + var ui = can.user.input(event, can, ["index", "args", "selection", "left", "top"], function(event, button, data, list, args) { + can.run(event, [chat.FIELD, mdb.INSERT, kit.MDB_ZONE, location.host].concat(args), function(res) { + can.user.toastSuccess(can) + }) + }); can.page.Modify(can, ui._target, {style: {left: 200, top: 200}}) + can.page.ClassList.add(can, ui._target, chat.CONTEXTS) + }, + field: function(can, msg, arg) { can.onappend.plugin(can, {type: chat.CONTEXTS, index: arg[0], args: can.base.Obj(arg[1])}, function(sub, meta) { var pos = {left: msg.Option(chat.LEFT), top: msg.Option(chat.TOP), right: msg.Option(chat.RIGHT), bottom: msg.Option(chat.BOTTOM)} can.page.Modify(can, sub._target, {style: pos}) @@ -50,58 +84,34 @@ setTimeout(function() { Volcanos({ } }, document.body) }, - order: function(can, msg, arg) { - var ui = can.user.input(event, can, ["index", "args", "selection", "left", "top"], function(event, button, data, list, args) { - can.run(event, [chat.FIELD, mdb.INSERT, kit.MDB_ZONE, location.host].concat(args), function(res) { - can.user.toastSuccess(can) + style: function(can, msg, arg) { + can.core.List(arg[0].split(ice.FS), function(item) { + can.page.Select(can, document.body, item, function(target) { + can.page.Modify(can, target, can.base.Obj(arg[1])) }) - }); can.page.Modify(can, ui._target, {style: {left: 200, top: 200}}) - can.page.ClassList.add(can, ui._target, chat.CONTEXTS) - }, - - 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 - var p = can.page.Select(can, document.body, "p.title")[0] - var ls = item.src.split("?") - var ls = ls[0].split(ice.PT) - - msg.Push(kit.MDB_TIME, can.base.Time()) - msg.Push(kit.MDB_TYPE, html.VIDEO) - msg.Push(kit.MDB_NAME, (p && p.innerText || html.VIDEO)+ice.PT+ls[ls.length-1]) - msg.Push(kit.MDB_TEXT, item.src) - msg.Push(kit.MDB_LINK, item.src) - }) - - can.page.Select(can, document.body, html.IMG, function(item) { - if (!item.src || has[item.src]) { return } has[item.src] = true - var ls = item.src.split("?") - var ls = ls[0].split(ice.PS) - - msg.Push(kit.MDB_TIME, can.base.Time()) - msg.Push(kit.MDB_TYPE, html.IMG) - if (item.src.indexOf("data:image") == 0) { - msg.Push(kit.MDB_NAME, item.src.slice(item.src.length-20)) - } else { - msg.Push(kit.MDB_NAME, ls[ls.length-1]||"image.jpg") - } - msg.Push(kit.MDB_TEXT, item.src) - msg.Push(kit.MDB_LINK, item.src) }) }, + Option: function() { return [] }, -}, 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) - }}) - }) + + _daemon: 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) + }}) + }) + }, + _motion: function(can) { + can.onmotion.float.auto(can, document.body) + document.body.ondblclick = function(event) { can.onengine.signal(can, "onselection") } + can.run({}, [ctx.ACTION, ctx.COMMAND], function(msg) { + msg.result && msg.result[0] && can.field(can, msg, msg.result) + }) + }, +}, function(can) { can.run = function(event, cmds, cb) { if (cmds[0] == "_search") { return } 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) - }) + }, can._daemon(can), can._motion(can) }) }, 1) diff --git a/publish/chrome/popup.html b/publish/chrome/popup.html index 113f26a1..43c4ab2b 100644 --- a/publish/chrome/popup.html +++ b/publish/chrome/popup.html @@ -1,9 +1,11 @@ + + diff --git a/publish/chrome/popup.js b/publish/chrome/popup.js index 1da8e734..f921fbf5 100644 --- a/publish/chrome/popup.js +++ b/publish/chrome/popup.js @@ -1,15 +1,4 @@ Volcanos({name: "popup", iceberg: "http://localhost:9020/chat/", river: { - serivce: {name: "运营群", storm: { - wx: {name: "公众号 wx", list: [ - {name: "微信公众号", help: "wx", index: "web.wiki.word", args: ["usr/icebergs/misc/wx/wx.shy"]}, - ]}, - mp: {name: "小程序 mp", list: [ - {name: "微信小程序", help: "mp", index: "web.wiki.word", args: ["usr/icebergs/misc/mp/mp.shy"]}, - ]}, - lark: {name: "机器人 lark", list: [ - {name: "飞书机器人", help: "lark", index: "web.wiki.word", args: ["usr/icebergs/misc/lark/lark.shy"]}, - ]}, - }}, product: {name: "产品群", storm: { office: {name: "办公 office", list: [ {name: "feel", help: "影音媒体", index: "web.wiki.feel"}, @@ -20,17 +9,6 @@ Volcanos({name: "popup", iceberg: "http://localhost:9020/chat/", river: { {name: "index", help: "索引", index: "web.wiki.word", args: ["usr/learning/index.shy"]}, {name: "context", help: "编程", index: "web.wiki.word", args: ["src/main.shy"]}, ]}, - english: {name: "英汉 english", list: [ - {name: "english", help: "英汉", index: "web.wiki.alpha.alpha", args: ["word", "hi"]}, - {name: "chinese", help: "汉英", index: "web.wiki.alpha.alpha", args: ["line", "你好"]}, - {name: "wubi", help: "五笔", index: "web.code.input.wubi", args: ["word", "wqvb"]}, - {name: "wubi", help: "五笔", index: "web.code.input.wubi", args: ["line", "你好"]}, - ]}, - learning: {name: "学习 learning", list: [ - {name: "golang", help: "编程", index: "web.wiki.word", args: ["usr/golang-story/src/main.shy"]}, - {name: "tmux", help: "粘贴", index: "web.code.tmux.text"}, - {name: "study", help: "学习", index: "web.wiki.word", args: ["usr/learning/study.shy"]}, - ]}, chrome: {name: "爬虫 chrome", list: [ {name: "feel", help: "网页爬虫", index: "web.wiki.feel", args: ["spide/"], feature: { display: "/plugin/local/wiki/feel.js", @@ -50,33 +28,6 @@ Volcanos({name: "popup", iceberg: "http://localhost:9020/chat/", river: { web: {name: "网页 web", list: [ {name: "HTML5", help: "浏览器", index: "web.wiki.word", args: ["usr/icebergs/misc/chrome/chrome.shy"]}, ]}, - cli: {name: "命令 cli", list: [ - {name: "bash", help: "命令行", index: "web.wiki.word", args: ["usr/icebergs/misc/bash/bash.shy"]}, - {name: "git", help: "代码库", index: "web.wiki.word", args: ["usr/icebergs/misc/git/git.shy"]}, - {name: "vim", help: "编辑器", index: "web.wiki.word", args: ["usr/icebergs/misc/vim/vim.shy"]}, - {name: "tmux", help: "命令行", index: "web.wiki.word", args: ["usr/icebergs/misc/tmux/tmux.shy"]}, - ]}, - linux: {name: "系统 linux", list: [ - {name: "idc", help: "平台", index: "web.wiki.word", args: ["usr/linux-story/idc/idc.shy"]}, - {name: "iso", help: "系统", index: "web.wiki.word", args: ["usr/linux-story/iso/iso.shy"]}, - {name: "iot", help: "设备", index: "web.wiki.word", args: ["usr/linux-story/iot/iot.shy"]}, - {name: "cli", help: "命令", index: "web.wiki.word", args: ["usr/linux-story/cli/cli.shy"]}, - {name: "linux", help: "系统", index: "web.wiki.word", args: ["usr/linux-story/src/main.shy"]}, - ]}, - nginx: {name: "代理 nginx", list: [ - {name: "nginx", help: "代理", index: "web.wiki.word", args: ["usr/nginx-story/src/main.shy"]}, - ]}, - context: {name: "编程 context", list: [ - {name: "golang", help: "编程", index: "web.wiki.word", args: ["usr/golang-story/src/main.shy"]}, - ]}, - redis: {name: "缓存 redis", list: [ - {name: "redis", help: "缓存", index: "web.wiki.word", args: ["usr/redis-story/src/main.shy"]}, - {name: "kafka", help: "队列", index: "web.wiki.word", args: ["usr/redis-story/src/kafka/kafka.shy"]}, - ]}, - mysql: {name: "存储 mysql", list: [ - {name: "mysql", help: "数据存储", index: "web.wiki.word", args: ["usr/mysql-story/src/main.shy"]}, - {name: "clickhouse", help: "数据存储", index: "web.wiki.word", args: ["usr/mysql-story/src/clickhouse/clickhouse.shy"]}, - ]}, }}, profile: {name: "测试群", storm: { release: {name: "发布 release", index: [