mirror of
https://shylinux.com/x/volcanos
synced 2025-04-25 16:58:06 +08:00
opt chrome
This commit is contained in:
parent
c92427c33b
commit
d5ce8f9339
114
chrome/chrome.js
114
chrome/chrome.js
@ -1,12 +1,5 @@
|
|||||||
var can = Volcanos("chrome", {
|
var can = Volcanos("chrome", {
|
||||||
_send: function(msg, cb) {chrome.extension.sendRequest(msg, cb)},
|
chrome: function(msg, cmd, cb) {
|
||||||
_open: function(url) {chrome.windows.create({url: url})},
|
|
||||||
|
|
||||||
open: function(msg, cmd, cb) {
|
|
||||||
chrome.windows.create({url: cmd[0]})
|
|
||||||
typeof cb == "function" && cb(msg)
|
|
||||||
},
|
|
||||||
wins: function(msg, cmd, cb) {
|
|
||||||
if (cmd.length == 0) {
|
if (cmd.length == 0) {
|
||||||
// 窗口列表
|
// 窗口列表
|
||||||
chrome.windows.getAll(function(wins) {
|
chrome.windows.getAll(function(wins) {
|
||||||
@ -17,86 +10,23 @@ var can = Volcanos("chrome", {
|
|||||||
})
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if (cmd.length == 1) {
|
||||||
if (cmd.length > 1) {
|
// 标签列表
|
||||||
// 新建标签
|
chrome.tabs.getAllInWindow(parseInt(cmd[0]), function(tabs) {
|
||||||
chrome.tabs.create({windowId: parseInt(cmd[0]), url: cmd[1], selected: false}, function() {
|
can.core.List(tabs, function(tab) {tab.tid = tab.id
|
||||||
can.wins(msg, [cmd[0]], cb)
|
msg.Push(tab, ["tid", "active", "width", "height", "index", "title", "url"])
|
||||||
})
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// 标签列表
|
|
||||||
chrome.tabs.getAllInWindow(parseInt(cmd[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)
|
|
||||||
})
|
|
||||||
},
|
|
||||||
tabs: function(msg, cmd, cb) {
|
|
||||||
if (cmd.length == 0) {
|
|
||||||
chrome.tabs.getAllInWindow(function(tabs) {
|
|
||||||
can.core.List(tabs, function(tab) {
|
|
||||||
msg.Push("id", tab.id)
|
|
||||||
msg.Push("active", tab.active)
|
|
||||||
msg.Push("index", tab.index)
|
|
||||||
msg.Push("title", tab.title)
|
|
||||||
msg.Push("url", tab.url)
|
|
||||||
})
|
})
|
||||||
typeof cb == "function" && cb(msg)
|
typeof cb == "function" && cb(msg)
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
chrome.tabs[cmd[1]](parseInt(cmd[0]), cb)
|
// 新建标签
|
||||||
},
|
chrome.tabs.create({windowId: parseInt(cmd[0]), url: cmd[1], selected: false}, function() {
|
||||||
cookie: function(msg, cmd, cb) {
|
can.chrome(msg, [cmd[0]], cb)
|
||||||
if (cmd[0] == "modify") {var data = {}; data[cmd[1]] = cmd[2]
|
|
||||||
chrome.bookmarks.update(cmd[4], data, function() {
|
|
||||||
typeof cb == "function" && cb(msg)
|
|
||||||
})
|
|
||||||
return
|
|
||||||
} else if (cmd[0] == "delete") {
|
|
||||||
chrome.bookmarks.remove(cmd[2], function() {
|
|
||||||
typeof cb == "function" && cb(msg)
|
|
||||||
})
|
|
||||||
return
|
|
||||||
} else if (cmd.length > 2) {
|
|
||||||
chrome.bookmarks.create({parentId: cmd[0], url: cmd[1], title: cmd[2], index: cmd[3]||0}, cb)
|
|
||||||
}
|
|
||||||
|
|
||||||
chrome.cookies.getAll({name: ""}, function(cs) {
|
|
||||||
typeof cb == "function" && cb(msg)
|
|
||||||
})
|
|
||||||
},
|
|
||||||
history: function(msg, cmd, cb) {
|
|
||||||
chrome.tabs.getAllInWindow(function(tabs) {
|
|
||||||
can.core.List(tabs, function(tab) {
|
|
||||||
msg.Push("id", tab.id)
|
|
||||||
msg.Push("active", tab.active)
|
|
||||||
msg.Push("index", tab.index)
|
|
||||||
msg.Push("title", tab.title)
|
|
||||||
msg.Push("url", tab.url)
|
|
||||||
})
|
|
||||||
typeof cb == "function" && cb(msg)
|
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
bookmark: function(msg, cmd, cb) {
|
bookmark: function(msg, cmd, cb) {
|
||||||
if (cmd[0] == "modify") {var data = {}; data[cmd[1]] = cmd[2]
|
|
||||||
chrome.bookmarks.update(cmd[4], data, function() {
|
|
||||||
typeof cb == "function" && cb(msg)
|
|
||||||
})
|
|
||||||
return
|
|
||||||
} else if (cmd[0] == "delete") {
|
|
||||||
chrome.bookmarks.remove(cmd[2], function() {
|
|
||||||
typeof cb == "function" && cb(msg)
|
|
||||||
})
|
|
||||||
return
|
|
||||||
} else if (cmd.length > 2) {
|
|
||||||
chrome.bookmarks.create({parentId: cmd[0], url: cmd[1], title: cmd[2], index: cmd[3]||0}, cb)
|
|
||||||
}
|
|
||||||
|
|
||||||
chrome.bookmarks.getSubTree(cmd[0]||"0", function(labs) {
|
chrome.bookmarks.getSubTree(cmd[0]||"0", function(labs) {
|
||||||
for (var i = 0; i < labs.length; i++) {labs[i].pid = labs[i].parentId
|
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("time", can.base.Time(labs[i].dateAdded))
|
||||||
@ -111,11 +41,8 @@ var can = Volcanos("chrome", {
|
|||||||
message: message, title: title||"volcanos", iconUrl: "/favicon.ico", type: "basic",
|
message: message, title: title||"volcanos", iconUrl: "/favicon.ico", type: "basic",
|
||||||
})},
|
})},
|
||||||
|
|
||||||
can.run = function(event, cmd, cb, silent) { var msg = can.request(event)
|
|
||||||
can.misc.Run(event, can, {names: "code/chrome/crx"}, cmd, cb)
|
|
||||||
},
|
|
||||||
can.misc.WSS(can, "ws://localhost:9020/space/", {name: "chrome", type: "chrome"}, function(event, msg) {
|
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(""))}
|
if (msg.Option("_handle")) { return can.user.toast(msg.result.join("")) }
|
||||||
|
|
||||||
can.user.toast(msg.detail.join(" "))
|
can.user.toast(msg.detail.join(" "))
|
||||||
switch (msg.detail[0]) {
|
switch (msg.detail[0]) {
|
||||||
@ -128,24 +55,11 @@ var can = Volcanos("chrome", {
|
|||||||
msg.Reply(msg)
|
msg.Reply(msg)
|
||||||
}, function() {can.user.toast("wss connect", "iceberg")})
|
}, 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)
|
||||||
|
},
|
||||||
chrome.history.onVisited.addListener(function(item) {
|
chrome.history.onVisited.addListener(function(item) {
|
||||||
can.run({}, ["history", item.id, item.title, item.url], function(msg) {
|
can.run({}, ["history", item.id, item.title, item.url])
|
||||||
// can.user.toast(item.url, item.title)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
return
|
|
||||||
|
|
||||||
chrome.bookmarks.onCreated.addListener(function(id, item) {
|
|
||||||
chrome.bookmarks.get(item.parentId, function(root) {
|
|
||||||
can.run(can, {cmd: ["bookmark", item.id, item.url, item.title, root[0].title]}, function(msg) {
|
|
||||||
can.user.toast(item.url, item.title)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
chrome.extension.onRequest.addListener(function(msg, sender, cb) {
|
|
||||||
can.run(can, msg, cb)
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -1,30 +1,41 @@
|
|||||||
Volcanos("onengine", { river: {
|
Volcanos("onengine", { river: {
|
||||||
"main": {name: "main", storm: {
|
"main": {name: "main", storm: {
|
||||||
"main": {name: "main", index: [
|
"inner": {name: "inner", index: [
|
||||||
"web.code.inner",
|
"web.code.inner",
|
||||||
"web.code.git.status",
|
"web.code.git.status",
|
||||||
"web.code.git.total",
|
"web.code.git.total",
|
||||||
]},
|
]},
|
||||||
"task": {name: "task", index: [
|
"pprof": {name: "pprof", index: [
|
||||||
"web.team.plan",
|
|
||||||
"web.wiki.draw.draw",
|
|
||||||
"web.wiki.word",
|
|
||||||
]},
|
|
||||||
"relay": {name: "relay", index: [
|
|
||||||
"aaa.totp.get",
|
|
||||||
"web.route",
|
|
||||||
]},
|
|
||||||
"性能": {name: "性能", index: [
|
|
||||||
"web.code.pprof",
|
"web.code.pprof",
|
||||||
"web.code.bench",
|
"web.code.bench",
|
||||||
"web.favor",
|
"web.favor",
|
||||||
"web.cache",
|
"web.cache",
|
||||||
"web.share",
|
"web.share",
|
||||||
]},
|
]},
|
||||||
"wiki": {name: "wiki", index: [
|
"relay": {name: "relay", index: [
|
||||||
// "web.wiki.draw.draw",
|
"aaa.totp.get",
|
||||||
|
"web.route",
|
||||||
|
"web.space",
|
||||||
|
"web.dream",
|
||||||
|
"web.code.docker.container",
|
||||||
|
"web.code.tmux.session",
|
||||||
|
]},
|
||||||
|
"office": {name: "office", index: [
|
||||||
|
"web.team.plan",
|
||||||
"web.wiki.feel",
|
"web.wiki.feel",
|
||||||
"web.wiki.data",
|
"web.wiki.data",
|
||||||
|
"web.wiki.word",
|
||||||
|
"web.wiki.draw.draw",
|
||||||
|
]},
|
||||||
|
"docker": {name: "docker", index: [
|
||||||
|
"web.code.docker.image",
|
||||||
|
"web.code.docker.container",
|
||||||
|
"web.code.docker.command",
|
||||||
|
]},
|
||||||
|
"tmux": {name: "tmux", index: [
|
||||||
|
"web.code.tmux.text",
|
||||||
|
"web.code.tmux.buffer",
|
||||||
|
"web.code.tmux.session",
|
||||||
]},
|
]},
|
||||||
}},
|
}},
|
||||||
}, })
|
}, })
|
||||||
|
Loading…
x
Reference in New Issue
Block a user