Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remember known shorts locally #219

Merged
merged 34 commits into from
Nov 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
f1664c8
Updated heading
NikkelM Sep 19, 2023
5473ac9
Updated changelog
NikkelM Sep 19, 2023
f3e116f
WIP for multiple video types in local playlistInfo
NikkelM Sep 19, 2023
b82c4f9
Fixed wrong return value if database value is falsy
NikkelM Oct 22, 2023
4398bac
Merge branch 'main' into local-shorts
NikkelM Oct 22, 2023
3fcab5e
Updated changelog
NikkelM Oct 22, 2023
a86a707
Updated variables, logs
NikkelM Oct 22, 2023
d84ad4d
Added logic for comparing local and database video data sets
NikkelM Oct 22, 2023
fd06527
Added better comments, resolved TODO's
NikkelM Oct 22, 2023
01fab15
Filtering WIP
NikkelM Oct 27, 2023
abfbb85
Merge branch 'main' into local-shorts
NikkelM Oct 27, 2023
0d184cf
Use correct filtering
NikkelM Nov 2, 2023
2f936fb
Removed debug code
NikkelM Nov 4, 2023
68c3bce
Added button message if ignoring shorts
NikkelM Nov 4, 2023
fc84178
Updated version, changelog
NikkelM Nov 4, 2023
bd65eae
Renamed variables
NikkelM Nov 4, 2023
c1afe2d
Test playlists now use the new localPlaylist format
NikkelM Nov 4, 2023
a5727eb
Updated playlist names
NikkelM Nov 4, 2023
c86f3d0
Fixed local storage access, test
NikkelM Nov 4, 2023
7c4a3cf
Assigned videos to the correct playlist
NikkelM Nov 4, 2023
2a60c24
Correctly merge playlist objects after fetching from DB
NikkelM Nov 4, 2023
6d460d9
Fixed playlist access
NikkelM Nov 4, 2023
8ae92d2
Join videos before shuffling
NikkelM Nov 4, 2023
24ca7e2
More diversity in choosing playlists for testing user settings
NikkelM Nov 4, 2023
a4ec5ed
Fixed some tests
NikkelM Nov 4, 2023
7d4b236
Fixed some tests
NikkelM Nov 4, 2023
9d05232
Fixed tests, bugs, removed unnecessary assignment
NikkelM Nov 4, 2023
8fc1343
Fixed, updated tests
NikkelM Nov 4, 2023
fdd432b
Formatting
NikkelM Nov 4, 2023
a731387
Fixed behaviour and added test for no video data in DB
NikkelM Nov 4, 2023
b5c1467
Exclude some code from coverage, change some wording
NikkelM Nov 4, 2023
a9e0e21
Updated changelog
NikkelM Nov 4, 2023
460c546
Updated comments
NikkelM Nov 4, 2023
9088aa0
Updated changelog
NikkelM Nov 4, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
# Changelog

## v2.2.4
## v2.3.0

<!--Releasenotes start-->
- Shuffling when excluding shorts is now a lot quicker if you have shuffled from the channel before, as the extension will remember which videos are shorts and skip them automatically.
- Added an additional message to the shuffle button if shuffling takes a bit longer due to ignoring shorts.
- Fixed a rare data inconsistency bug occurring with specific database values.
<!--Releasenotes end-->

## v2.2.4

- Fixed an alignment issue of the shuffle button on channel pages that was introduced with the latest update to the YouTube UI.
- Fixed some issues with the display of the shuffle button if the shuffle icon is not loaded in time.
<!--Releasenotes end-->

## v2.2.3

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ Did you find any bugs with the version you tested? Please let me know by [openin
- The bundled extension files will be placed in the `dist/<browser>` directories.
- You can load the extension in your browser by following the instructions below.

#### Chrome/Chromium
#### Chromium

- Open the Extension Management page by navigating to `chrome://extensions`.
- Make sure that you have enabled developer mode.
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "random-youtube-video",
"version": "2.2.4",
"version": "2.3.0",
"description": "Play a random video uploaded on the current YouTube channel.",
"scripts": {
"dev": "concurrently \"npm run dev:chromium\" \"npm run dev:firefox\"",
Expand Down
6 changes: 3 additions & 3 deletions src/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ chrome.runtime.onStartup.addListener(async function () {
console.log(`${((utilizedStorage / maxLocalStorage) * 100).toFixed(2)}% of local storage is used. (${utilizedStorage}/${maxLocalStorage} bytes)`);

if (maxLocalStorage * 0.9 < utilizedStorage) {
console.log("Local storage is over 90% utilized. Removing playlists that have not been accessed the longest...");
console.log("Local storage is over 90% utilized. Removing playlists that have not been accessed the longest to free up some space...");

// Get all playlists from local storage
const localStorageContents = await chrome.storage.local.get();

// We only need the keys that hold playlists, which is signified by the existence of the "videos" sub-key
const allPlaylists = Object.fromEntries(Object.entries(localStorageContents).filter(([k, v]) => v["videos"]));
const allPlaylists = Object.fromEntries(Object.entries(localStorageContents).filter(([key, value]) => value["videos"]));

// Sort the playlists by lastAccessedLocally value
const sortedPlaylists = Object.entries(allPlaylists).sort((a, b) => {
Expand Down Expand Up @@ -324,7 +324,7 @@ async function openVideoInTabWithId(tabId, videoUrl) {
// ---------- Local storage ----------
async function getFromLocalStorage(key) {
return await chrome.storage.local.get([key]).then((result) => {
if (result[key]) {
if (result[key] !== undefined) {
return result[key];
}
return null;
Expand Down
3 changes: 3 additions & 0 deletions src/content.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,9 @@ async function shuffleVideos() {
var hasBeenShuffled = false;
setDOMTextWithDelay(shuffleButtonTextElement, "\xa0Shuffling...", 1000, () => { return (shuffleButtonTextElement.innerText === "\xa0Shuffle" && !hasBeenShuffled); });
setDOMTextWithDelay(shuffleButtonTextElement, "\xa0Still on it...", 5000, () => { return (shuffleButtonTextElement.innerText === "\xa0Shuffling..." && !hasBeenShuffled); });
if (configSync.shuffleIgnoreShortsOption) {
setDOMTextWithDelay(shuffleButtonTextElement, "\xa0Sorting shorts...", 8000, () => { return (shuffleButtonTextElement.innerText === "\xa0Still on it..." && !hasBeenShuffled); });
}

await chooseRandomVideo(channelId, false, shuffleButtonTextElement);
hasBeenShuffled = true;
Expand Down
187 changes: 143 additions & 44 deletions src/shuffleVideo.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion static/manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "Random YouTube Video",
"description": "Play a random video uploaded on the current YouTube channel.",
"version": "2.2.4",
"version": "2.3.0",
"manifest_version": 3,
"content_scripts": [
{
Expand Down
343 changes: 193 additions & 150 deletions test/playlistPermutations.js

Large diffs are not rendered by default.

115 changes: 81 additions & 34 deletions test/shuffleVideo.test.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion test/testSetup.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ chrome.runtime.sendMessage.callsFake((request) => {
// Only for the tests
case "setKeyInDB":
mockedDatabase[request.data.key] = request.data.val;
return "Key was removed from database.";
return "Key was set in the database (mocked for tests).";

case "getAPIKey":
return getAPIKey(false, request.data.useAPIKeyAtIndex);
Expand Down