TODO: 重构inject.js 利用tabs.executeScript 回调通信. 实现对内容的判断与获取.
This commit is contained in:
@@ -1,19 +1,19 @@
|
||||
|
||||
|
||||
|
||||
chrome.runtime.onMessage.addListener(function (request) {
|
||||
switch(request.type) {
|
||||
switch (request.type) {
|
||||
case InjectMsgType.WAIT:
|
||||
setTimeout(function(){
|
||||
setTimeout(function () {
|
||||
GetTask();
|
||||
}, 6000);
|
||||
break;
|
||||
case InjectMsgType.NOTASK:
|
||||
setTimeout(function(){
|
||||
setTimeout(function () {
|
||||
GetTask();
|
||||
}, 4000);
|
||||
break;
|
||||
case InjectMsgType.FETCH:
|
||||
setTimeout(function(){
|
||||
setTimeout(function () {
|
||||
GetTask();
|
||||
}, 6000)
|
||||
break;
|
||||
@@ -22,23 +22,30 @@ chrome.runtime.onMessage.addListener(function (request) {
|
||||
};
|
||||
});
|
||||
|
||||
|
||||
// var href = window.location.href;
|
||||
// var content = document.documentElement.innerHTML;
|
||||
|
||||
var condition = PassContentCondition != undefined ? PassContentCondition : DefaultContentCondition;
|
||||
if (condition()) {
|
||||
Tell(BackgroundMsgType.CONTENT, content);
|
||||
var href = window.location.href;
|
||||
var content = document.documentElement.innerHTML;
|
||||
if (href.startsWith(Host)) {
|
||||
GetTask();
|
||||
} else {
|
||||
Tell(BackgroundMsgType.NOTWANT, content);
|
||||
var condition = PassContentCondition != undefined ? PassContentCondition : DefaultContentCondition;
|
||||
if (condition()) {
|
||||
console.log(condition, PassContentCondition);
|
||||
Tell(BackgroundMsgType.CONTENT, content);
|
||||
} else {
|
||||
console.log(condition, PassContentCondition);
|
||||
Tell(BackgroundMsgType.NOTWANT, content);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
function Tell(backgroundType, content) {
|
||||
try {
|
||||
if(content == undefined) {
|
||||
chrome.runtime.sendMessage({type: backgroundType});
|
||||
if (content == undefined) {
|
||||
chrome.runtime.sendMessage({ type: backgroundType });
|
||||
} else {
|
||||
chrome.runtime.sendMessage({type: backgroundType, content: content});
|
||||
chrome.runtime.sendMessage({ type: backgroundType, content: content });
|
||||
}
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
|
||||
Reference in New Issue
Block a user