stable
This commit is contained in:
parent
9e2d9d5abc
commit
f330daf242
|
@ -33,8 +33,8 @@ if(document.contentType == "application/json") {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (condition()) {
|
if (condition()) {
|
||||||
Tell(BackgroundMsgType.CONTENT, content);
|
Tell("content", content);
|
||||||
} else {
|
} else {
|
||||||
Tell(BackgroundMsgType.NOTWANT, content);
|
Tell("notwant", content);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,22 +2,40 @@
|
||||||
chrome.webRequest.onBeforeRequest.addListener(function (details) {
|
chrome.webRequest.onBeforeRequest.addListener(function (details) {
|
||||||
if (details.url.startsWith("http://eson.config")) {
|
if (details.url.startsWith("http://eson.config")) {
|
||||||
var params = new URL(details.url).searchParams;
|
var params = new URL(details.url).searchParams;
|
||||||
UpdateHost(params.get("taskurl"))
|
|
||||||
chrome.tabs.remove(details.tabId);
|
for( key of params.keys()) {
|
||||||
chrome.tabs.query({ currentWindow: true }, function (tabs) {
|
switch(key) {
|
||||||
var count = 0
|
case "proxyserver":
|
||||||
for (var tab of tabs) {
|
ProxyServer = params.get(key)
|
||||||
if (!tab.url.startsWith("chrome://")) {
|
break
|
||||||
count++;
|
|
||||||
chrome.tabs.executeScript(tab.id, { runAt: "document_end", code: `window.location.href = "${Host}"` })
|
|
||||||
} else {
|
|
||||||
chrome.tabs.remove(tab.id);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
for (var i = count; i < WorkerNumber; i++) {
|
}
|
||||||
chrome.tabs.create({ url: `${Host}` });
|
|
||||||
}
|
var taskurl = params.get("taskurl")
|
||||||
})
|
if(taskurl !== "") {
|
||||||
|
UpdateHost(taskurl)
|
||||||
|
removeConfigTabAndCreateGetTaskTab(details);
|
||||||
|
}
|
||||||
|
|
||||||
return { cancel: true };
|
return { cancel: true };
|
||||||
}
|
}
|
||||||
}, { 'urls': ["<all_urls>"] }, ['blocking']);
|
}, { 'urls': ["<all_urls>"] }, ['blocking']);
|
||||||
|
|
||||||
|
|
||||||
|
function removeConfigTabAndCreateGetTaskTab(details) {
|
||||||
|
chrome.tabs.remove(details.tabId);
|
||||||
|
chrome.tabs.query({ currentWindow: true }, function (tabs) {
|
||||||
|
var count = 0
|
||||||
|
for (var tab of tabs) {
|
||||||
|
if (!tab.url.startsWith("chrome://")) {
|
||||||
|
count++;
|
||||||
|
chrome.tabs.executeScript(tab.id, { runAt: "document_end", code: `window.location.href = "${Host}"` })
|
||||||
|
} else {
|
||||||
|
chrome.tabs.remove(tab.id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (var i = count; i < WorkerNumber; i++) {
|
||||||
|
chrome.tabs.create({ url: `${Host}` });
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
21
chromeproxy/background/proxy.js
Normal file
21
chromeproxy/background/proxy.js
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
|
||||||
|
|
||||||
|
var config = {
|
||||||
|
mode: "pac_script",
|
||||||
|
pacScript: {
|
||||||
|
data:
|
||||||
|
`
|
||||||
|
ProxyServer = ${ProxyServer};
|
||||||
|
function FindProxyForURL(url, host) {
|
||||||
|
if(ProxyServer != undefined) {
|
||||||
|
return ProxyServer;
|
||||||
|
}
|
||||||
|
return 'DIRECT';
|
||||||
|
}`
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
chrome.proxy.settings.set(
|
||||||
|
{ value: config, scope: 'regular' },
|
||||||
|
function () { });
|
|
@ -61,9 +61,7 @@ function GetTask(sender) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function CaptureContentCurrentPage(tabid) {
|
function CaptureContentCurrentPage(tabid) {
|
||||||
chrome.tabs.executeScript(tabid, { runAt: "document_end", file: "base.js" }, function(){
|
chrome.tabs.executeScript(tabid, { runAt: "document_end", file: "background/capture.js" });
|
||||||
chrome.tabs.executeScript(tabid, { runAt: "document_end", file: "background/capture.js" });
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function CaptureContent(task) {
|
function CaptureContent(task) {
|
||||||
|
@ -82,7 +80,7 @@ function CaptureContent(task) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (condition != undefined) {
|
if (condition != undefined) {
|
||||||
chrome.tabs.executeScript(tab.id, { runAt: "document_end", code: condition }, function () {
|
chrome.tabs.executeScript(tab.id, { runAt: "document_start", code: condition }, function () {
|
||||||
CaptureContentCurrentPage(tab.id)
|
CaptureContentCurrentPage(tab.id)
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -1,17 +1,19 @@
|
||||||
|
|
||||||
var Host = "http://localhost:7123"
|
var Host = "http://localhost:7123"
|
||||||
|
|
||||||
var GetTaskUrl = `${Host}/task/get`;
|
var GetTaskUrl = `${Host}/task/get`;
|
||||||
var FinishTaskUrl = `${Host}/task/content`;
|
var FinishTaskUrl = `${Host}/task/content`;
|
||||||
var ErrorTaskUrl = `${Host}/task/error`;
|
var ErrorTaskUrl = `${Host}/task/error`;
|
||||||
|
var ConfigUrl = `${Host}/task/config`
|
||||||
|
|
||||||
var WorkerNumber = 1;
|
var WorkerNumber = 1;
|
||||||
|
var ProxyServer = undefined;
|
||||||
|
|
||||||
function UpdateHost(host) {
|
function UpdateHost(host) {
|
||||||
Host = host
|
Host = host
|
||||||
GetTaskUrl = `${Host}/task/get`
|
GetTaskUrl = `${Host}/task/get`
|
||||||
FinishTaskUrl = `${Host}/task/content`
|
FinishTaskUrl = `${Host}/task/content`
|
||||||
ErrorTaskUrl = `${Host}/task/error`
|
ErrorTaskUrl = `${Host}/task/error`
|
||||||
|
ConfigUrl = `${Host}/task/config`
|
||||||
}
|
}
|
||||||
|
|
||||||
const BackgroundMsgType = {
|
const BackgroundMsgType = {
|
||||||
|
|
|
@ -39,7 +39,7 @@
|
||||||
"key": "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAlurgt0Ykv740tjk1ebeiSX6UVVRRhxVvh+FvRMTe9PKzkAKUDEW2IjNUz1swxZA8ILnMvtyamAfiErTOxUFB8+zCADU/CK2YEhqUJo3tmHCg6EP2XJL220ZXjmIeft1AqJV1BmGRLhm8VnH8dJ2EThfcflx4JEdlh0/aLJr6UVjF2hPVX8JLAMTVjEfiC82KDNGgXDADqBm3E/6n+Dx+3KhgIYTXKIMk+qRVaOhjAJLh8a9OrDBwpylP5RDifTAyVVa9UOyoLNqynzC9oLabWUr1ovWAOiivhYknFCXnl5q971iNSFpmjc+ZW+aK+TRjMnJF84IeA170corVG3KgnwIDAQAB",
|
"key": "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAlurgt0Ykv740tjk1ebeiSX6UVVRRhxVvh+FvRMTe9PKzkAKUDEW2IjNUz1swxZA8ILnMvtyamAfiErTOxUFB8+zCADU/CK2YEhqUJo3tmHCg6EP2XJL220ZXjmIeft1AqJV1BmGRLhm8VnH8dJ2EThfcflx4JEdlh0/aLJr6UVjF2hPVX8JLAMTVjEfiC82KDNGgXDADqBm3E/6n+Dx+3KhgIYTXKIMk+qRVaOhjAJLh8a9OrDBwpylP5RDifTAyVVa9UOyoLNqynzC9oLabWUr1ovWAOiivhYknFCXnl5q971iNSFpmjc+ZW+aK+TRjMnJF84IeA170corVG3KgnwIDAQAB",
|
||||||
"manifest_version": 2,
|
"manifest_version": 2,
|
||||||
"name": "ChromeProxy",
|
"name": "ChromeProxy",
|
||||||
"permissions": ["background", "http://*/*", "https://*/*", "storage","tabs" , "activeTab", "webRequest", "webRequestBlocking", "<all_urls>", "webNavigation"],
|
"permissions": ["background", "http://*/*", "https://*/*", "proxy", "storage","tabs" , "activeTab", "webRequest", "webRequestBlocking", "<all_urls>", "webNavigation"],
|
||||||
"short_name": "ChromeProxy",
|
"short_name": "ChromeProxy",
|
||||||
"version": "0.1.0"
|
"version": "0.1.0"
|
||||||
}
|
}
|
||||||
|
|
1
chromeproxy/pac.js
Normal file
1
chromeproxy/pac.js
Normal file
|
@ -0,0 +1 @@
|
||||||
|
|
|
@ -7,7 +7,7 @@ import (
|
||||||
"gopkg.in/yaml.v2"
|
"gopkg.in/yaml.v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
var config = &Config{}
|
var config = &LocalConfig{}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
f, err := os.Open("config.yaml")
|
f, err := os.Open("config.yaml")
|
||||||
|
@ -21,8 +21,8 @@ func init() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Config 本地yaml配置对象
|
// LocalConfig 本地yaml配置对象
|
||||||
type Config struct {
|
type LocalConfig struct {
|
||||||
Server struct {
|
Server struct {
|
||||||
URI string `yaml:"uri"`
|
URI string `yaml:"uri"`
|
||||||
} `yaml:"server"`
|
} `yaml:"server"`
|
||||||
|
@ -41,3 +41,8 @@ func initChromeProxy() {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ChromeConfig chrome的配置, 包括代理
|
||||||
|
type ChromeConfig struct {
|
||||||
|
PacScript string
|
||||||
|
}
|
||||||
|
|
|
@ -3,7 +3,7 @@ module git.nonolive.co/eson.hsm/proxyserver
|
||||||
go 1.15
|
go 1.15
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/474420502/focus v0.12.0
|
github.com/474420502/focus v0.13.1
|
||||||
github.com/474420502/requests v1.10.1
|
github.com/474420502/requests v1.10.1
|
||||||
github.com/bwmarrin/snowflake v0.3.0
|
github.com/bwmarrin/snowflake v0.3.0
|
||||||
github.com/gin-gonic/gin v1.6.3
|
github.com/gin-gonic/gin v1.6.3
|
||||||
|
|
|
@ -1,6 +1,10 @@
|
||||||
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
|
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
|
||||||
github.com/474420502/focus v0.12.0 h1:+icbmj7IEOefvTegHt5EpcHt6WFbe2miIrceUJx2Evo=
|
github.com/474420502/focus v0.12.0 h1:+icbmj7IEOefvTegHt5EpcHt6WFbe2miIrceUJx2Evo=
|
||||||
github.com/474420502/focus v0.12.0/go.mod h1:d0PMjtMxFz1a9HIhwyFPkWa+JF+0LgOrEUfd8iZka6s=
|
github.com/474420502/focus v0.12.0/go.mod h1:d0PMjtMxFz1a9HIhwyFPkWa+JF+0LgOrEUfd8iZka6s=
|
||||||
|
github.com/474420502/focus v0.13.0 h1:68G0txM38EinNitcfpP0752k8tF4JRJ0r1mmdH6FoGc=
|
||||||
|
github.com/474420502/focus v0.13.0/go.mod h1:d0PMjtMxFz1a9HIhwyFPkWa+JF+0LgOrEUfd8iZka6s=
|
||||||
|
github.com/474420502/focus v0.13.1 h1:HwJCqY60eqRAkwKtIefJib1ofBfcvVh5ZTU2xE8Gmkk=
|
||||||
|
github.com/474420502/focus v0.13.1/go.mod h1:SrqNq63qSx53TkvVWOuHTbTSvAQTNO8ZUrufXm0Ncq8=
|
||||||
github.com/474420502/requests v1.10.0 h1:Oz7+Nx+1iuJJUjbBH3cVmkDVosF2tyq5d72TMAoQH8I=
|
github.com/474420502/requests v1.10.0 h1:Oz7+Nx+1iuJJUjbBH3cVmkDVosF2tyq5d72TMAoQH8I=
|
||||||
github.com/474420502/requests v1.10.0/go.mod h1:SB8/RIUVWF3AGotuq/mATUwAjXzzlV7iWaBNM3+c06c=
|
github.com/474420502/requests v1.10.0/go.mod h1:SB8/RIUVWF3AGotuq/mATUwAjXzzlV7iWaBNM3+c06c=
|
||||||
github.com/474420502/requests v1.10.1 h1:k5qK8ZWPIdrG0EurJuK2hhoYFbJ9GJTe0xvrzESMFLo=
|
github.com/474420502/requests v1.10.1 h1:k5qK8ZWPIdrG0EurJuK2hhoYFbJ9GJTe0xvrzESMFLo=
|
||||||
|
@ -127,6 +131,7 @@ golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7w
|
||||||
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
|
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
|
||||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||||
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
|
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
|
||||||
|
golang.org/x/text v0.3.4/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||||
golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||||
golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY=
|
golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY=
|
||||||
|
|
|
@ -42,10 +42,9 @@ func init() {
|
||||||
task := engine.Group("/task")
|
task := engine.Group("/task")
|
||||||
task.GET("/get", GetTask)
|
task.GET("/get", GetTask)
|
||||||
task.POST("/put", PutTask)
|
task.POST("/put", PutTask)
|
||||||
|
|
||||||
task.POST("/content", ContentTask)
|
task.POST("/content", ContentTask)
|
||||||
|
|
||||||
task.POST("/error", ErrorTask)
|
task.POST("/error", ErrorTask)
|
||||||
|
task.GET("/config", GetConfig)
|
||||||
|
|
||||||
task.GET("/ready", ReadyTask)
|
task.GET("/ready", ReadyTask)
|
||||||
task.POST("/ack", AckTask)
|
task.POST("/ack", AckTask)
|
||||||
|
@ -174,6 +173,11 @@ func ReadyTask(c *gin.Context) {
|
||||||
c.JSON(http.StatusOK, Response{Code: 404, Message: fmt.Sprintf("taskid: %s is not found", tid)})
|
c.JSON(http.StatusOK, Response{Code: 404, Message: fmt.Sprintf("taskid: %s is not found", tid)})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetConfig 获取任务配置
|
||||||
|
func GetConfig(c *gin.Context) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
// ErrorTask 任务错误无法完成
|
// ErrorTask 任务错误无法完成
|
||||||
func ErrorTask(c *gin.Context) {
|
func ErrorTask(c *gin.Context) {
|
||||||
tid := c.PostForm("taskid")
|
tid := c.PostForm("taskid")
|
||||||
|
|
Loading…
Reference in New Issue
Block a user