-
Notifications
You must be signed in to change notification settings - Fork 110
/
Copy pathshared.js
98 lines (80 loc) · 2.51 KB
/
shared.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
var currentVersion = parseInt(chrome.runtime.getManifest().version.replace(/\./g, ''));
var storageKeys = {
"showRepeat": "showRepeat",
"profiles": "profiles",
"enableMultiHost": "enableMultiHost",
"selectedHost": "selectedHost",
"enableDebugLogs": "enableDebugLogs",
"magnetAddOn": "magnetAddOn"
};
var actions = {
"PlayPause": "Player.PlayPause",
"Stop": "Player.Stop",
"SmallSkipBackward":"VideoPlayer.SmallSkipBackward",
"SmallSkipForward":"VideoPlayer.SmallSkipForward",
"GoPrevious": "Player.GoPrevious",
"GoNext": "Player.GoNext"
};
var validPlaylistPatterns = [
".*youtube.com/playlist.*list=.*",
"(https|http)://(www\.)?youtube.com/watch?.*list=.+",
"(https|http)://(www\.)?soundcloud.com/[^_&/#\?]+/sets/[^_&/#\?]+"
];
function getCurrentProfile() {
var profile;
var selectedHost = localStorage[storageKeys.selectedHost];
var allProfiles = JSON.parse(getAllProfiles());
for (var i = 0; i < allProfiles.length; i++) {
var profile = allProfiles[i];
if (profile.id == selectedHost) {
profile = profile;
break;
}
}
return profile;
}
function getURL() {
var url;
var port;
if (isMultiHostEnabled()) {
var profile = getCurrentProfile();
url = profile.url;
port = profile.port;
} else {
url = localStorage["url"];
port = localStorage["port"];
}
// Handle https in the url
if (url.includes('https://')) {
// Remove https in url and append after
// so user/pass is in the correct place
url = url.replace('https://', '')
return 'https://'+url + ':' + port;
} else {
return 'http://'+url + ':' + port;
}
}
function getCredentials() {
var username;
var password;
if (isMultiHostEnabled()) {
var profile = getCurrentProfile();
username = profile.username;
password = profile.password;
} else {
username = localStorage["username"];
password = localStorage["password"];
}
return [username ? username : "anonymous", password];
}
function isMultiHostEnabled() {
var enableMultiHost = localStorage[storageKeys.enableMultiHost];
return enableMultiHost != null && enableMultiHost == 'true';
}
function isDebugLogsEnabled() {
var enableDebugLogs = localStorage[storageKeys.enableDebugLogs];
return enableDebugLogs != null && enableDebugLogs == 'true';
}
function getAllProfiles() {
return localStorage[storageKeys.profiles];
}