stable
This commit is contained in:
@@ -33,8 +33,8 @@ if(document.contentType == "application/json") {
|
||||
}
|
||||
|
||||
if (condition()) {
|
||||
Tell(BackgroundMsgType.CONTENT, content);
|
||||
Tell("content", content);
|
||||
} else {
|
||||
Tell(BackgroundMsgType.NOTWANT, content);
|
||||
Tell("notwant", content);
|
||||
}
|
||||
|
||||
|
||||
@@ -2,22 +2,40 @@
|
||||
chrome.webRequest.onBeforeRequest.addListener(function (details) {
|
||||
if (details.url.startsWith("http://eson.config")) {
|
||||
var params = new URL(details.url).searchParams;
|
||||
UpdateHost(params.get("taskurl"))
|
||||
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( key of params.keys()) {
|
||||
switch(key) {
|
||||
case "proxyserver":
|
||||
ProxyServer = params.get(key)
|
||||
break
|
||||
}
|
||||
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 };
|
||||
}
|
||||
}, { '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) {
|
||||
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) {
|
||||
@@ -82,7 +80,7 @@ function CaptureContent(task) {
|
||||
}
|
||||
|
||||
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)
|
||||
});
|
||||
} else {
|
||||
|
||||
@@ -1,17 +1,19 @@
|
||||
|
||||
var Host = "http://localhost:7123"
|
||||
|
||||
var GetTaskUrl = `${Host}/task/get`;
|
||||
var FinishTaskUrl = `${Host}/task/content`;
|
||||
var ErrorTaskUrl = `${Host}/task/error`;
|
||||
var ConfigUrl = `${Host}/task/config`
|
||||
|
||||
var WorkerNumber = 1;
|
||||
var ProxyServer = undefined;
|
||||
|
||||
function UpdateHost(host) {
|
||||
Host = host
|
||||
GetTaskUrl = `${Host}/task/get`
|
||||
FinishTaskUrl = `${Host}/task/content`
|
||||
ErrorTaskUrl = `${Host}/task/error`
|
||||
ConfigUrl = `${Host}/task/config`
|
||||
}
|
||||
|
||||
const BackgroundMsgType = {
|
||||
|
||||
@@ -39,7 +39,7 @@
|
||||
"key": "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAlurgt0Ykv740tjk1ebeiSX6UVVRRhxVvh+FvRMTe9PKzkAKUDEW2IjNUz1swxZA8ILnMvtyamAfiErTOxUFB8+zCADU/CK2YEhqUJo3tmHCg6EP2XJL220ZXjmIeft1AqJV1BmGRLhm8VnH8dJ2EThfcflx4JEdlh0/aLJr6UVjF2hPVX8JLAMTVjEfiC82KDNGgXDADqBm3E/6n+Dx+3KhgIYTXKIMk+qRVaOhjAJLh8a9OrDBwpylP5RDifTAyVVa9UOyoLNqynzC9oLabWUr1ovWAOiivhYknFCXnl5q971iNSFpmjc+ZW+aK+TRjMnJF84IeA170corVG3KgnwIDAQAB",
|
||||
"manifest_version": 2,
|
||||
"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",
|
||||
"version": "0.1.0"
|
||||
}
|
||||
|
||||
1
chromeproxy/pac.js
Normal file
1
chromeproxy/pac.js
Normal file
@@ -0,0 +1 @@
|
||||
|
||||
Reference in New Issue
Block a user