feat(contentjson): add judge the json of content
This commit is contained in:
parent
b14615f339
commit
9e2d9d5abc
|
@ -1,24 +1,3 @@
|
||||||
var href = window.location.href;
|
|
||||||
var content = document.documentElement.innerHTML;
|
|
||||||
|
|
||||||
try {
|
|
||||||
if (condition == undefined) {
|
|
||||||
condition = function () {
|
|
||||||
return true;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
condition = function () {
|
|
||||||
return true;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if (condition()) {
|
|
||||||
Tell(BackgroundMsgType.CONTENT, content);
|
|
||||||
} else {
|
|
||||||
Tell(BackgroundMsgType.NOTWANT, content);
|
|
||||||
}
|
|
||||||
|
|
||||||
function Tell(backgroundType, content) {
|
function Tell(backgroundType, content) {
|
||||||
try {
|
try {
|
||||||
|
@ -32,3 +11,30 @@ function Tell(backgroundType, content) {
|
||||||
window.location.href = Host;
|
window.location.href = Host;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (condition == undefined) {
|
||||||
|
condition = function () {
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
condition = function () {
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
} else {
|
||||||
|
Tell(BackgroundMsgType.NOTWANT, content);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -48,7 +48,6 @@ function GetTask(sender) {
|
||||||
fetch(GetTaskUrl).then(function (response) {
|
fetch(GetTaskUrl).then(function (response) {
|
||||||
if (response.ok) {
|
if (response.ok) {
|
||||||
response.json().then(function (task) {
|
response.json().then(function (task) {
|
||||||
|
|
||||||
CaptureContent(task);
|
CaptureContent(task);
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
|
@ -62,7 +61,9 @@ 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) {
|
||||||
|
@ -75,8 +76,11 @@ function CaptureContent(task) {
|
||||||
chrome.tabs.create({ url: task.data.url }, function (tab) {
|
chrome.tabs.create({ url: task.data.url }, function (tab) {
|
||||||
task_manager[tab.id] = task;
|
task_manager[tab.id] = task;
|
||||||
if (task.data.content_condition) {
|
if (task.data.content_condition) {
|
||||||
condition = `${task.data.content_condition}`
|
condition = `${task.data.content_condition}`;
|
||||||
|
} else {
|
||||||
|
condition = undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (condition != undefined) {
|
if (condition != undefined) {
|
||||||
chrome.tabs.executeScript(tab.id, { runAt: "document_end", code: condition }, function () {
|
chrome.tabs.executeScript(tab.id, { runAt: "document_end", code: condition }, function () {
|
||||||
CaptureContentCurrentPage(tab.id)
|
CaptureContentCurrentPage(tab.id)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user