All files / src/platform Chrome.ts

100% Statements 24/24
100% Branches 0/0
100% Functions 9/9
100% Lines 21/21

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54    10x               10x 10x           10x 10x 10x 10x     10x     10x 28x 28x     8x 8x 8x 8x 8x 8x         8x       7x   5x         10x  
import type { CaptureMode } from '../lib/Db';
 
export const CAPTURE_MODES: CaptureMode[] = [
  'visible',
  'full',
  'selection',
  'tabs',
];
 
export const CAPTURE_HINT =
  'Click the Daguerre icon in the toolbar, or use a shortcut.';
export const SHORTCUT_HINTS: [keys: string, label: string][] = [
  ['Alt+Shift+V', 'Visible area'],
  ['Alt+Shift+F', 'Entire page'],
  ['Alt+Shift+S', 'Select area'],
];
/** Shown in History for pages without a host, such as local files. */
export const NO_URL_LABEL = 'Local page';
export const SAVE_PNG_LABEL = 'Download PNG';
export const SAVED_TOAST = 'Download started';
export const SEARCH_PLACEHOLDER = 'Search by title or URL';
 
/** Return true to handle "back to History" instead of following the link. */
export const leaveToHistory = () => false;
 
/** Tabs rely on `beforeunload` instead. */
export const guardClose =
  (_isDirty: () => boolean, _ask: () => Promise<boolean>) => () =>
    undefined;
 
export function downloadBlob(blob: Blob, name: string) {
  const url = URL.createObjectURL(blob);
  const a = document.createElement('a');
  a.href = url;
  a.download = name;
  a.click();
  setTimeout(() => URL.revokeObjectURL(url), 10_000);
}
 
/** Accepts a promise so the clipboard write keeps the user gesture while encoding. */
export function copyPng(png: Blob | Promise<Blob>) {
  return navigator.clipboard.write([new ClipboardItem({ 'image/png': png })]);
}
 
export function copyText(text: Promise<string>) {
  return navigator.clipboard.write([
    new ClipboardItem({
      'text/plain': text.then((t) => new Blob([t], { type: 'text/plain' })),
    }),
  ]);
}
 
export const printPage = () => window.print();