-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
99 lines (85 loc) · 2.65 KB
/
script.js
File metadata and controls
99 lines (85 loc) · 2.65 KB
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
// hide comments
(function() {
$('li.player .player.mode').toggleClass('no-comments');
})();
(function() {
// create localStorage array if undefined
if(localStorage['scm_tracks'] === undefined) {
localStorage['scm_tracks']=JSON.stringify([]);
}
function moderateHandle(context, reason) {
// get the localStorage string
var moderatedTracks = JSON.parse(localStorage['scm_tracks']);
//track id
var id = $(context).closest('li.player').find('.player.mode').attr('data-sc-track'),
// parse the string to an array
moderatedTracks = JSON.parse(localStorage['scm_tracks']),
// is the track already in the db ?
track = hasBeenModerated(moderatedTracks, id),
// init date obj
date = new Date(),
// create dateString
dateString = dateString = date.getDate() + '/' + date.getMonth();
if(! track) {
//create a new track
track = {
'id': id,
'a': reason,
d: dateString
};
//push the track to the array.
moderatedTracks.push(track);
}
else {
//find the index of the existing track
var i = moderatedTracks.indexOf(track);
moderatedTracks[i].d = dateString
moderatedTracks[i].a = reason;
}
localStorage['scm_tracks'] = JSON.stringify(moderatedTracks);
}
// extend the soundcloud approve button click handle to save the track id.
$('a.approve.icon-button.contribution').click(function() {
moderateHandle(this, 1)
});
// destroy
$('a.destroy.icon-button.contribution.remove').click(function() {
moderateHandle(this, 0)
});
$('li.player').each(function() {
//player context
var $player = $(this),
// is the track under moderation ?
$underMod = $player.find('div.moderate-track'),
//the track
$track = $player.find('.player.mode');
// if the track is under moderation proceed
if( $underMod.length > 0 ) {
var moderatedTracks = JSON.parse(localStorage['scm_tracks']),
id = $track.attr('data-sc-track'),
track = hasBeenModerated( moderatedTracks, id );
if(track) {
var $inner = $underMod.find('.moderate-track-inner');
$inner.css('background' , 'lightCoral');
//get the track title
var track_title = $player.find('.info-header h3 a').text(),
action = track.a ? 'approved' : 'disapproved'
// forge the message
var $msg = $('<div></div>').html('<b>' + track_title + '</b> was last seen <b>' + track.d + '</b> and was <b>' + action + '</b>');
$msg.prependTo($inner);
}
else {
//console.log(track_id+' has not been moderated');
}
}
})
// checks an array with objects if the 'id' is present
function hasBeenModerated (arr,val) {
for(var i in arr) {
if(arr[i].id == val) {
return arr[i];
}
}
return undefined;
}
})();