-
Notifications
You must be signed in to change notification settings - Fork 4
/
quickblocker.js
60 lines (56 loc) · 2.58 KB
/
quickblocker.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
var authToken = $('.authenticity_token').val();
var imgURL = chrome.extension.getURL("quickblocker.png");
$(document).ready(function(){
$('.ProfileTweet-action--favorite').not('.u-hiddenVisually').addClass('quickblockered').after('<a class="blocky" style="background-image: url('+imgURL+')" title="Block this user"> </div>');
});
$(document).bind('DOMNodeInserted', function(e) {
if ($(e.target).find('.ProfileTweet-action--favorite')) {
$(e.target).find('.ProfileTweet-action--favorite').not('.u-hiddenVisually').not('.quickblockered').addClass('quickblockered').after('<a class="blocky" style="background-image: url('+imgURL+')" title="Block this user"> </div>');
}
}); //bind
$(document).on('click', '.blocky', function(){
var self = this;
if ($(self).parents('.Grid[data-component-term="tweet"]').length) {
console.log('one');
bigthing = self;
var submissionObject = {
'authenticity_token':authToken,
'block_user':true,
'report_type':null,
'screen_name':$(self).parents('.Grid[data-component-term="tweet"]').find('.ProfileTweet-screenname').text().trim().slice(1),
'tweet_id':$(self).parents('.Grid[data-component-term="tweet"]').find('.js-stream-item').attr('data-item-id'),
'user_id':$(self).parents('.Grid[data-component-term="tweet"]').find('.js-tweet.js-stream-tweet').attr('data-user-id'),
}
} else {
console.log('two');
var submissionObject = {
'authenticity_token':authToken,
'block_user':true,
'report_type':null,
'screen_name':$(self).parents('.tweet').find('.username.js-action-profile-name').text().trim().slice(1),
'tweet_id':$(self).parents('.tweet').attr('data-tweet-id'),
'user_id':$(self).parents('.tweet').attr('data-user-id'),
}
}
console.log(submissionObject);
$.ajax({
type: "POST",
data: submissionObject,
url: "/i/tweet/report",
headers: {
Accept : "application/json, text/javascript, */*; q=0.01",
},
success: function(m1, m2, m3) {
// console.log('Ok!', m1, m2, m3);
}, //success
error: function (m1, err2, err3){
if (JSON.parse(m1.responseText).message.indexOf('has been blocked')) {
$('.tweet').find('.js-action-profile-name.username:contains('+submissionObject.screen_name+')').parents('.stream-item').slideUp(200)
$('.tweet').find('.js-action-profile-name.username:contains('+submissionObject.screen_name+')').parents('.Grid[data-component-term="tweet"]').slideUp(200)
setTimeout(function(){
alert('User '+submissionObject.screen_name+' has been blocked.');
}, 300)
}
} //error
}); //ajax
}) //on click