-
Notifications
You must be signed in to change notification settings - Fork 4
/
join_giveaway.js
67 lines (59 loc) · 1.82 KB
/
join_giveaway.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
var joinStatus = {comment: false, join: false, tryCount: 1};
if (rewriteStatus) {
joinStatus = rewriteStatus;
}
var mainTimeout = setTimeout(function () {
returnStatus();
}, 10000);
$(document).ready(function () {
joinGiveaway();
});
function joinGiveaway() {
if (joinStatus.join == false && vis.canJoinGiveaway()) {
$('.sidebar__entry-insert').click();
addComment();
setTimeout(function () {
checkJoinStatus();
checkCommentStatus();
returnStatus();
}, 3000);
} else {
returnStatus();
}
}
function addComment() {
if (joinStatus.comment == false) {
console.log('comment');
chrome.storage.sync.get(['join_comment'], function (result) {
var comment = (typeof result.join_comment == 'undefined' ? null : result.join_comment);
if (comment) {
var cForm = $('.comment--submit form').last();
$('textarea[name=description]', cForm).val(comment);
$.ajax({
url: window.location.href,
type: 'post',
dataType: 'json',
data: cForm.serialize()
})
} else {
joinStatus.comment = true;
}
});
}
}
function checkJoinStatus() {
if (!vis.joinIsLoading() && !vis.canJoinGiveaway()) {
joinStatus.join = true;
}
}
function checkCommentStatus() {
joinStatus.comment = true;
}
function returnStatus() {
clearTimeout(mainTimeout);
if (joinStatus.comment && joinStatus.join) {
chrome.extension.sendRequest({ action: "removeTab" });
} else {
chrome.extension.sendRequest({ action: "rejoin", joinStatus: joinStatus });
}
}