forked from lovethebomb/bandcamp-feed-playlist
-
Notifications
You must be signed in to change notification settings - Fork 1
/
contentScript.js
118 lines (99 loc) · 4.13 KB
/
contentScript.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
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
import { bindControlKeys } from './modules/shared.js';
import { replaceFunctions } from './modules/overrides.js';
import { addFunctions, catchErrors } from './modules/player.js';
import { FeedPlaylist, initFeedPlaylist } from './modules/feed.js';
import { loadCollection } from './modules/profile.js';
/***************************
* BANDCAMP STREAMER *
* by A Flow of Code *
* github.com/aflowofcode *
**************************/
(function(window, document) {
// Don't bother initializing on pages where BCS is not applicable
// 404 "that something isn't here"
if (window.gplayerviews == undefined) return;
const bcplayer = window.playerview,
colplayer = window.collectionPlayer,
albumplayer = window.gplayerviews[0] ? window.gplayerviews[0]._playlist._player : false,
jQuery = window.jQuery,
pagedata = jQuery("#pagedata").data("blob");
// band album index (.../music) -> gplayerviews == [] and other players are undefined
if (!bcplayer && !colplayer && !albumplayer) return;
console.log('Bandcamp Streamer! (v1.6.1)');
// using more globals due to split into modules
// TODO: these should be namespaced
window.bcplayer = bcplayer;
window.colplayer = colplayer;
window.pagedata = pagedata;
// record original document title for updating with track/artist
window.originalTitle = window.document.title;
/*
some useful functions
colplayer.player2.currentTrackIndex()
colplayer.player2.currentTracklist()
colplayer.player2.currentState() -> "idle", "paused", "playing"
colplayer.player2.showPlay() -> true if play button showing (means not playing)
*/
// list all access keys & track titles in console
// for (key in colplayer.tracklists.collection) {console.log(`${key}: ${colplayer.tracklists.collection[key][0].trackTitle}`);}
if (!bcplayer && colplayer) {
// on collection page & need to modify some of that player's functions + add shuffle
replaceFunctions(colplayer);
addFunctions(colplayer);
catchErrors(colplayer.player2._playlist._player._html5player, 'collection');
// handle people loading on non wishlist or collection tabs (eg /followers)
const tab = pagedata.active_tab,
wishTab = document.querySelector('#grid-tabs > li[data-tab=wishlist]'),
collectionTab = document.querySelector('#grid-tabs > li[data-tab=collection]');
console.log('initial tab:', tab);
// save these to listen for switching playlists later
if (wishTab) {
wishTab.id = 'wishtab';
window.wishTab = wishTab;
}
collectionTab.id = 'collectiontab';
window.collectionTab = collectionTab;
if (tab !== 'wishlist' && tab !== 'collection') {
if (wishTab) wishTab.addEventListener('click', tabClicked);
collectionTab.addEventListener('click', tabClicked);
} else {
loadCollection(tab);
}
} else if (bcplayer) {
console.log('feed init');
catchErrors(bcplayer._playlist._player._html5player, 'feed');
bcplayer.feed_playlist = [];
}
function tabClicked(e) {
e.stopPropagation();
let targetTab = false,
epath = e.path || e.composedPath();
console.log(e);
for (let i = 0; i < epath.length; i++) {
if (epath[i].id === 'wishtab') {
targetTab = 'wishlist';
break;
}
}
if (!targetTab) targetTab = 'collection';
collectionTab.removeEventListener('click', tabClicked);
if (wishTab) wishTab.removeEventListener('click', tabClicked);
loadCollection(targetTab);
}
/**********************************************************
********** FEED FUNCTIONS ********************************
**********************************************************/
window.originalPlaylist = bcplayer ? bcplayer._playlist._playlist : '';
window.releasePlaylist = [];
window.releasePlaylistLength = 0;
window.currentList = 'feed';
window.nowPlaying = document.getElementById('track_play_waypoint');
initFeedPlaylist(FeedPlaylist);
// init feed player
window.feedPlayer = bcplayer ? new FeedPlaylist(bcplayer, originalPlaylist) : false;
bindControlKeys({
bcplayer,
colplayer,
albumplayer
});
})(window, document);