Skip to content

Commit 31403be

Browse files
authored
Remember known shorts locally (#219)
1 parent 89ed0d0 commit 31403be

File tree

10 files changed

+435
-237
lines changed

10 files changed

+435
-237
lines changed

CHANGELOG.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
# Changelog
22

3-
## v2.2.4
3+
## v2.3.0
44

55
<!--Releasenotes start-->
6+
- 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.
7+
- Added an additional message to the shuffle button if shuffling takes a bit longer due to ignoring shorts.
8+
- Fixed a rare data inconsistency bug occurring with specific database values.
9+
<!--Releasenotes end-->
10+
11+
## v2.2.4
12+
613
- Fixed an alignment issue of the shuffle button on channel pages that was introduced with the latest update to the YouTube UI.
714
- Fixed some issues with the display of the shuffle button if the shuffle icon is not loaded in time.
8-
<!--Releasenotes end-->
915

1016
## v2.2.3
1117

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ Did you find any bugs with the version you tested? Please let me know by [openin
7272
- The bundled extension files will be placed in the `dist/<browser>` directories.
7373
- You can load the extension in your browser by following the instructions below.
7474

75-
#### Chrome/Chromium
75+
#### Chromium
7676

7777
- Open the Extension Management page by navigating to `chrome://extensions`.
7878
- Make sure that you have enabled developer mode.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "random-youtube-video",
3-
"version": "2.2.4",
3+
"version": "2.3.0",
44
"description": "Play a random video uploaded on the current YouTube channel.",
55
"scripts": {
66
"dev": "concurrently \"npm run dev:chromium\" \"npm run dev:firefox\"",

src/background.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ chrome.runtime.onStartup.addListener(async function () {
1212
console.log(`${((utilizedStorage / maxLocalStorage) * 100).toFixed(2)}% of local storage is used. (${utilizedStorage}/${maxLocalStorage} bytes)`);
1313

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

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

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

2323
// Sort the playlists by lastAccessedLocally value
2424
const sortedPlaylists = Object.entries(allPlaylists).sort((a, b) => {
@@ -324,7 +324,7 @@ async function openVideoInTabWithId(tabId, videoUrl) {
324324
// ---------- Local storage ----------
325325
async function getFromLocalStorage(key) {
326326
return await chrome.storage.local.get([key]).then((result) => {
327-
if (result[key]) {
327+
if (result[key] !== undefined) {
328328
return result[key];
329329
}
330330
return null;

src/content.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,9 @@ async function shuffleVideos() {
141141
var hasBeenShuffled = false;
142142
setDOMTextWithDelay(shuffleButtonTextElement, "\xa0Shuffling...", 1000, () => { return (shuffleButtonTextElement.innerText === "\xa0Shuffle" && !hasBeenShuffled); });
143143
setDOMTextWithDelay(shuffleButtonTextElement, "\xa0Still on it...", 5000, () => { return (shuffleButtonTextElement.innerText === "\xa0Shuffling..." && !hasBeenShuffled); });
144+
if (configSync.shuffleIgnoreShortsOption) {
145+
setDOMTextWithDelay(shuffleButtonTextElement, "\xa0Sorting shorts...", 8000, () => { return (shuffleButtonTextElement.innerText === "\xa0Still on it..." && !hasBeenShuffled); });
146+
}
144147

145148
await chooseRandomVideo(channelId, false, shuffleButtonTextElement);
146149
hasBeenShuffled = true;

src/shuffleVideo.js

Lines changed: 143 additions & 44 deletions
Large diffs are not rendered by default.

static/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "Random YouTube Video",
33
"description": "Play a random video uploaded on the current YouTube channel.",
4-
"version": "2.2.4",
4+
"version": "2.3.0",
55
"manifest_version": 3,
66
"content_scripts": [
77
{

test/playlistPermutations.js

Lines changed: 193 additions & 150 deletions
Large diffs are not rendered by default.

test/shuffleVideo.test.js

Lines changed: 81 additions & 34 deletions
Large diffs are not rendered by default.

test/testSetup.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ chrome.runtime.sendMessage.callsFake((request) => {
6464
// Only for the tests
6565
case "setKeyInDB":
6666
mockedDatabase[request.data.key] = request.data.val;
67-
return "Key was removed from database.";
67+
return "Key was set in the database (mocked for tests).";
6868

6969
case "getAPIKey":
7070
return getAPIKey(false, request.data.useAPIKeyAtIndex);

0 commit comments

Comments
 (0)