Skip to content

Commit 3306807

Browse files
committed
tweaks
1 parent 082ce41 commit 3306807

File tree

13 files changed

+383
-42
lines changed

13 files changed

+383
-42
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
icons/.DS_Store

content.js

Lines changed: 100 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,12 @@ class VideoSpeedController {
33
this.defaultSpeeds = [0.05, 0.1, 0.25, 0.5, 0.75, 1, 1.25, 1.5, 1.75, 2, 3, 4, 6, 10];
44
this.speeds = [...this.defaultSpeeds];
55
this.currentSpeedIndex = this.speeds.indexOf(1);
6+
this.previousSpeedIndex = null;
7+
this.longPressTimer = null;
8+
this.settings = null;
69
this.overlay = this.createOverlay();
7-
this.loadCustomSpeeds();
10+
this.controls = this.createControls();
11+
this.loadSettings();
812
this.setupEventListeners();
913
}
1014

@@ -16,11 +20,59 @@ class VideoSpeedController {
1620
return overlay;
1721
}
1822

19-
async loadCustomSpeeds() {
20-
const result = await chrome.storage.sync.get('customSpeeds');
21-
if (result.customSpeeds) {
22-
this.speeds = [...new Set([...this.defaultSpeeds, ...result.customSpeeds])].sort((a, b) => a - b);
23-
this.currentSpeedIndex = this.speeds.indexOf(1);
23+
createControls() {
24+
const controls = document.createElement('div');
25+
controls.className = 'video-speed-controls';
26+
controls.innerHTML = `
27+
<button class="speed-down" title="Decrease speed">
28+
<span class="icon">-</span>
29+
<span class="shortcut"></span>
30+
</button>
31+
<button class="speed-reset" title="Reset to normal speed">
32+
<span class="icon">1×</span>
33+
<span class="shortcut"></span>
34+
</button>
35+
<button class="speed-up" title="Increase speed">
36+
<span class="icon">+</span>
37+
<span class="shortcut"></span>
38+
</button>
39+
`;
40+
document.body.appendChild(controls);
41+
return controls;
42+
}
43+
44+
async loadSettings() {
45+
const defaultSettings = {
46+
customSpeeds: this.defaultSpeeds,
47+
shortcuts: {
48+
speedUp: 'd',
49+
speedDown: 's',
50+
reset: 'r'
51+
},
52+
enableNumberShortcuts: true,
53+
showSpeedButtons: true,
54+
showShortcutHints: true
55+
};
56+
57+
const result = await chrome.storage.sync.get(defaultSettings);
58+
this.settings = result;
59+
this.speeds = [...new Set([...this.defaultSpeeds, ...result.customSpeeds])].sort((a, b) => a - b);
60+
this.currentSpeedIndex = this.speeds.indexOf(1);
61+
this.updateControlsVisibility();
62+
this.updateShortcutHints();
63+
}
64+
65+
updateControlsVisibility() {
66+
this.controls.style.display = this.settings.showSpeedButtons ? 'flex' : 'none';
67+
}
68+
69+
updateShortcutHints() {
70+
if (this.settings.showShortcutHints) {
71+
this.controls.querySelector('.speed-down .shortcut').textContent = `[${this.settings.shortcuts.speedDown}]`;
72+
this.controls.querySelector('.speed-reset .shortcut').textContent = `[${this.settings.shortcuts.reset}]`;
73+
this.controls.querySelector('.speed-up .shortcut').textContent = `[${this.settings.shortcuts.speedUp}]`;
74+
} else {
75+
this.controls.querySelectorAll('.shortcut').forEach(el => el.textContent = '');
2476
}
2577
}
2678

@@ -31,21 +83,56 @@ class VideoSpeedController {
3183
const video = document.querySelector('video');
3284
if (!video) return;
3385

34-
if (e.key === 's') {
35-
this.changeSpeed(video, -1);
36-
} else if (e.key === 'd') {
86+
const key = e.key.toLowerCase();
87+
88+
if (key === this.settings.shortcuts.speedUp) {
3789
this.changeSpeed(video, 1);
90+
} else if (key === this.settings.shortcuts.speedDown) {
91+
this.changeSpeed(video, -1);
92+
} else if (key === this.settings.shortcuts.reset) {
93+
this.resetSpeed(video);
94+
} else if (this.settings.enableNumberShortcuts && /^[1-9]$/.test(key)) {
95+
this.jumpToSpeed(video, parseInt(key) - 1);
3896
}
3997
});
4098

41-
// Listen for custom speed updates
99+
// Button click handlers
100+
this.controls.querySelector('.speed-down').addEventListener('click', () => {
101+
const video = document.querySelector('video');
102+
if (video) this.changeSpeed(video, -1);
103+
});
104+
105+
this.controls.querySelector('.speed-up').addEventListener('click', () => {
106+
const video = document.querySelector('video');
107+
if (video) this.changeSpeed(video, 1);
108+
});
109+
110+
this.controls.querySelector('.speed-reset').addEventListener('click', () => {
111+
const video = document.querySelector('video');
112+
if (video) this.resetSpeed(video);
113+
});
114+
115+
// Listen for settings updates
42116
chrome.storage.onChanged.addListener((changes) => {
43-
if (changes.customSpeeds) {
44-
this.loadCustomSpeeds();
45-
}
117+
this.loadSettings();
46118
});
47119
}
48120

121+
resetSpeed(video) {
122+
this.currentSpeedIndex = this.speeds.indexOf(1);
123+
video.playbackRate = 1;
124+
this.showSpeedIndicator(1);
125+
}
126+
127+
jumpToSpeed(video, index) {
128+
if (index >= 0 && index < this.speeds.length) {
129+
this.currentSpeedIndex = index;
130+
const newSpeed = this.speeds[this.currentSpeedIndex];
131+
video.playbackRate = newSpeed;
132+
this.showSpeedIndicator(newSpeed);
133+
}
134+
}
135+
49136
changeSpeed(video, direction) {
50137
this.currentSpeedIndex = Math.max(0, Math.min(this.speeds.length - 1, this.currentSpeedIndex + direction));
51138
const newSpeed = this.speeds[this.currentSpeedIndex];

docs/user-stories.md

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# Video Speed Controller - User Stories
2+
3+
## Done
4+
5+
### Core Speed Control
6+
- As a user, I want to press 'd' to increase video playback speed, so I can watch videos faster
7+
- As a user, I want to press 's' to decrease video playback speed, so I can watch videos slower
8+
- As a user, I want to long-press 'd' to jump to maximum speed that the browser supports, so I can quickly skip through unimportant sections
9+
- As a user, I want to press 's' after using max speed to return to my previous speed, so I can resume watching at my preferred pace
10+
- As a user, I want visual feedback showing my current playback speed, so I know how fast the video is playing
11+
12+
### Speed Customization
13+
- As a user, I want to access a settings page to customize my available playback speeds
14+
- As a user, I want to add my own custom speeds to the list of available speeds
15+
- As a user, I want my custom speeds to persist between browser sessions
16+
- As a user, I want to see my custom speeds displayed in a clear list format
17+
- As a user, I want validation on my custom speeds to ensure they're between 0.05x and 16x
18+
19+
### User Interface
20+
- As a user, I want an unobtrusive overlay that shows my current speed briefly when I change it
21+
- As a user, I want the speed controls to be disabled when I'm typing in input fields or text areas
22+
- As a user, I want to see the version and build number in the options page
23+
- As a user, I want the interface to use system fonts and have a clean, modern appearance
24+
25+
### Default Behavior
26+
- As a user, I want a sensible set of default speeds (0.05, 0.1×, 0.25×, 0.5×, 0.75×, 1×, 1.25×, 1.5×, 2×, 5×, 10×, 16×) when I haven't set custom speeds
27+
- As a user, I want the video to start at normal (1x) speed by default
28+
- As a user, I want the speed overlay to automatically fade out after showing the current speed
29+
30+
### Technical Requirements
31+
- The extension should work on all websites with HTML5 video players
32+
- The extension should maintain state using Chrome's storage sync API
33+
- The extension should follow semantic versioning (major.minor.build)
34+
- The extension should be lightweight and not impact page performance
35+
36+
## Later
37+
38+
### Keyboard Shortcuts
39+
- As a user, I want to customize my keyboard shortcuts, so I can use keys that feel natural to me
40+
- As a user, I want a keyboard shortcut to reset to normal (1x) speed, so I can quickly return to default
41+
- As a user, I want to use number keys 1-9 to jump directly to specific speeds, so I can change speed more efficiently
42+
43+
### Advanced Features
44+
- As a user, I want to save different speed presets for different websites, so I can have site-specific defaults
45+
- As a user, I want to remember my last used speed per website, so I don't have to reset it each visit
46+
- As a user, I want to see a small speed indicator permanently in the corner (toggleable), so I always know my current speed
47+
- As a user, I want to control video speed with mouse wheel + modifier key, so I can adjust speed without keyboard
48+
49+
### User Experience
50+
- As a user, I want to import/export my speed settings, so I can backup or share my configuration
51+
- As a user, I want to see a tutorial on first use, so I can learn the controls quickly
52+
- As a user, I want to see keyboard shortcut hints in the options page, so I can remember all available controls

icons/bug.svg

Lines changed: 14 additions & 0 deletions
Loading

icons/icon-128.png

13.8 KB
Loading

icons/icon-16.png

1.32 KB
Loading

icons/icon-2048.png

330 KB
Loading

icons/icon-48.png

3.94 KB
Loading

icons/icon.svg

Lines changed: 23 additions & 0 deletions
Loading

manifest.json

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,23 @@
11
{
2-
"manifest_version": 3,
2+
"manifest_version": 2,
33
"name": "Video Speed Controller",
44
"version": "1.0",
5-
"description": "Control video playback speed with keyboard shortcuts",
6-
"permissions": ["storage"],
5+
"description": "Control video playback speed with customizable keyboard shortcuts",
6+
"permissions": [
7+
"storage",
8+
"activeTab"
9+
],
10+
"options_page": "options.html",
711
"content_scripts": [
812
{
913
"matches": ["<all_urls>"],
1014
"css": ["styles.css"],
1115
"js": ["content.js"]
1216
}
1317
],
14-
"options_page": "options.html"
18+
"icons": {
19+
"16": "icons/icon-16.png",
20+
"48": "icons/icon-48.png",
21+
"128": "icons/icon-128.png"
22+
}
1523
}

0 commit comments

Comments
 (0)