-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.js
More file actions
47 lines (43 loc) · 1.26 KB
/
Copy pathutils.js
File metadata and controls
47 lines (43 loc) · 1.26 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
// YouTube Bookmark Extension - Utility Functions
// Helper functions used across the extension
/**
* Get the current active tab
* @returns {Promise<Object>} The active tab object
*/
export async function getActiveTabUrl() {
try {
const queryOptions = { active: true, currentWindow: true };
const [tab] = await chrome.tabs.query(queryOptions);
return tab;
} catch (error) {
console.error('Error getting active tab:', error);
return null;
}
}
/**
* Extract video ID from YouTube URL
* @param {string} url - YouTube URL
* @returns {string|null} Video ID or null
*/
export function getVideoIdFromUrl(url) {
try {
const urlObj = new URL(url);
return urlObj.searchParams.get('v');
} catch (e) {
return null;
}
}
/**
* Format seconds to MM:SS or HH:MM:SS format
* @param {number} totalSeconds - Total seconds
* @returns {string} Formatted time string
*/
export function formatTime(totalSeconds) {
const hours = Math.floor(totalSeconds / 3600);
const minutes = Math.floor((totalSeconds % 3600) / 60);
const seconds = Math.floor(totalSeconds % 60);
if (hours > 0) {
return `${hours}:${minutes.toString().padStart(2, '0')}:${seconds.toString().padStart(2, '0')}`;
}
return `${minutes}:${seconds.toString().padStart(2, '0')}`;
}