TODO: 回调没反应

This commit is contained in:
eson 2020-11-23 18:50:25 +08:00
parent 4a60282e7e
commit 5c6dc47d47
7 changed files with 58 additions and 14 deletions

1
.gitignore vendored
View File

@ -1,2 +1,3 @@
*.crx
*.log
build

View File

@ -1 +1,5 @@
google-chrome --pack-extension=./chromeproxy --pack-extension-key=./chromeproxy.pem
rm build/ -rf
mkdir -p ./build
cd proxyserver && go build && mv proxyserver ../build/ && cd ..
cp start.sh build/start.sh
cp proxyserver/config.yaml build/config.yaml

2
build_crx.sh Normal file
View File

@ -0,0 +1,2 @@
google-chrome --pack-extension=./chromeproxy --pack-extension-key=./chromeproxy.pem

View File

@ -8,8 +8,11 @@ function GetTask(sender) {
response.json().then(function (task) {
if(task.code == 200) {
task_manager[sender.tab.id] = task;
chrome.tabs.executeScript(sender.tab.id, {runAt: "document_end", code: `window.location.href = "${task.data.url}"` }, function (results) {
})
var execCode = `window.location.href = "${task.data.url}";`
if(task.data.content_condition) {
execCode += `PassContentCondition = ${task.data.content_condition};`
}
chrome.tabs.executeScript(sender.tab.id, {runAt: "document_end", code: execCode})
Tell(sender, InjectMsgType.FETCH);
} else {
Tell(sender, InjectMsgType.NOTASK);
@ -92,12 +95,21 @@ function Tell(sender, jnjectType) {
// 配置使用的监听
chrome.webRequest.onBeforeRequest.addListener(function (details) {
if (details.url.startsWith("http://eson.config")) {
var params = new URLSearchParams(details.url)
var params = new URL(details.url).searchParams;
UpdateHost(params.get("taskurl"))
chrome.tabs.remove(details.tabId, function () { });
chrome.tabs.remove(details.tabId);
chrome.tabs.query({currentWindow: true}, function(tabs) {
for( tab in tabs) {
console.log(tab);
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}`});
}
})
return { cancel: true };

View File

@ -5,6 +5,16 @@ var GetTaskUrl = `${Host}/task/get`;
var FinishTaskUrl = `${Host}/task/content`;
var ErrorTaskUrl = `${Host}/task/error`;
var WorkerNumber = 10;
var PassContentCondition = undefined;
// 默认条件所有内容都获取
var DefaultContentCondition = function () {
return true;
// return href.startsWith("https://playerduo.com") && content.startsWith('<head></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">')
}
function UpdateHost(host) {
Host = host
GetTaskUrl = `${Host}/task/get`

View File

@ -23,20 +23,28 @@ chrome.runtime.onMessage.addListener(function (request) {
});
var href = window.location.href;
var content = document.documentElement.innerHTML;
if (href.startsWith("https://playerduo.com") && content.startsWith('<head></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">')) {
// var href = window.location.href;
// var content = document.documentElement.innerHTML;
var condition = PassContentCondition != undefined ? PassContentCondition : DefaultContentCondition;
if (condition()) {
Tell(BackgroundMsgType.CONTENT, content);
} else {
Tell(BackgroundMsgType.NOTWANT, content);
}
function Tell(backgroundType, content) {
if(content == undefined) {
chrome.runtime.sendMessage({type: backgroundType});
} else {
chrome.runtime.sendMessage({type: backgroundType, content: content});
try {
if(content == undefined) {
chrome.runtime.sendMessage({type: backgroundType});
} else {
chrome.runtime.sendMessage({type: backgroundType, content: content});
}
} catch (error) {
console.log(error);
window.location.href = Host;
}
}
function GetTask() {

7
start.sh Executable file
View File

@ -0,0 +1,7 @@
DISPLAY=:99
screen -L -dmS google-chrome-web google-chrome --load-extension=../chromeproxy --user-data-dir=/tmp/chromeproxy-userdata --ignore-certificate-errors --disable-dev-shm-usage --mute-audio --safebrowsing-disable-auto-update --disable-gpu --no-sandbox --disable-blink-features=AutomationControlled --disable-infobars --allow-running-insecure-content --disable-features=TranslateUI --test-type --no-report-upload --display=$DISPLAY
sleep 2s
echo "启动浏览器..."
screen -L -dmS proxyserver ./proxyserver
echo "启动代理服务器..."