-
Notifications
You must be signed in to change notification settings - Fork 447
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
39ca9ee
commit 868f55b
Showing
6 changed files
with
75 additions
and
4,523 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/** | ||
* 根据任务ID获取任务,执行点击 | ||
* @param taskId | ||
*/ | ||
function secKill(taskId) { | ||
console.log("开始秒杀!"); | ||
console.log(taskId); | ||
chrome.storage.local.get({"tasks": new Array()}, function(value) { | ||
tasks = value.tasks; | ||
if(tasks != undefined && tasks != null && tasks.length > 0) { | ||
for(var i=0; i<tasks.length; i++) { | ||
if(taskId == tasks[i].id) { | ||
dealTask(tasks[i]); | ||
} | ||
} | ||
} | ||
}); | ||
} | ||
|
||
/** | ||
* 根据xPath查询节点 | ||
* @param STR_XPATH | ||
* @returns {Array} | ||
*/ | ||
function getElementsByXPath(STR_XPATH) { | ||
var xresult = document.evaluate(STR_XPATH, document, null, XPathResult.ANY_TYPE, null); | ||
var xnodes = []; | ||
var xres; | ||
while (xres = xresult.iterateNext()) { | ||
xnodes.push(xres); | ||
} | ||
return xnodes; | ||
} | ||
|
||
/** | ||
* 处理任务 | ||
* @param task | ||
*/ | ||
function dealTask(task) { | ||
var count = 0; | ||
var timer = setInterval(function () { | ||
if(task.selector == "jQuery") { | ||
$(task.location).each(function(){ | ||
this.click(); | ||
}); | ||
} else { | ||
$(getElementsByXPath(task.location)).each(function(){ | ||
this.click(); | ||
}); | ||
} | ||
count++; | ||
if(count>task.count) { | ||
clearInterval(timer); | ||
} | ||
}, task.frequency); | ||
|
||
} |
Oops, something went wrong.