feat(config): add retry and waitcapture property

This commit is contained in:
eson 2020-11-25 16:34:15 +08:00
parent 899f554336
commit b14615f339
7 changed files with 54 additions and 28 deletions

View File

@ -2,30 +2,22 @@ var href = window.location.href;
var content = document.documentElement.innerHTML;
try {
if(waittime === undefined) {
waittime = 6000
if (condition == undefined) {
condition = function () {
return true;
};
}
} catch (error) {
waittime = 6000
}
if (condition == undefined) {
condition = function () {
return true;
};
}
if (condition()) {
Tell(BackgroundMsgType.CONTENT, content);
} else {
setTimeout(function () {
if (condition()) {
Tell(BackgroundMsgType.CONTENT, content);
} else {
Tell(BackgroundMsgType.NOTWANT, content);
}
}, waittime)
Tell(BackgroundMsgType.NOTWANT, content);
}
function Tell(backgroundType, content) {

View File

@ -16,16 +16,29 @@ chrome.runtime.onMessage.addListener(function (request, sender, sendResponse) {
GetTask(sender);
break;
case BackgroundMsgType.NOTWANT:
task = task_manager[sender.tab.id];
task.data.retry --;
if(task.data.retry >= 0) {
CaptureContent(task);
} else {
ErrorTask(sender, request.content);
}
if(task.data.waitcapture != undefined) {
setTimeout(function(){
CaptureContentCurrentPage(sender.tab.id);
}, task.data.waitcapture);
} else {
task.data.retry --;
if(task.data.retry >= 0) {
setTimeout(function(){
CaptureContent(task);
}, 6000)
} else {
ErrorTask(sender, request.content);
}
}
break;
case BackgroundMsgType.CLOSETAB:
delete task_manager[sender.tab.id]
chrome.tabs.remove(sender.tab.id);
default:
break;
}
@ -48,6 +61,10 @@ function GetTask(sender) {
})
}
function CaptureContentCurrentPage(tabid) {
chrome.tabs.executeScript(tabid, { runAt: "document_end", file: "background/capture.js" });
}
function CaptureContent(task) {
if (task.code == 200) {
@ -60,12 +77,12 @@ function CaptureContent(task) {
if (task.data.content_condition) {
condition = `${task.data.content_condition}`
}
if (condition) {
if (condition != undefined) {
chrome.tabs.executeScript(tab.id, { runAt: "document_end", code: condition }, function () {
chrome.tabs.executeScript(tab.id, { runAt: "document_end", file: "background/capture.js" });
CaptureContentCurrentPage(tab.id)
});
} else {
chrome.tabs.executeScript(tab.id, { runAt: "document_end", file: "background/capture.js" });
CaptureContentCurrentPage(tab.id)
}
});
}
@ -74,7 +91,7 @@ function CaptureContent(task) {
function FinishTask(sender, content) {
var task = task_manager[sender.tab.id];
var formdata = new FormData();
formdata.append("taskid", task.data.taskid);
formdata.append("content", content);

View File

@ -19,6 +19,7 @@ const BackgroundMsgType = {
CONTENT: 'content',
GETTASK: 'gettask',
TIMEOUT: 'timeout',
CLOSETAB: 'closetab',
ERROR: 'error',
OK: 'ok',
};

View File

@ -5,7 +5,7 @@ if(href.startsWith(Host)) {
}, 1);
} else {
setTimeout(function(){
close();
chrome.runtime.sendMessage({ type: BackgroundMsgType.CLOSETAB })
}, 15000)
}

View File

@ -4,6 +4,7 @@ import (
"fmt"
"log"
"net/http"
"strconv"
"time"
"github.com/bwmarrin/snowflake"
@ -85,6 +86,18 @@ func PutTask(c *gin.Context) {
data.Store("label", label)
data.Store("content_condition", c.PostForm("content_condition"))
if waitcapture, err := strconv.Atoi(c.PostForm("waitcapture")); err != nil {
data.Store("waitcapture", 1)
} else {
data.Store("waitcapture", waitcapture)
}
if retry, err := strconv.Atoi(c.PostForm("retry")); err != nil {
data.Store("retry", 1)
} else {
data.Store("retry", retry)
}
taskQueue.Push(tid, data)
oplog.Write(data)
c.JSON(http.StatusOK, Response{Code: 200, Message: "ok", Data: data})
@ -110,7 +123,6 @@ func ContentTask(c *gin.Context) {
task.Store("status", "ready")
readyQueue.Push(tid, task) // 进入回调发送队列.TODO: 内容持久化
c.JSON(200, Response{Code: 200, Data: task})
// log.Println("start callback")
if label, ok := task.Load("label"); ok {
log.Println(label.(string), tid)
}

2
screenlog.0 Normal file
View File

@ -0,0 +1,2 @@
Cannot exec './proxyserver': 权限不够
^C

View File

@ -1,6 +1,8 @@
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
rm /tmp/chromeproxy-userdata/ -rf
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 --disable-breakpad --no-first-run --display=$DISPLAY
sleep 2s
echo "启动浏览器..."
screen -L -dmS proxyserver ./proxyserver