Skip to content

Commit

Permalink
v2.4.0: Scan current tab for YouTube links and create a playlist #24
Browse files Browse the repository at this point in the history
  • Loading branch information
soufianesakhi committed Aug 26, 2021
1 parent 257f30c commit 4246877
Show file tree
Hide file tree
Showing 9 changed files with 64 additions and 11 deletions.
26 changes: 24 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
"description": "Generate YouTube playlists from bookmarks and URL lists",
"author": "Soufiane Sakhi <soufiane.sakhi.js@gmail.com>",
"license": "MIT",
"scripts": {
"build": "cd playlist-editor && npm run build"
},
"dependencies": {},
"devDependencies": {
"@types/firefox-webext-browser": "^70.0.1",
Expand Down
14 changes: 7 additions & 7 deletions playlist-editor/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion playlist-editor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"@rollup/plugin-node-resolve": "^11.0.0",
"@rollup/plugin-replace": "^2.4.1",
"@rollup/plugin-typescript": "^8.0.0",
"@tsconfig/svelte": "^1.0.0",
"@tsconfig/svelte": "^1.0.13",
"@types/firefox-webext-browser": "^82.0.0",
"cors-anywhere-cli": "^1.2.0",
"http-proxy": ">=1.18.1",
Expand Down
Binary file modified screenshots/extension-popup-menu.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified screenshots/extension-popup-menu_firefox.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion src/manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "YouTube Playlist Helper",
"description": "Generate YouTube playlists from various sources (links lists, bookmarks, ...)",
"version": "2.3.0",
"version": "2.4.0",
"manifest_version": 2,
"icons": {
"48": "icons/icon_48.png",
Expand Down
3 changes: 3 additions & 0 deletions src/popup/popup.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
<div id="from-current-thumbnails" class="menu-item">
Create a playlist from current tab YouTube video thumbnails
</div>
<div id="from-current-links" class="menu-item">
Scan current tab for YouTube links and create a playlist
</div>

<div id="save-playlist" class="menu-item">Save current playlist</div>
<div id="open-settings" class="menu-item">Settings</div>
Expand Down
25 changes: 25 additions & 0 deletions src/popup/popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,17 @@ getById("from-current-thumbnails").onclick = async () => {
}
};

getById("from-current-links").onclick = async () => {
let body = await getCurrentTabBody();
let videoIds = parseYoutubeLinks(body);
videoIds = removeDuplicates(videoIds);
if (videoIds.length > 0) {
await createPlaylist(videoIds);
} else {
alert("No YouTube video link found in the current tab");
}
};

getById("save-playlist").onclick = async () => {
const activeTab = await getActiveTab();
if (!(isYoutubeTab(activeTab) && isPlaylistTab(activeTab))) {
Expand Down Expand Up @@ -335,6 +346,20 @@ function parseYoutubeThumbnailIds(text) {
return videoIds;
}

/**
* @param {string} text
*/
function parseYoutubeLinks(text) {
let matches,
videoIds = [];
const regex = RegExp(youtubeRegexPattern, "ig");
while ((matches = regex.exec(text))) {
const videoId = matches[1].replace(/"$/, "");
videoIds.push(videoId);
}
return videoIds;
}

/***********************************
* Playlists
***********************************/
Expand Down

0 comments on commit 4246877

Please sign in to comment.