diff --git a/README.md b/README.md index 3fa3550..694951a 100644 --- a/README.md +++ b/README.md @@ -7,9 +7,11 @@ Website: https://fullorama.com [![Install from the Chrome Web Store](https://img.shields.io/badge/Get_it_on-Chrome_Web_Store-4285F4?style=for-the-badge&logo=googlechrome&logoColor=white)](https://chromewebstore.google.com/detail/fullorama-for-youtube/pacjdmdcmmnbpnjfhmjfgenbpedbakjg) [![Install from Firefox Add-ons](https://img.shields.io/badge/Get_it_on-Firefox_Add--ons-FF7139?style=for-the-badge&logo=firefoxbrowser&logoColor=white)](https://addons.mozilla.org/firefox/addon/fullorama/) -Fullorama for YouTube™ adds one crop button directly to YouTube's player. Turn -it on once and videos stay zoomed to fill across videos, refreshes, navigation, -and fullscreen, until you turn it off. +Fullorama for YouTube™ adds one button directly to YouTube's player. Choose Crop +or Stretch in the toolbar popup, then click the player button to turn that mode +on or off. Crop zooms in evenly to fill the player and trims the edges; stretch +widens the picture to fill it and leaves nothing out. The choice stays across +videos, refreshes, navigation, and fullscreen, until you change it. Built for 21:9 and other ultrawide displays. @@ -30,18 +32,22 @@ https://github.com/user-attachments/assets/3c62393f-5d82-4c7b-8543-0c3c0938f052 ## Features -- YouTube player button for ultrawide crop / zoom-to-fill -- Global persistent on/off state across videos, refreshes, and navigation +- Choose Crop or Stretch in the toolbar popup +- An Original frame and two looping result previews show what each mode does +- YouTube player button turns the selected mode on or off +- Crop mode zooms evenly to fill the player and trims the edges +- Stretch mode fills the player without trimming, at the cost of distortion +- The selected mode and on/off state persist across videos, refreshes, and navigation - Works with YouTube's single-page navigation - Works in theater mode and fullscreen -- Read-only popup shows current crop status +- Popup shows the selected mode and whether it's on or off - Optional feedback form (popup link and uninstall survey) ## FAQ ### How do I watch YouTube full screen on an ultrawide monitor? -Install Fullorama for [Chrome](https://chromewebstore.google.com/detail/fullorama-for-youtube/pacjdmdcmmnbpnjfhmjfgenbpedbakjg) or [Firefox](https://addons.mozilla.org/firefox/addon/fullorama/) and play any YouTube video. Look at the bottom-right of the player: there's a new button with four little corner brackets, next to the settings gear. Click it and the video zooms in to fill the player. A small square appears in the middle of the icon to show it's on. Click it again to go back to normal. +Install Fullorama for [Chrome](https://chromewebstore.google.com/detail/fullorama-for-youtube/pacjdmdcmmnbpnjfhmjfgenbpedbakjg) or [Firefox](https://addons.mozilla.org/firefox/addon/fullorama/) and play any YouTube video. Click Fullorama's icon in your browser toolbar and choose Crop or Stretch from the two result cards under the Original frame. Crop zooms the video in to fill the player; stretch fills it without trimming anything, at the cost of distortion. Then use the new button with four little corner brackets at the bottom-right of the player, next to the settings gear, to turn that mode on or off. A small square (crop) or wide bar (stretch) appears in the middle of the icon while it's on. ### I can't find the button. Where is it? @@ -49,27 +55,27 @@ It's with YouTube's own buttons at the bottom-right of the video, between the se ### Will the video look stretched? -No. Fullorama zooms in evenly from the center, so people and objects keep their normal shape. The trade-off is that a little of the edges gets trimmed. +Crop mode doesn't stretch anything. It zooms in evenly from the center, so people and objects keep their normal shape; the trade-off is that a little of the edges gets trimmed. Stretch mode does stretch the picture to fill the player and will make it look wider or taller than it is. Nothing gets trimmed in stretch mode. Use crop if you care more about shape, and stretch if you care more about seeing the whole frame. The player button turns the selected mode off at any time. ### Why do some videos still have black bars? -Some videos have the bars recorded into the picture itself, often old movies or re-uploads. Fullorama can't tell those apart from the real image, so they can stay even with the button on. It also can't show picture that was never in the video. +Some videos have the bars recorded into the picture itself, often old movies or re-uploads. Fullorama can't tell those apart from the real image, so they can stay even with a mode on. It also can't show picture that was never in the video. ### Does it work in theater mode and fullscreen? -Yes. When you switch to theater mode or fullscreen, the zoom adjusts automatically to fill the new size. +Yes. When you switch to theater mode or fullscreen, the scaling adjusts automatically to fill the new size. ### Do I have to click it for every video? -No. Turn it on once and it stays on as you watch more videos, refresh, or browse around YouTube. Turn it off the same way whenever you like. The setting applies to all of YouTube in that browser. +No. Pick a mode once and it stays selected as you watch more videos, refresh, or browse around YouTube. It also remembers whether it was on or off. Change either from the toolbar popup or the player button whenever you like. The setting applies to all of YouTube in that browser. ### Does it work on 21:9 and 32:9 ultrawide monitors? -Yes. Fullorama works out the zoom from the shape of your player and the video, so it fits 21:9, 32:9 and anything in between. On wider screens, a little more of the edges is trimmed. +Yes. Fullorama works out the scaling from the shape of your player and the video, so it fits 21:9, 32:9 and anything in between. In crop mode, wider screens trim a little more of the edges; stretch mode fills them without trimming. ### Can I fill the screen and still see the whole picture? -Only if the video is already the same shape as your screen. Otherwise a little of the edges is trimmed to fill it. You can turn the button off any time to see the whole picture. +Only if the video is already the same shape as your screen. Crop mode trims a little of the edges to fill it; stretch mode keeps everything but distorts the shape. You can turn the selected mode off any time to see the original picture. ### Does it work on Netflix, other sites, or my phone? @@ -77,15 +83,15 @@ No, only YouTube in a desktop browser (Chrome or Firefox). It doesn't work on Ne ### Will it slow YouTube down or make videos sharper? -It just zooms in on the video that's already playing, so it doesn't change the video's quality or load anything extra. Zooming in won't make it sharper, either. We haven't measured its effect on performance yet, but it does very little work. It only resizes the video you're watching. +It just scales the video that's already playing, so it doesn't change the video's quality or load anything extra. Scaling won't make it sharper, either. We haven't measured its effect on performance yet, but it does very little work. It only resizes the video you're watching. ### What's the toolbar icon for? -Clicking Fullorama's icon in your browser toolbar shows whether the zoom is on or off, and has a link to send us feedback. To turn it on or off, use the button in the video player. +Clicking Fullorama's icon in your browser toolbar opens the mode picker. It shows whether the selected mode is on or off, alongside an Original frame and the two results: Crop keeps the shape and cuts off the edges; Stretch shows everything and pulls the video to fit. Clicking a card selects that mode and turns it on. To turn the selected mode off, use the button in the video player. ### Does Fullorama collect my data? -No. It saves one thing in your browser: whether the zoom is on or off. It doesn't track what you watch, has no ads, and needs no account. +No. It saves two things in your browser: which mode you selected and whether it's on or off. It doesn't track what you watch, has no ads, and needs no account. Feedback is optional and goes through a separate form run by Tally. It opens if you choose "Share feedback" in the toolbar popup, or after you uninstall. The form link includes the extension's version and where you opened it from. On Firefox, those two details are only sent if you've allowed the optional data permission. See the [privacy policy](https://fullorama.com/privacy) for the full details. @@ -95,24 +101,45 @@ Yes, completely free and open source. The code is on GitHub under the [MIT licen ## How It Works -The extension stores one boolean, `cropEnabled`, in extension local storage (`chrome.storage.local` on Chrome and `browser.storage.local` on Firefox). - -A read-only toolbar popup displays whether crop is currently on or off by -reading the stored value once when opened. The popup cannot toggle crop — only -the player button can. A tiny background script registers an uninstall survey -URL so the browser can open the optional feedback form if you remove the -extension. - -When crop is enabled, the content script adds a class to YouTube's -`#movie_player` element and sets a CSS scale variable based on the current -player aspect ratio and video aspect ratio. The CSS clips the player and scales -the rendered video from the center. +The extension stores `fillMode` (`crop` or `stretch`) and `fillEnabled` +(`true` or `false`) in extension local storage (`chrome.storage.local` on Chrome +and `browser.storage.local` on Firefox). Two values are needed because the +player can be off while still remembering which mode its button will turn back +on. Upgrading from a version before 1.3.0 moves the older `cropEnabled` boolean +to `fillEnabled` and removes the old key. That migration is temporary and will +be removed in the release after 1.3.0. + +The toolbar popup is interactive. It reads the state once and shows the status in +the header (`Crop is off`, `Crop is on`, `Stretch is off`, `Stretch is on`) with +a green dot when on. A static `Original` frame above a branching connector shows +the square video inside a 21:9 player with side bars. The two result cards loop +between the original frame and the mode applied. They are CSS-only: each card +holds the square still in a 21:9 box, scaled uniformly by `21 ÷ 9 = 2.3333` for +crop or on the X axis only for stretch, on the same 5-second loop. The selected +card gets a white outline and a filled radio, and the selected Crop card shows +the cut-off parts as a faded overflow above and below the frame. Under +`prefers-reduced-motion: reduce` the loop stops and each card holds its applied +state. Clicking a card calls `selectMode`, which selects that mode and turns fill +on. The player button calls `toggleEnabled`, so it only turns the selected mode +off and on. A tiny background script registers an uninstall survey URL so the +browser can open the optional feedback form if you remove the extension. + +When enabled, `applyFill` reads the state itself and adds `flrm-fill-on` to +YouTube's `#movie_player` element, setting `--flrm-scale-x` and `--flrm-scale-y` +from the current player and video aspect ratios. Crop sets both variables to the +same scale and clips the overflow, so the picture fills the player without +changing shape. Stretch sets the shorter axis to 1 and the longer axis to the +fill scale, so the picture fills the player but changes shape. `content.css` +applies one transform from the center. If the player size is not known yet, +`applyFill` clears the previous fill so changing modes early cannot leave stale +geometry behind. YouTube rebuilds parts of its player during normal navigation, so the extension uses YouTube navigation events, a controls-scoped `MutationObserver`, a player-scoped `ResizeObserver`, video metadata events, window resize, fullscreen, -and short retry bursts to keep the button and crop state in sync. Player-size -changes automatically recalculate the crop when entering or leaving theater mode. +and short retry bursts to keep the button and mode state in sync. Player-size +changes automatically recalculate the scaling when entering or leaving theater +mode. ## Install Locally diff --git a/package.json b/package.json index 94d8f59..bea4f77 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "fullorama", - "version": "1.2.1", + "version": "1.3.0", "description": "Fill your ultrawide screen with YouTube videos without distracting black bars.", "type": "module", "license": "MIT", diff --git a/scripts/build.ts b/scripts/build.ts index abcc2db..d1bebde 100644 --- a/scripts/build.ts +++ b/scripts/build.ts @@ -79,6 +79,7 @@ function copyStatic(target: BuildTarget): void { copyFileSync('src/content.css', `${target.distDir}/content.css`); copyFileSync('src/popup/popup.html', `${target.distDir}/popup.html`); copyFileSync('src/popup/popup.css', `${target.distDir}/popup.css`); + copyFileSync('src/popup/preview.jpg', `${target.distDir}/preview.jpg`); rmSync(`${target.distDir}/icons`, { recursive: true, force: true }); cpSync('icons', `${target.distDir}/icons`, { recursive: true }); } diff --git a/src/content.css b/src/content.css index 77eef8d..4e5e59c 100644 --- a/src/content.css +++ b/src/content.css @@ -11,15 +11,24 @@ display: block; } -.flrm-btn[aria-pressed="false"] .flrm-on { +.flrm-btn .flrm-crop, +.flrm-btn .flrm-stretch { display: none; } -#movie_player.flrm-crop-on { +.flrm-btn[aria-pressed="true"][data-flrm-mode="crop"] .flrm-crop { + display: block; +} + +.flrm-btn[aria-pressed="true"][data-flrm-mode="stretch"] .flrm-stretch { + display: block; +} + +#movie_player.flrm-fill-on { overflow: hidden !important; } -#movie_player.flrm-crop-on video.html5-main-video { - transform: scale(var(--flrm-scale, 1)) !important; +#movie_player.flrm-fill-on video.html5-main-video { + transform: scale(var(--flrm-scale-x, 1), var(--flrm-scale-y, 1)) !important; transform-origin: center center !important; } diff --git a/src/index.ts b/src/index.ts index 431b395..7272dd2 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,18 +1,19 @@ /** * Fullorama for YouTube™ * - * Adds a crop button to the YouTube player that zooms the video to fill - * the player, removing letterboxing. The toggle persists in + * Adds a button to the YouTube player that turns the selected fill mode on or + * off. The toolbar popup chooses crop (uniform zoom that trims edges) or + * stretch (scales one axis and distorts). The mode and on/off state persist in * chrome.storage.local across videos, refreshes, and navigation. */ import { loadState, onStorageChange } from './storage/state'; import { updateButton } from './player/button'; -import { applyCrop } from './player/crop'; +import { applyFill } from './player/fill'; import { getPlayer } from './player/dom'; import { - applyCropAndSync, - applyCropNow, + applyFillAndSync, + applyFillNow, onVideoMetadata, resetObserver, retryBurst, @@ -24,12 +25,12 @@ async function init(): Promise { // Sync from other tabs onStorageChange(() => { updateButton(); - applyCrop(getPlayer()); + applyFill(getPlayer()); }); - // Apply crop immediately on resize and fullscreen - window.addEventListener('resize', applyCropNow, { passive: true }); - document.addEventListener('fullscreenchange', applyCropAndSync); + // Apply the selected mode immediately on resize and fullscreen + window.addEventListener('resize', applyFillNow, { passive: true }); + document.addEventListener('fullscreenchange', applyFillAndSync); document.addEventListener('yt-navigate-finish', retryBurst); document.addEventListener('yt-navigate-start', resetObserver); document.addEventListener('loadedmetadata', onVideoMetadata, true); diff --git a/src/player/button.ts b/src/player/button.ts index 87d3982..d331276 100644 --- a/src/player/button.ts +++ b/src/player/button.ts @@ -1,9 +1,9 @@ /** - * Button — injects and manages the crop toggle button in YouTube's player. + * Button — injects and manages the mode button in YouTube's player. */ -import { isEnabled, toggleCrop } from '../storage/state'; -import { applyCrop } from './crop'; +import { getMode, isEnabled, toggleEnabled } from '../storage/state'; +import { applyFill } from './fill'; import { getPlayer } from './dom'; const BUTTON_ATTR = 'data-flrm-btn'; @@ -49,7 +49,7 @@ function createIcon(): SVGSVGElement { svg.append( group, svgElement('rect', { - class: 'flrm-on', + class: 'flrm-crop', x: '13', y: '13', width: '10', @@ -58,17 +58,47 @@ function createIcon(): SVGSVGElement { fill: 'currentColor', stroke: 'none', }), + svgElement('rect', { + class: 'flrm-stretch', + x: '10', + y: '15', + width: '16', + height: '6', + rx: '1', + fill: 'currentColor', + stroke: 'none', + }), ); return svg; } +function syncButtonState(button: HTMLElement): void { + const mode = getMode(); + const enabled = isEnabled(); + const label = `Fullorama: ${mode} ${enabled ? 'on' : 'off'}`; + const pressed = String(enabled); + + if (button.dataset.flrmMode !== mode) { + button.dataset.flrmMode = mode; + } + if (button.title !== label) { + button.title = label; + } + if (button.getAttribute('aria-label') !== label) { + button.setAttribute('aria-label', label); + } + if (button.getAttribute('aria-pressed') !== pressed) { + button.setAttribute('aria-pressed', pressed); + } +} + function onButtonClick(event: Event): void { event.preventDefault(); event.stopPropagation(); - toggleCrop(); + toggleEnabled(); updateButton(); - applyCrop(getPlayer()); + applyFill(getPlayer()); } export function injectButton( @@ -82,12 +112,9 @@ export function injectButton( const button = document.createElement('button'); button.setAttribute(BUTTON_ATTR, ''); button.className = 'ytp-button flrm-btn'; - button.title = 'Fullorama crop'; - button.setAttribute('aria-label', 'Fullorama crop'); - button.setAttribute('aria-pressed', String(isEnabled())); button.append(createIcon()); - button.addEventListener('click', onButtonClick); + syncButtonState(button); controls.insertBefore( button, @@ -99,11 +126,7 @@ export function updateButton(): void { const btn = document.querySelector( '#movie_player [' + BUTTON_ATTR + ']', ); - if (!btn) { - return; - } - const pressed = String(isEnabled()); - if (btn.getAttribute('aria-pressed') !== pressed) { - btn.setAttribute('aria-pressed', pressed); + if (btn) { + syncButtonState(btn); } } diff --git a/src/player/crop.ts b/src/player/crop.ts deleted file mode 100644 index 84869c4..0000000 --- a/src/player/crop.ts +++ /dev/null @@ -1,57 +0,0 @@ -/** - * Crop — applies zoom-to-fill by adding a class + CSS variable to #movie_player. - * The actual transform is defined in content.css. - */ - -import { isEnabled } from '../storage/state'; - -const CROP_CLASS = 'flrm-crop-on'; -const SCALE_VAR = '--flrm-scale'; - -export function applyCrop(player: HTMLElement | null): void { - if (!player) { - return; - } - - if (!isEnabled()) { - if (player.classList.contains(CROP_CLASS)) { - player.classList.remove(CROP_CLASS); - } - if (player.style.getPropertyValue(SCALE_VAR)) { - player.style.removeProperty(SCALE_VAR); - } - return; - } - - const video = player.querySelector('video.html5-main-video'); - if (!video) { - return; - } - - const vw = video.videoWidth; - const vh = video.videoHeight; - if (!vw || !vh) { - return; - } - - const rect = player.getBoundingClientRect(); - if (!rect.width || !rect.height) { - return; - } - - // Scale to fill: ratio of player and video aspect ratios - const videoAspect = vw / vh; - const playerAspect = rect.width / rect.height; - const scale = - Math.round( - Math.max(playerAspect / videoAspect, videoAspect / playerAspect) * 10000, - ) / 10000; - - const nextScale = String(scale); - if (player.style.getPropertyValue(SCALE_VAR) !== nextScale) { - player.style.setProperty(SCALE_VAR, nextScale); - } - if (!player.classList.contains(CROP_CLASS)) { - player.classList.add(CROP_CLASS); - } -} \ No newline at end of file diff --git a/src/player/fill.ts b/src/player/fill.ts new file mode 100644 index 0000000..d335994 --- /dev/null +++ b/src/player/fill.ts @@ -0,0 +1,106 @@ +/** + * Fill — applies the selected fill mode to #movie_player when enabled. + * Crop zooms the video uniformly to fill; stretch scales each axis to fill. + * The actual transform is defined in content.css. + */ + +import { getMode, isEnabled } from '../storage/state'; + +const PLAYER_CLASS = 'flrm-fill-on'; +const SCALE_X_VAR = '--flrm-scale-x'; +const SCALE_Y_VAR = '--flrm-scale-y'; + +type Aspects = { + video: number; + player: number; +}; + +function readAspects(player: HTMLElement): Aspects | null { + const video = player.querySelector('video.html5-main-video'); + if (!video) { + return null; + } + + const vw = video.videoWidth; + const vh = video.videoHeight; + if (!vw || !vh) { + return null; + } + + const rect = player.getBoundingClientRect(); + if (!rect.width || !rect.height) { + return null; + } + + return { + video: vw / vh, + player: rect.width / rect.height, + }; +} + +function removeClass(player: HTMLElement, name: string): void { + if (player.classList.contains(name)) { + player.classList.remove(name); + } +} + +function removeVar(player: HTMLElement, name: string): void { + if (player.style.getPropertyValue(name)) { + player.style.removeProperty(name); + } +} + +function setVar(player: HTMLElement, name: string, value: string): void { + if (player.style.getPropertyValue(name) !== value) { + player.style.setProperty(name, value); + } +} + +function round(value: number): number { + return Math.round(value * 10000) / 10000; +} + +export function applyFill(player: HTMLElement | null): void { + if (!player) { + return; + } + + if (!isEnabled()) { + removeClass(player, PLAYER_CLASS); + removeVar(player, SCALE_X_VAR); + removeVar(player, SCALE_Y_VAR); + return; + } + + const aspects = readAspects(player); + if (!aspects) { + // The size is not known yet. Clear any previous fill so a mode change + // cannot leave stale geometry on the player. + removeClass(player, PLAYER_CLASS); + removeVar(player, SCALE_X_VAR); + removeVar(player, SCALE_Y_VAR); + return; + } + + let scaleX: number; + let scaleY: number; + + if (getMode() === 'stretch') { + const wider = aspects.player >= aspects.video; + scaleX = wider ? aspects.player / aspects.video : 1; + scaleY = wider ? 1 : aspects.video / aspects.player; + } else { + const scale = Math.max( + aspects.player / aspects.video, + aspects.video / aspects.player, + ); + scaleX = scale; + scaleY = scale; + } + + setVar(player, SCALE_X_VAR, String(round(scaleX))); + setVar(player, SCALE_Y_VAR, String(round(scaleY))); + if (!player.classList.contains(PLAYER_CLASS)) { + player.classList.add(PLAYER_CLASS); + } +} diff --git a/src/popup/popup.css b/src/popup/popup.css index 33e16b4..074c445 100644 --- a/src/popup/popup.css +++ b/src/popup/popup.css @@ -1,11 +1,10 @@ :root { color-scheme: dark; - --background: #181818; - --surface: #1f1f1f; - --border: #333; + --background: #1b1b1b; + --border: #3a3a3a; + --line: #4a4a4a; --text: #f2f2f2; - --muted: #ababab; - --accent: #ababab; + --muted: #a3a3a3; --on: #2ba640; --off: #717171; } @@ -21,7 +20,7 @@ body { } body { - width: 300px; + width: 360px; background: var(--background); color: var(--text); font-family: Roboto, Arial, sans-serif; @@ -33,20 +32,20 @@ body { display: flex; flex-direction: column; gap: 14px; - padding: 16px; + padding: 20px; } .header { display: flex; align-items: center; - gap: 10px; + justify-content: space-between; + gap: 12px; } .header img { display: block; width: auto; height: 24px; - mix-blend-mode: lighten; } .header h1 { @@ -60,18 +59,17 @@ body { .status { display: flex; align-items: center; - gap: 9px; - min-height: 42px; - padding: 10px 12px; - background: var(--surface); - border: 1px solid var(--border); - border-radius: 8px; + gap: 7px; + margin-left: auto; + color: var(--muted); + font-size: 13px; font-weight: 500; + white-space: nowrap; } .dot { - width: 8px; - height: 8px; + width: 6px; + height: 6px; flex: none; background: var(--off); border-radius: 50%; @@ -85,41 +83,268 @@ body { color: var(--muted); } -.links { +.original { + margin-top: 6px; +} + +.eyebrow { + margin: 0 0 9px; + color: var(--muted); + font-size: 13px; + text-align: center; +} + +.original-frame { display: flex; + align-items: center; + justify-content: center; + width: 46%; + aspect-ratio: 21 / 9; + margin: 0 auto; + overflow: hidden; + background: #000; + border: 1px solid var(--border); + border-radius: 10px; } -a { - color: inherit; - text-decoration: none; +.original-frame img { + display: block; + width: auto; + height: 100%; + max-width: none; } -.links a { - width: 100%; - padding: 9px 12px; +.branch { + position: relative; + height: 20px; + margin: -6px 0 -4px; +} + +.branch::before { + content: ""; + position: absolute; + top: 0; + left: 50%; + width: 1px; + height: 10px; + background: var(--line); +} + +.branch::after { + content: ""; + position: absolute; + top: 10px; + left: 24%; + right: 24%; + height: 10px; + border: 1px solid var(--line); + border-bottom: 0; + border-radius: 8px 8px 0 0; +} + +.modes { + display: grid; + grid-template-columns: repeat(2, minmax(0, 1fr)); + gap: 14px; +} + +.option { + display: flex; + flex-direction: column; + min-width: 0; + padding: 0; color: var(--text); - background: var(--surface); + background: transparent; + border: 0; + font: inherit; + text-align: left; + cursor: pointer; +} + +.option:focus-visible { + outline: 2px solid var(--on); + outline-offset: 4px; + border-radius: 12px; +} + +.preview-wrap { + --preview-fill: 2.3333; + position: relative; + display: block; +} + +.preview { + position: relative; + z-index: 1; + display: flex; + align-items: center; + justify-content: center; + width: 100%; + aspect-ratio: 21 / 9; + overflow: hidden; + background: #000; + background-clip: padding-box; border: 1px solid var(--border); - border-radius: 8px; - text-align: center; - font-weight: 500; + border-radius: 10px; } -.links a:hover, -.links a:focus-visible { - border-color: var(--accent); - outline: none; +.preview-frame { + display: block; + width: auto; + height: 100%; + max-width: none; + transform-origin: center center; } -.footer { - display: grid; - grid-template-columns: auto auto 1fr auto; +.preview-bleed { + --bleed: 14px; + position: absolute; + top: calc(-1 * var(--bleed)); + right: 0; + bottom: calc(-1 * var(--bleed)); + left: 0; + display: flex; align-items: center; - gap: 6px; - padding-top: 12px; + justify-content: center; + overflow: hidden; + opacity: 0; + pointer-events: none; + -webkit-mask-image: linear-gradient( + to bottom, + transparent, + #000 20%, + #000 80%, + transparent + ); + mask-image: linear-gradient( + to bottom, + transparent, + #000 20%, + #000 80%, + transparent + ); +} + +.preview-bleed::before { + content: ""; + flex: none; + width: auto; + height: calc(100% - 2 * var(--bleed) - 2px); + aspect-ratio: 1; + background: url("preview.jpg") center / cover no-repeat; + transform-origin: center center; +} + +.option[data-mode="crop"] .preview-bleed::before { + animation: preview-crop 5s ease-in-out infinite; +} + +.option[data-mode="crop"].is-selected .preview-bleed { + opacity: 0.6; +} + +.option[data-mode="crop"] .preview-frame { + animation: preview-crop 5s ease-in-out infinite; +} + +.option[data-mode="stretch"] .preview-frame { + animation: preview-stretch 5s ease-in-out infinite; +} + +@keyframes preview-crop { + 0%, + 20% { + transform: scale(1); + } + + 30%, + 70% { + transform: scale(var(--preview-fill)); + } + + 80%, + 100% { + transform: scale(1); + } +} + +@keyframes preview-stretch { + 0%, + 20% { + transform: scaleX(1); + } + + 30%, + 70% { + transform: scaleX(var(--preview-fill)); + } + + 80%, + 100% { + transform: scaleX(1); + } +} + +.option.is-selected .preview { + border-color: transparent; + outline: 2px solid #fff; + outline-offset: 2px; +} + +.option-body { + display: flex; + align-items: flex-start; + gap: 9px; + margin-top: 8px; +} + +.radio { + width: 16px; + height: 16px; + flex: none; + margin-top: 1px; + border: 2px solid #6f6f6f; + border-radius: 50%; +} + +.option.is-selected .radio { + border-color: #fff; + background: radial-gradient(circle, #fff 0 4px, transparent 4.5px); +} + +.option-copy { + display: flex; + flex-direction: column; + gap: 2px; + min-width: 0; +} + +.option-label { + font-size: 16px; + font-weight: 600; + line-height: 1.2; +} + +.option-desc { color: var(--muted); + font-size: 12.5px; + line-height: 1.5; +} + +.footer { + display: flex; + align-items: center; + justify-content: space-between; + gap: 10px; + padding-top: 13px; border-top: 1px solid var(--border); - font-size: 11px; + color: var(--muted); + font-size: 12px; +} + +a { + color: inherit; + text-decoration: none; } .footer a:hover, @@ -129,6 +354,19 @@ a { text-decoration: underline; } -.version { - justify-self: end; +@media (prefers-reduced-motion: reduce) { + .option[data-mode="crop"] .preview-frame, + .option[data-mode="crop"] .preview-bleed::before, + .option[data-mode="stretch"] .preview-frame { + animation: none; + } + + .option[data-mode="crop"] .preview-frame, + .option[data-mode="crop"] .preview-bleed::before { + transform: scale(var(--preview-fill)); + } + + .option[data-mode="stretch"] .preview-frame { + transform: scaleX(var(--preview-fill)); + } } diff --git a/src/popup/popup.html b/src/popup/popup.html index d9735f0..1dffb67 100644 --- a/src/popup/popup.html +++ b/src/popup/popup.html @@ -8,25 +8,60 @@
-
+

