feat(contentjson): add judge the json of content

This commit is contained in:
eson 2020-11-25 17:44:52 +08:00
parent b14615f339
commit 9e2d9d5abc
2 changed files with 29 additions and 19 deletions
chromeproxy/background

View File

@ -1,6 +1,17 @@
var href = window.location.href;
var content = document.documentElement.innerHTML;
function Tell(backgroundType, 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;
}
}
try {
if (condition == undefined) {
condition = function () {
@ -13,6 +24,13 @@ try {
};
}
var href = window.location.href;
var content = "";
if(document.contentType == "application/json") {
content = document.documentElement.innerText;
} else {
content = document.documentElement.innerHTML;
}
if (condition()) {
Tell(BackgroundMsgType.CONTENT, content);
@ -20,15 +38,3 @@ if (condition()) {
Tell(BackgroundMsgType.NOTWANT, content);
}
function Tell(backgroundType, 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;
}
}

View File

@ -23,7 +23,7 @@ chrome.runtime.onMessage.addListener(function (request, sender, sendResponse) {
CaptureContentCurrentPage(sender.tab.id);
}, task.data.waitcapture);
} else {
task.data.retry --;
if(task.data.retry >= 0) {
setTimeout(function(){
@ -48,7 +48,6 @@ function GetTask(sender) {
fetch(GetTaskUrl).then(function (response) {
if (response.ok) {
response.json().then(function (task) {
CaptureContent(task);
})
} else {
@ -62,7 +61,9 @@ function GetTask(sender) {
}
function CaptureContentCurrentPage(tabid) {
chrome.tabs.executeScript(tabid, { runAt: "document_end", file: "background/capture.js" });
chrome.tabs.executeScript(tabid, { runAt: "document_end", file: "base.js" }, function(){
chrome.tabs.executeScript(tabid, { runAt: "document_end", file: "background/capture.js" });
});
}
function CaptureContent(task) {
@ -75,8 +76,11 @@ function CaptureContent(task) {
chrome.tabs.create({ url: task.data.url }, function (tab) {
task_manager[tab.id] = task;
if (task.data.content_condition) {
condition = `${task.data.content_condition}`
condition = `${task.data.content_condition}`;
} else {
condition = undefined;
}
if (condition != undefined) {
chrome.tabs.executeScript(tab.id, { runAt: "document_end", code: condition }, function () {
CaptureContentCurrentPage(tab.id)