Fullorama

-
+
+ + Loading… +
+ -
- - Loading… -
+
+

Original

+ +
- diff --git a/src/popup/popup.ts b/src/popup/popup.ts index 72cfac9..a5de44c 100644 --- a/src/popup/popup.ts +++ b/src/popup/popup.ts @@ -1,14 +1,9 @@ /** - * Popup entrypoint — read-only crop status display. - * - * Reads `cropEnabled` from storage.local once when opened and reflects it. - * It never writes state: the only way to toggle crop is the YouTube player - * button. The popup closes when focus returns to YouTube, so a live - * storage listener provides no practical benefit. + * Popup entrypoint — selects the fill mode and turns it on. */ import { canSendFeedbackMetadata, extensionApi } from '../platform/extension-api'; -import { STORAGE_KEY } from '../storage/state'; +import { FillMode, getMode, isEnabled, loadState, selectMode } from '../storage/state'; import { buildFeedbackUrl, FEEDBACK_URL } from '../feedback'; declare const TARGET_BROWSER: 'chrome' | 'firefox'; @@ -17,6 +12,11 @@ const feedbackSource = TARGET_BROWSER === 'firefox' ? 'firefox-popup' : 'chrome-popup'; +const LABELS: Record = { + crop: 'Crop', + stretch: 'Stretch', +}; + function setStatus(text: string, stateClass: string): void { const status = document.getElementById('status'); const statusText = document.getElementById('status-text'); @@ -28,6 +28,30 @@ function setStatus(text: string, stateClass: string): void { status.classList.add(stateClass); } +function render(): void { + const mode = getMode(); + const enabled = isEnabled(); + + setStatus( + `${LABELS[mode]} is ${enabled ? 'on' : 'off'}`, + enabled ? 'is-on' : 'is-off', + ); + + for (const card of document.querySelectorAll('.option')) { + const selected = card.dataset.mode === mode; + card.classList.toggle('is-selected', selected); + card.setAttribute('aria-pressed', String(selected)); + } +} + +function onModeClick(event: Event): void { + const mode = (event.currentTarget as HTMLElement).dataset.mode; + if (mode === 'crop' || mode === 'stretch') { + selectMode(mode); + render(); + } +} + async function init(): Promise { const version = extensionApi.runtime.getManifest().version; @@ -43,13 +67,13 @@ async function init(): Promise { : FEEDBACK_URL; } + for (const card of document.querySelectorAll('.option')) { + card.addEventListener('click', onModeClick); + } + try { - const result = await extensionApi.storage.local.get(STORAGE_KEY); - if (result[STORAGE_KEY] === true) { - setStatus('Crop is on', 'is-on'); - } else { - setStatus('Crop is off', 'is-off'); - } + await loadState(); + render(); } catch { setStatus('Status unavailable', 'is-unavailable'); } diff --git a/src/popup/preview.jpg b/src/popup/preview.jpg new file mode 100644 index 0000000..abac93a Binary files /dev/null and b/src/popup/preview.jpg differ diff --git a/src/storage/state.ts b/src/storage/state.ts index 6acffa8..fbcf8aa 100644 --- a/src/storage/state.ts +++ b/src/storage/state.ts @@ -1,29 +1,82 @@ /** - * State — crop on/off persisted in extension storage. + * State — fill mode and on/off persisted in extension storage. */ import { extensionApi } from '../platform/extension-api'; -export const STORAGE_KEY = 'cropEnabled'; +export type FillMode = 'crop' | 'stretch'; -let cropEnabled = false; +const ENABLED_KEY = 'fillEnabled'; +const MODE_KEY = 'fillMode'; +const LEGACY_CROP_ENABLED_KEY = 'cropEnabled'; + +let enabled = false; +let mode: FillMode = 'crop'; + +function parseMode(value: unknown): FillMode | null { + return value === 'crop' || value === 'stretch' ? value : null; +} export function isEnabled(): boolean { - return cropEnabled; + return enabled; +} + +export function getMode(): FillMode { + return mode; +} + +function save(): void { + extensionApi.storage.local.set({ + [ENABLED_KEY]: enabled, + [MODE_KEY]: mode, + }); } export async function loadState(): Promise { - const result = await extensionApi.storage.local.get(STORAGE_KEY); - cropEnabled = result[STORAGE_KEY] === true; + const result = await extensionApi.storage.local.get([ + ENABLED_KEY, + MODE_KEY, + LEGACY_CROP_ENABLED_KEY, + ]); + + const storedEnabled = result[ENABLED_KEY]; + const storedMode = parseMode(result[MODE_KEY]); + + if (typeof storedEnabled === 'boolean' && storedMode) { + enabled = storedEnabled; + mode = storedMode; + return; + } + + enabled = typeof storedEnabled === 'boolean' ? storedEnabled : false; + mode = storedMode ?? 'crop'; + + // Temporary: moves the pre-1.3.0 `cropEnabled` key. Remove in the release after 1.3.0. + const legacyEnabled = result[LEGACY_CROP_ENABLED_KEY]; + const migrating = typeof storedEnabled !== 'boolean' && typeof legacyEnabled === 'boolean'; + if (migrating) { + enabled = legacyEnabled; + } + + await extensionApi.storage.local.set({ + [ENABLED_KEY]: enabled, + [MODE_KEY]: mode, + }); + + if (migrating) { + await extensionApi.storage.local.remove(LEGACY_CROP_ENABLED_KEY); + } } -function saveState(): void { - extensionApi.storage.local.set({ [STORAGE_KEY]: cropEnabled }); +export function selectMode(next: FillMode): void { + mode = next; + enabled = true; + save(); } -export function toggleCrop(): void { - cropEnabled = !cropEnabled; - saveState(); +export function toggleEnabled(): void { + enabled = !enabled; + save(); } export function onStorageChange( @@ -33,14 +86,29 @@ export function onStorageChange( if (area !== 'local') { return; } - const change = changes[STORAGE_KEY]; - if (change) { - const nextEnabled = change.newValue === true; - if (cropEnabled === nextEnabled) { - return; + + let changed = false; + + const enabledChange = changes[ENABLED_KEY]; + if (enabledChange) { + const next = enabledChange.newValue === true; + if (next !== enabled) { + enabled = next; + changed = true; } - cropEnabled = nextEnabled; + } + + const modeChange = changes[MODE_KEY]; + if (modeChange) { + const next = parseMode(modeChange.newValue); + if (next && next !== mode) { + mode = next; + changed = true; + } + } + + if (changed) { cb(); } }); -} \ No newline at end of file +} diff --git a/src/sync/sync.ts b/src/sync/sync.ts index 6c10fa5..42c330f 100644 --- a/src/sync/sync.ts +++ b/src/sync/sync.ts @@ -1,9 +1,9 @@ /** - * Sync — debounced re-injection and re-apply of button + crop. + * Sync — debounced re-injection and re-apply of button + fill. * Watches for YouTube DOM changes, navigation events, and player resizes. */ -import { applyCrop } from '../player/crop'; +import { applyFill } from '../player/fill'; import { injectButton } from '../player/button'; import { getPlayer, getControls } from '../player/dom'; @@ -47,7 +47,7 @@ function observePlayer(player: HTMLElement | null): void { return; } - playerObserver = new ResizeObserver(applyCropNow); + playerObserver = new ResizeObserver(applyFillNow); playerObserver.observe(player); } @@ -59,7 +59,7 @@ function sync(): void { if (player && controls) { injectButton(player, controls); } - applyCrop(player); + applyFill(player); } export function scheduleSync(): void { @@ -109,11 +109,11 @@ export function onVideoMetadata(event: Event): void { } } -export function applyCropNow(): void { - applyCrop(getPlayer()); +export function applyFillNow(): void { + applyFill(getPlayer()); } -export function applyCropAndSync(): void { - applyCrop(getPlayer()); +export function applyFillAndSync(): void { + applyFill(getPlayer()); scheduleSync(); -} \ No newline at end of file +} diff --git a/tests/build.test.ts b/tests/build.test.ts index ab1f7a1..cb119fc 100644 --- a/tests/build.test.ts +++ b/tests/build.test.ts @@ -98,6 +98,11 @@ describe('generated build output', () => { expect(popup).not.toContain('firefox-popup'); }); + it('packages the popup preview image', () => { + expect(existsSync(join('dist-chrome', 'preview.jpg'))).toBe(true); + expect(existsSync(join('dist-firefox', 'preview.jpg'))).toBe(true); + }); + it('Firefox popup.js contains firefox-popup source', () => { const popup = readFileSync(join('dist-firefox', 'popup.js'), 'utf8'); expect(popup).toContain('firefox-popup'); diff --git a/tests/fill.test.ts b/tests/fill.test.ts new file mode 100644 index 0000000..3c1df0d --- /dev/null +++ b/tests/fill.test.ts @@ -0,0 +1,142 @@ +import { beforeEach, describe, expect, it } from 'bun:test'; +import { resetStore } from './helpers/storage'; + +const state = await import('../src/storage/state'); +const { applyFill } = await import('../src/player/fill'); + +beforeEach(async () => { + resetStore(); + await state.loadState(); +}); + +function createPlayer( + playerWidth = 2560, + playerHeight = 1080, + videoWidth = 1920, + videoHeight = 1080, +) { + const classes = new Set(); + const styles = new Map(); + const video = { videoWidth, videoHeight }; + const size = { width: playerWidth, height: playerHeight }; + + const player = { + classList: { + add: (name: string) => { + classes.add(name); + }, + remove: (...names: string[]) => { + for (const name of names) { + classes.delete(name); + } + }, + contains: (name: string) => classes.has(name), + }, + style: { + getPropertyValue: (name: string) => styles.get(name) ?? '', + setProperty: (name: string, value: string) => { + styles.set(name, value); + }, + removeProperty: (name: string) => { + styles.delete(name); + }, + }, + querySelector: () => video, + getBoundingClientRect: () => size, + }; + + return { + player: player as unknown as HTMLElement, + classes, + styles, + setSize: (width: number, height: number) => { + size.width = width; + size.height = height; + }, + }; +} + +describe('applyFill', () => { + it('clears fill state when disabled', () => { + state.selectMode('stretch'); + const { player, classes, styles } = createPlayer(); + classes.add('flrm-fill-on'); + styles.set('--flrm-scale-x', '1.5'); + styles.set('--flrm-scale-y', '1'); + + state.toggleEnabled(); + applyFill(player); + + expect(classes.has('flrm-fill-on')).toBe(false); + expect(styles.has('--flrm-scale-x')).toBe(false); + expect(styles.has('--flrm-scale-y')).toBe(false); + }); + + it('applies a uniform scale in crop mode', () => { + state.selectMode('crop'); + const { player, classes, styles } = createPlayer(); + + applyFill(player); + + expect(classes.has('flrm-fill-on')).toBe(true); + expect(styles.get('--flrm-scale-x')).toBe('1.3333'); + expect(styles.get('--flrm-scale-y')).toBe('1.3333'); + }); + + it('stretches horizontally for a wide player', () => { + state.selectMode('stretch'); + const { player, classes, styles } = createPlayer(); + + applyFill(player); + + expect(classes.has('flrm-fill-on')).toBe(true); + expect(styles.get('--flrm-scale-x')).toBe('1.3333'); + expect(styles.get('--flrm-scale-y')).toBe('1'); + }); + + it('stretches vertically when the video is wider than the player', () => { + state.selectMode('stretch'); + const { player, classes, styles } = createPlayer(1440, 1080, 1920, 1080); + + applyFill(player); + + expect(classes.has('flrm-fill-on')).toBe(true); + expect(styles.get('--flrm-scale-x')).toBe('1'); + expect(styles.get('--flrm-scale-y')).toBe('1.3333'); + }); + + it('uses one player class for both modes', () => { + state.selectMode('crop'); + const { player, classes } = createPlayer(); + + applyFill(player); + + expect(classes.has('flrm-fill-on')).toBe(true); + expect(classes.has('flrm-crop-on')).toBe(false); + expect(classes.has('flrm-stretch-on')).toBe(false); + + state.selectMode('stretch'); + applyFill(player); + + expect(classes.has('flrm-fill-on')).toBe(true); + expect(classes.has('flrm-crop-on')).toBe(false); + expect(classes.has('flrm-stretch-on')).toBe(false); + }); + + it('clears the previous mode while the player size is unknown', () => { + state.selectMode('crop'); + const { player, classes, styles, setSize } = createPlayer(); + applyFill(player); + + expect(classes.has('flrm-fill-on')).toBe(true); + expect(styles.get('--flrm-scale-x')).toBe('1.3333'); + + setSize(0, 0); + state.selectMode('stretch'); + applyFill(player); + + expect(classes.has('flrm-fill-on')).toBe(false); + expect(styles.has('--flrm-scale-x')).toBe(false); + expect(styles.has('--flrm-scale-y')).toBe(false); + }); +}); diff --git a/tests/helpers/storage.ts b/tests/helpers/storage.ts new file mode 100644 index 0000000..cc0615e --- /dev/null +++ b/tests/helpers/storage.ts @@ -0,0 +1,45 @@ +/** + * Shared extension-storage mock for tests. + * + * `src/platform/extension-api` captures `chrome` when it is first imported, so + * every test file must use the same mock instance. Reset the store in place + * between tests instead of replacing it. + */ + +export type Store = Record; + +export const store: Store = {}; +export const removed: string[][] = []; + +(globalThis as { chrome?: unknown }).chrome = { + storage: { + local: { + get: async (keys: string | string[]) => { + const list = Array.isArray(keys) ? keys : [keys]; + return Object.fromEntries( + list.filter((key) => key in store).map((key) => [key, store[key]]), + ); + }, + set: async (values: Store) => { + Object.assign(store, values); + }, + remove: async (keys: string | string[]) => { + const list = Array.isArray(keys) ? keys : [keys]; + removed.push(list); + for (const key of list) { + delete store[key]; + } + }, + }, + onChanged: { + addListener: () => {}, + }, + }, +}; + +export function resetStore(): void { + for (const key of Object.keys(store)) { + delete store[key]; + } + removed.length = 0; +} diff --git a/tests/state.test.ts b/tests/state.test.ts new file mode 100644 index 0000000..96eb3af --- /dev/null +++ b/tests/state.test.ts @@ -0,0 +1,100 @@ +import { beforeEach, describe, expect, it } from 'bun:test'; +import { removed, resetStore, store } from './helpers/storage'; + +beforeEach(() => { + resetStore(); +}); + +const state = await import('../src/storage/state'); + +describe('loadState', () => { + it('keeps existing fill keys', async () => { + store.fillEnabled = false; + store.fillMode = 'stretch'; + + await state.loadState(); + + expect(state.getMode()).toBe('stretch'); + expect(state.isEnabled()).toBe(false); + expect(store.fillEnabled).toBe(false); + expect(store.fillMode).toBe('stretch'); + expect(removed).toEqual([]); + }); + + // Temporary: delete this test with the `cropEnabled` migration after 1.3.0. + it('migrates the pre-1.3.0 cropEnabled key', async () => { + store.cropEnabled = true; + + await state.loadState(); + + expect(state.getMode()).toBe('crop'); + expect(state.isEnabled()).toBe(true); + expect(store.fillEnabled).toBe(true); + expect(store.fillMode).toBe('crop'); + expect('cropEnabled' in store).toBe(false); + }); + + it('starts a fresh install with crop off', async () => { + await state.loadState(); + + expect(state.getMode()).toBe('crop'); + expect(state.isEnabled()).toBe(false); + expect(store.fillEnabled).toBe(false); + expect(store.fillMode).toBe('crop'); + }); + + it('falls back to crop when the stored mode is invalid', async () => { + store.fillMode = 'zoom'; + store.fillEnabled = true; + + await state.loadState(); + + expect(state.getMode()).toBe('crop'); + expect(state.isEnabled()).toBe(true); + expect(store.fillMode).toBe('crop'); + }); +}); + +describe('selectMode', () => { + it('selects a mode and turns fill on', async () => { + await state.loadState(); + + state.selectMode('stretch'); + + expect(state.getMode()).toBe('stretch'); + expect(state.isEnabled()).toBe(true); + expect(store.fillMode).toBe('stretch'); + expect(store.fillEnabled).toBe(true); + }); + + it('keeps fill on when re-selecting the active mode', async () => { + store.fillEnabled = true; + store.fillMode = 'crop'; + await state.loadState(); + + state.selectMode('crop'); + + expect(state.getMode()).toBe('crop'); + expect(state.isEnabled()).toBe(true); + }); +}); + +describe('toggleEnabled', () => { + it('flips only the enabled flag', async () => { + store.fillEnabled = false; + store.fillMode = 'stretch'; + await state.loadState(); + + state.toggleEnabled(); + + expect(state.isEnabled()).toBe(true); + expect(state.getMode()).toBe('stretch'); + expect(store.fillEnabled).toBe(true); + expect(store.fillMode).toBe('stretch'); + + state.toggleEnabled(); + + expect(state.isEnabled()).toBe(false); + expect(store.fillEnabled).toBe(false); + }); +});