├── .nvmrc
├── .eslintignore
├── auth.js
├── fonts
├── roboto.woff
└── roboto-bold.woff
├── images
├── icon128.png
├── icon16.png
├── icon32.png
├── icon48.png
├── provider-icons
│ └── twitch.svg
└── icon.svg
├── .prettierrc
├── packages
├── hooks
│ ├── package.json
│ ├── index.ts
│ ├── use-id.ts
│ └── use-did-update-effect.ts
├── state
│ ├── package.json
│ └── index.ts
├── components
│ ├── package.json
│ ├── loading-indicator.tsx
│ ├── visually-hidden.tsx
│ ├── index.ts
│ ├── provider-label.tsx
│ ├── color-scheme.tsx
│ ├── tab-panel.tsx
│ ├── icon-button.tsx
│ ├── notice.tsx
│ ├── card.tsx
│ ├── tooltip.tsx
│ ├── tab-panels.tsx
│ └── icon.tsx
└── stub-global
│ ├── package.json
│ └── index.ts
├── .mocharc.json
├── .gitignore
├── background.html
├── test
└── setup.ts
├── CREDITS.md
├── options
├── index.tsx
└── components
│ ├── root.tsx
│ ├── section.tsx
│ ├── provider-token-error.tsx
│ ├── provider-settings.tsx
│ ├── color-scheme-setting.tsx
│ └── provider-authorization.tsx
├── popup
├── index.tsx
└── components
│ ├── test
│ └── stream-list.ts
│ ├── offline-warning.tsx
│ ├── no-streams-live.tsx
│ ├── no-search-results.tsx
│ ├── search-context.tsx
│ ├── getting-started.tsx
│ ├── if-online.tsx
│ ├── if-authenticated.tsx
│ ├── token-errors.tsx
│ ├── root.tsx
│ ├── stream.tsx
│ ├── toolbar.tsx
│ └── stream-list.tsx
├── popup.html
├── options.html
├── .github
└── workflows
│ └── test.yml
├── config.ts
├── background
├── test
│ └── oauth.ts
├── components
│ ├── connection-status.ts
│ ├── providers.tsx
│ ├── provider-subscription.ts
│ ├── migrations.ts
│ ├── persistence.ts
│ ├── badge.ts
│ └── test
│ │ └── badge.tsx
├── index.tsx
├── providers
│ ├── index.ts
│ └── twitch.ts
├── store.ts
├── store
│ └── actions.ts
└── oauth.ts
├── tsconfig.json
├── .eslintrc.json
├── manifest.json
├── options.css
├── CHANGELOG.md
├── package.json
├── README.md
├── popup.css
├── _locales
└── en
│ └── messages.json
├── common.css
└── LICENSE.md
/.nvmrc:
--------------------------------------------------------------------------------
1 | 18
2 |
--------------------------------------------------------------------------------
/.eslintignore:
--------------------------------------------------------------------------------
1 | build
2 |
--------------------------------------------------------------------------------
/auth.js:
--------------------------------------------------------------------------------
1 | browser.runtime.sendMessage(window.location.href);
2 |
--------------------------------------------------------------------------------
/fonts/roboto.woff:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/aduth/StreamLens/HEAD/fonts/roboto.woff
--------------------------------------------------------------------------------
/images/icon128.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/aduth/StreamLens/HEAD/images/icon128.png
--------------------------------------------------------------------------------
/images/icon16.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/aduth/StreamLens/HEAD/images/icon16.png
--------------------------------------------------------------------------------
/images/icon32.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/aduth/StreamLens/HEAD/images/icon32.png
--------------------------------------------------------------------------------
/images/icon48.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/aduth/StreamLens/HEAD/images/icon48.png
--------------------------------------------------------------------------------
/fonts/roboto-bold.woff:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/aduth/StreamLens/HEAD/fonts/roboto-bold.woff
--------------------------------------------------------------------------------
/.prettierrc:
--------------------------------------------------------------------------------
1 | {
2 | "singleQuote": true,
3 | "useTabs": true,
4 | "printWidth": 100,
5 | "parenSpacing": true
6 | }
7 |
--------------------------------------------------------------------------------
/packages/hooks/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "@streamlens/hooks",
3 | "private": true,
4 | "exports": {
5 | ".": "./index.ts"
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/packages/state/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "@streamlens/state",
3 | "private": true,
4 | "exports": {
5 | ".": "./index.ts"
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/packages/hooks/index.ts:
--------------------------------------------------------------------------------
1 | export { default as useDidUpdateEffect } from './use-did-update-effect';
2 | export { default as useId } from './use-id';
3 |
--------------------------------------------------------------------------------
/packages/components/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "@streamlens/components",
3 | "private": true,
4 | "exports": {
5 | ".": "./index.ts"
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/packages/stub-global/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "@streamlens/stub-global",
3 | "private": true,
4 | "exports": {
5 | ".": "./index.ts"
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/.mocharc.json:
--------------------------------------------------------------------------------
1 | {
2 | "loader": "esbuild-esm-loader",
3 | "require": ["undom/register", "test/setup.ts"],
4 | "extension": ["js", "jsx", "ts", "tsx"]
5 | }
6 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # System
2 | .DS_Store
3 |
4 | # Dependencies
5 | node_modules
6 |
7 | # Generated
8 | build
9 | stream-lens.zip
10 |
11 | # Logs
12 | *.log
13 |
--------------------------------------------------------------------------------
/background.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
StreamLens
4 |
5 |
6 |
--------------------------------------------------------------------------------
/test/setup.ts:
--------------------------------------------------------------------------------
1 | import { webcrypto } from 'crypto';
2 | import chai from 'chai';
3 | import sinonChai from 'sinon-chai';
4 |
5 | // @ts-ignore: Node types aren't up-to-date with webcrypto properties.
6 | globalThis.crypto = webcrypto;
7 |
8 | chai.use(sinonChai);
9 |
--------------------------------------------------------------------------------
/packages/hooks/use-id.ts:
--------------------------------------------------------------------------------
1 | import { useMemo } from 'preact/hooks';
2 |
3 | let counter = 0;
4 |
5 | function useId(prefix: string): string {
6 | const id = useMemo(() => `${prefix}-${++counter}`, [prefix]);
7 |
8 | return id;
9 | }
10 |
11 | export default useId;
12 |
--------------------------------------------------------------------------------
/CREDITS.md:
--------------------------------------------------------------------------------
1 | This project makes use of and thanks the following:
2 |
3 | - Icons provided by [FontAwesome](https://fontawesome.com/) under the [CC BY 4.0 License](https://creativecommons.org/licenses/by/4.0/). Revisions include adaptation into [React component ``](./packages/components/icon.tsx).
4 |
--------------------------------------------------------------------------------
/options/index.tsx:
--------------------------------------------------------------------------------
1 | import { render } from 'preact';
2 | import createStore from 'unistore';
3 | import { replica } from 'unistore-browser-sync';
4 | import Root from './components/root';
5 |
6 | replica(createStore()).then((store) => {
7 | const appRoot = document.getElementById('app');
8 | if (appRoot) {
9 | render(, appRoot);
10 | }
11 | });
12 |
--------------------------------------------------------------------------------
/popup/index.tsx:
--------------------------------------------------------------------------------
1 | import { render } from 'preact';
2 | import createStore from 'unistore';
3 | import { replica } from 'unistore-browser-sync';
4 | import Root from './components/root';
5 |
6 | replica(createStore()).then((store) => {
7 | const appRoot = document.getElementById('app');
8 | if (appRoot) {
9 | render(, appRoot);
10 | }
11 | });
12 |
--------------------------------------------------------------------------------
/popup/components/test/stream-list.ts:
--------------------------------------------------------------------------------
1 | import { expect } from 'chai';
2 | import { isTolerantStringMatch } from '../stream-list';
3 |
4 | describe('isTolerantStringMatch', () => {
5 | it('normalizes case, ignores whitespace, punctuation', () => {
6 | expect(
7 | isTolerantStringMatch(
8 | 'age of empires definitive edition',
9 | 'Age of Empires: Definitive Edition'
10 | )
11 | ).to.be.true;
12 | });
13 | });
14 |
--------------------------------------------------------------------------------
/images/provider-icons/twitch.svg:
--------------------------------------------------------------------------------
1 |
9 |
--------------------------------------------------------------------------------
/popup/components/offline-warning.tsx:
--------------------------------------------------------------------------------
1 | import { Card } from '@streamlens/components';
2 |
3 | /**
4 | * Returns a Offline Warning element.
5 | */
6 | function OfflineWarning() {
7 | const title = browser.i18n.getMessage('popupOfflineWarningTitle');
8 | const description = browser.i18n.getMessage('popupOfflineWarningDescription');
9 |
10 | return (
11 |
12 | {description}
13 |
14 | );
15 | }
16 |
17 | export default OfflineWarning;
18 |
--------------------------------------------------------------------------------
/popup/components/no-streams-live.tsx:
--------------------------------------------------------------------------------
1 | import { Card } from '@streamlens/components';
2 |
3 | /**
4 | * Returns a No Streams Live element.
5 | */
6 | function NoStreamsLive() {
7 | const title = browser.i18n.getMessage('popupNoStreamsLiveTitle');
8 | const description = browser.i18n.getMessage('popupNoStreamsLiveDescription');
9 |
10 | return (
11 |
12 | {description}
13 |
14 | );
15 | }
16 |
17 | export default NoStreamsLive;
18 |
--------------------------------------------------------------------------------
/popup/components/no-search-results.tsx:
--------------------------------------------------------------------------------
1 | import { Card } from '@streamlens/components';
2 |
3 | /**
4 | * Returns a No Streams Live element.
5 | */
6 | function NoSearchResults() {
7 | const title = browser.i18n.getMessage('popupNoSearchResultsTitle');
8 | const description = browser.i18n.getMessage('popupNoSearchResultsDescription');
9 |
10 | return (
11 |
12 | {description}
13 |
14 | );
15 | }
16 |
17 | export default NoSearchResults;
18 |
--------------------------------------------------------------------------------
/packages/components/loading-indicator.tsx:
--------------------------------------------------------------------------------
1 | /**
2 | * Returns a Loading Indicator element.
3 | */
4 | function LoadingIndicator() {
5 | const label = browser.i18n.getMessage('commonLoadingIndicatorLabel');
6 |
7 | return (
8 |
13 | );
14 | }
15 |
16 | export default LoadingIndicator;
17 |
--------------------------------------------------------------------------------
/popup.html:
--------------------------------------------------------------------------------
1 |
2 |
3 | StreamLens
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/options.html:
--------------------------------------------------------------------------------
1 |
2 |
3 | StreamLens
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/.github/workflows/test.yml:
--------------------------------------------------------------------------------
1 | name: Test
2 |
3 | on: [push]
4 |
5 | jobs:
6 | build:
7 | runs-on: ubuntu-latest
8 | steps:
9 | - name: Checkout repository
10 | uses: actions/checkout@v2
11 | - name: Read .nvmrc
12 | run: echo ::set-output name=NVMRC::$(cat .nvmrc)
13 | id: nvm
14 | - name: Setup Node.js
15 | uses: actions/setup-node@v2
16 | with:
17 | node-version: '${{ steps.nvm.outputs.NVMRC }}'
18 | - name: Install dependencies
19 | run: npm ci
20 | - name: Run tests
21 | run: npm test
22 |
--------------------------------------------------------------------------------
/config.ts:
--------------------------------------------------------------------------------
1 | /**
2 | * URL to which OAuth authorization should redirect upon completion.
3 | */
4 | export const authRedirectURL = 'https://streamlens.app/auth/';
5 |
6 | /**
7 | * Extension-specific provider application details.
8 | */
9 | interface SLProviderApplication {
10 | /**
11 | * Application client ID.
12 | */
13 | clientId: string;
14 | }
15 |
16 | /**
17 | * Extension provider applications, keyed by provider name.
18 | */
19 | export const applications: Record = {
20 | twitch: {
21 | clientId: 'tjitmvnig93faxcivnlhuxvtl8s8vh7',
22 | },
23 | };
24 |
--------------------------------------------------------------------------------
/images/icon.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/packages/components/visually-hidden.tsx:
--------------------------------------------------------------------------------
1 | import { ComponentChildren } from 'preact';
2 |
3 | interface VisuallyHiddenProps {
4 | /**
5 | * Hidden contents.
6 | */
7 | children: ComponentChildren;
8 | }
9 |
10 | /** @typedef {import('preact').ComponentChildren} ComponentChildren */
11 |
12 | /**
13 | * Returns text intended to be present in the DOM but visually hidden,
14 | * typically used for screen reader text.
15 | */
16 | function VisuallyHidden({ children }: VisuallyHiddenProps) {
17 | return {children};
18 | }
19 |
20 | export default VisuallyHidden;
21 |
--------------------------------------------------------------------------------
/packages/hooks/use-did-update-effect.ts:
--------------------------------------------------------------------------------
1 | import { useEffect, useRef, EffectCallback, Inputs } from 'preact/hooks';
2 |
3 | /**
4 | * Hook which behaves identical to useEffect but skips the initial render callback.
5 | *
6 | * @param callback Effect callback.
7 | * @param inputs Effect inputs.
8 | */
9 | function useDidUpdateEffect(callback: EffectCallback, inputs?: Inputs) {
10 | const didMount = useRef(false);
11 | useEffect(() => {
12 | if (didMount.current) {
13 | return callback();
14 | }
15 |
16 | didMount.current = true;
17 | }, inputs);
18 | }
19 |
20 | export default useDidUpdateEffect;
21 |
--------------------------------------------------------------------------------
/options/components/root.tsx:
--------------------------------------------------------------------------------
1 | import { StoreContext } from '@streamlens/state';
2 | import { SyncStore } from 'unistore-browser-sync';
3 | import ProviderSettings from './provider-settings';
4 | import ColorSchemeSetting from './color-scheme-setting';
5 |
6 | interface RootProps {
7 | /**
8 | * Store instance.
9 | */
10 | store: SyncStore;
11 | }
12 |
13 | /**
14 | * Returns a Root element.
15 | */
16 | function Root({ store }: RootProps) {
17 | return (
18 |
19 |
20 |
21 |
22 | );
23 | }
24 |
25 | export default Root;
26 |
--------------------------------------------------------------------------------
/background/test/oauth.ts:
--------------------------------------------------------------------------------
1 | import { expect } from 'chai';
2 | import { getRandomString } from '../oauth';
3 |
4 | describe('getRandomString', () => {
5 | it('produces a string', () => {
6 | expect(getRandomString()).to.be.a('string');
7 | });
8 |
9 | it('produces a string of default length 32', () => {
10 | expect(getRandomString()).to.have.lengthOf(32);
11 | });
12 |
13 | it('produces a string of custom length', () => {
14 | expect(getRandomString(40)).to.have.lengthOf(40);
15 | });
16 |
17 | it('includes only base36', () => {
18 | expect(getRandomString()).to.not.match(/[^0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ]/i);
19 | });
20 | });
21 |
--------------------------------------------------------------------------------
/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "compilerOptions": {
3 | "baseUrl": ".",
4 | "paths": {
5 | "/*": ["*"]
6 | },
7 | "module": "esnext",
8 | "moduleResolution": "node",
9 | "target": "es2019",
10 | "lib": ["dom", "esnext"],
11 | "skipLibCheck": true,
12 | "typeRoots": ["node_modules/@types", "node_modules/web-ext-types"],
13 | "noEmit": true,
14 | "strictNullChecks": true,
15 | "jsx": "react-jsx",
16 | "jsxImportSource": "preact"
17 | },
18 | "include": [
19 | "background",
20 | "packages",
21 | "options",
22 | "popup",
23 | "packages/state",
24 | "packages/components"
25 | ],
26 | "exclude": ["node_modules"]
27 | }
28 |
--------------------------------------------------------------------------------
/packages/components/index.ts:
--------------------------------------------------------------------------------
1 | export { default as Card } from './card';
2 | export { default as ColorScheme } from './color-scheme';
3 | export { default as IconButton } from './icon-button';
4 | export { default as Icon } from './icon';
5 | export { default as LoadingIndicator } from './loading-indicator';
6 | export { default as Notice } from './notice';
7 | export { default as ProviderLabel, getProviderLabel } from './provider-label';
8 | export { default as TabPanel } from './tab-panel';
9 | export { default as TabPanels } from './tab-panels';
10 | export { default as Tooltip } from './tooltip';
11 | export { default as VisuallyHidden } from './visually-hidden';
12 |
--------------------------------------------------------------------------------
/popup/components/search-context.tsx:
--------------------------------------------------------------------------------
1 | import { createContext, ComponentChildren } from 'preact';
2 | import { StateUpdater, useState } from 'preact/hooks';
3 |
4 | interface SearchProviderProps {
5 | /**
6 | * Context children.
7 | */
8 | children: ComponentChildren;
9 | }
10 |
11 | export const SearchContext = createContext(['', () => {}] as [
12 | value: string,
13 | setValue: StateUpdater
14 | ]);
15 |
16 | /**
17 | * Returns an element which provides the search state context to its children.
18 | */
19 | export function SearchProvider({ children }: SearchProviderProps) {
20 | const value = useState('');
21 |
22 | return {children};
23 | }
24 |
--------------------------------------------------------------------------------
/popup/components/getting-started.tsx:
--------------------------------------------------------------------------------
1 | import { Card } from '@streamlens/components';
2 |
3 | /**
4 | * Returns a Getting Started element.
5 | */
6 | function GettingStarted() {
7 | const title = browser.i18n.getMessage('popupGettingStartedWelcome');
8 | const buttonText = browser.i18n.getMessage('popupGettingStartedSettings');
9 | const description = browser.i18n.getMessage('popupGettingStartedDescription');
10 |
11 | return (
12 | {
15 | browser.runtime.openOptionsPage();
16 | window.close();
17 | }}
18 | title={title}
19 | buttonText={buttonText}
20 | >
21 | {description}
22 |
23 | );
24 | }
25 |
26 | export default GettingStarted;
27 |
--------------------------------------------------------------------------------
/.eslintrc.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": ["@aduth/eslint-config"],
3 | "plugins": ["react", "import"],
4 | "parserOptions": {
5 | "ecmaFeatures": {
6 | "jsx": true
7 | }
8 | },
9 | "env": {
10 | "browser": true
11 | },
12 | "globals": {
13 | "browser": true,
14 | "globalThis": true
15 | },
16 | "rules": {
17 | "import/no-duplicates": "error",
18 | "no-duplicate-imports": "off",
19 | "react/jsx-filename-extension": ["error", { "extensions": [".tsx"] }],
20 | "react/jsx-uses-react": "error",
21 | "react/jsx-uses-vars": "error",
22 | "array-callback-return": ["error", { "allowImplicit": true }]
23 | },
24 | "overrides": [
25 | {
26 | "files": ["**/test/**/*"],
27 | "env": {
28 | "browser": false,
29 | "node": true,
30 | "mocha": true
31 | }
32 | }
33 | ]
34 | }
35 |
--------------------------------------------------------------------------------
/manifest.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "StreamLens",
3 | "version": "1.3.2",
4 | "description": "__MSG_extDescription__",
5 | "background": {
6 | "page": "background.html"
7 | },
8 | "browser_action": {
9 | "default_popup": "popup.html"
10 | },
11 | "icons": {
12 | "16": "images/icon16.png",
13 | "32": "images/icon32.png",
14 | "48": "images/icon48.png",
15 | "128": "images/icon128.png"
16 | },
17 | "options_ui": {
18 | "page": "options.html",
19 | "open_in_tab": false
20 | },
21 | "content_scripts": [
22 | {
23 | "matches": [ "https://streamlens.app/auth/" ],
24 | "js": [ "node_modules/webextension-polyfill/dist/browser-polyfill.js", "auth.js" ],
25 | "all_frames": true
26 | }
27 | ],
28 | "default_locale": "en",
29 | "permissions": [ "storage" ],
30 | "manifest_version": 2
31 | }
32 |
--------------------------------------------------------------------------------
/packages/components/provider-label.tsx:
--------------------------------------------------------------------------------
1 | import { Fragment } from 'preact';
2 |
3 | interface ProviderLabelProps {
4 | /**
5 | * Provider name for which to return label.
6 | */
7 | providerName: string;
8 | }
9 |
10 | /**
11 | * Provider label mapping.
12 | */
13 | const LABELS: Record = {
14 | twitch: 'Twitch',
15 | };
16 |
17 | /**
18 | * Returns a provider label as a string.
19 | *
20 | * @param providerName Provider name for which to return label.
21 | */
22 | export const getProviderLabel = (providerName: string): string | null =>
23 | LABELS[providerName] || null;
24 |
25 | /**
26 | * Returns a Provider Label element.
27 | */
28 | function ProviderLabel({ providerName }: ProviderLabelProps) {
29 | return <>{getProviderLabel(providerName)}>;
30 | }
31 |
32 | export default ProviderLabel;
33 |
--------------------------------------------------------------------------------
/packages/components/color-scheme.tsx:
--------------------------------------------------------------------------------
1 | import { Fragment, ComponentChildren } from 'preact';
2 | import { useEffect } from 'preact/hooks';
3 | import { useSelect } from '@streamlens/state';
4 |
5 | interface ColorSchemeProps {
6 | /**
7 | * Contents of section
8 | */
9 | children: ComponentChildren;
10 | }
11 |
12 | /**
13 | * Returns a wrapping element which assigns the color context as a data
14 | * attribute on its wrapping element.
15 | */
16 | function ColorScheme({ children }: ColorSchemeProps) {
17 | const colorScheme = useSelect((state) => state.preferences.colorScheme);
18 |
19 | useEffect(() => {
20 | const normalColorScheme = colorScheme === null ? 'inherit' : colorScheme;
21 | document.body.dataset.theme = normalColorScheme;
22 | }, [colorScheme]);
23 |
24 | return <>{children}>;
25 | }
26 |
27 | export default ColorScheme;
28 |
--------------------------------------------------------------------------------
/background/components/connection-status.ts:
--------------------------------------------------------------------------------
1 | import { useEffect } from 'preact/hooks';
2 | import { useDispatch } from '@streamlens/state';
3 |
4 | /**
5 | * Component managing online status, responding to global events.
6 | */
7 | function ConnectionStatus() {
8 | const dispatch = useDispatch();
9 |
10 | useEffect(() => {
11 | const toggleIsOnline = (isOnline) => dispatch('toggleIsOnline', isOnline);
12 | const setIsOnline = () => toggleIsOnline(true);
13 | const setIsOffline = () => toggleIsOnline(false);
14 |
15 | self.addEventListener('online', setIsOnline);
16 | self.addEventListener('offline', setIsOffline);
17 |
18 | return () => {
19 | self.removeEventListener('online', setIsOnline);
20 | self.removeEventListener('offline', setIsOffline);
21 | };
22 | }, []);
23 |
24 | return null;
25 | }
26 |
27 | export default ConnectionStatus;
28 |
--------------------------------------------------------------------------------
/options/components/section.tsx:
--------------------------------------------------------------------------------
1 | import { ComponentChildren } from 'preact';
2 |
3 | interface SectionProps {
4 | /**
5 | * Section title.
6 | */
7 | title: string;
8 |
9 | /**
10 | * Optional section description.
11 | */
12 | description?: string;
13 |
14 | /**
15 | * Contents of section.
16 | */
17 | children?: ComponentChildren;
18 | }
19 |
20 | /** @typedef {import('preact').ComponentChildren} ComponentChildren */
21 |
22 | /**
23 | * Returns a Section element.
24 | */
25 | function Section({ title, description, children }: SectionProps) {
26 | return (
27 |
28 |
31 | {description && {description}
}
32 | {children}
33 |
34 | );
35 | }
36 |
37 | export default Section;
38 |
--------------------------------------------------------------------------------
/popup/components/if-online.tsx:
--------------------------------------------------------------------------------
1 | import { Fragment, ComponentChildren } from 'preact';
2 | import { useSelect } from '@streamlens/state';
3 |
4 | interface IfOnlineProps {
5 | /**
6 | * Component children.
7 | */
8 | children: ComponentChildren;
9 |
10 | /**
11 | * Whether to render only if authentications exist.
12 | */
13 | hasConnection?: boolean;
14 | }
15 |
16 | /**
17 | * Component which renders its children only if the user has configured some authentications.
18 | */
19 | function IfOnline({ hasConnection = true, children }: IfOnlineProps) {
20 | const isOnline = useSelect((state) => state.isOnline);
21 |
22 | return hasConnection === isOnline ? <>{children}> : null;
23 | }
24 |
25 | IfOnline.Else = ({ children }: Omit) => (
26 |
27 | );
28 |
29 | export default IfOnline;
30 |
--------------------------------------------------------------------------------
/packages/components/tab-panel.tsx:
--------------------------------------------------------------------------------
1 | import { ComponentChildren, VNode } from 'preact';
2 |
3 | interface TabPanelProps {
4 | /**
5 | * Tab label.
6 | */
7 | name: VNode | string;
8 |
9 | /**
10 | * Unique identifier for tab.
11 | */
12 | id?: string;
13 |
14 | /**
15 | * Unique identifier for tab label.
16 | */
17 | labelId?: string;
18 |
19 | /**
20 | * Whether the tab is active.
21 | */
22 | isActive?: boolean;
23 |
24 | /**
25 | * Tab contents.
26 | */
27 | children: ComponentChildren;
28 | }
29 |
30 | function TabPanel({ id, labelId, isActive, children }: TabPanelProps): VNode {
31 | const classes = ['tab-panel', isActive && 'tab-panel--active'].filter(Boolean).join(' ');
32 |
33 | return (
34 |
35 | {children}
36 |
37 | );
38 | }
39 |
40 | export default TabPanel;
41 |
--------------------------------------------------------------------------------
/background/index.tsx:
--------------------------------------------------------------------------------
1 | import { render } from 'preact';
2 | import createStore from 'unistore';
3 | import { primary } from 'unistore-browser-sync';
4 | import { StoreContext } from '@streamlens/state';
5 | import { getInitialState } from './store';
6 | import Badge from './components/badge';
7 | import Persistence from './components/persistence';
8 | import Migrations from './components/migrations';
9 | import Providers from './components/providers';
10 | import ConnectionStatus from './components/connection-status';
11 | import * as actions from './store/actions';
12 |
13 | getInitialState().then((initialState) => {
14 | const store = primary(createStore(initialState), { ...actions });
15 |
16 | render(
17 |
18 |
19 |
20 |
21 |
22 |
23 | ,
24 | {} as Document
25 | );
26 | });
27 |
--------------------------------------------------------------------------------
/packages/components/icon-button.tsx:
--------------------------------------------------------------------------------
1 | import Tooltip, { TooltipPosition } from './tooltip';
2 | import Icon, { IconProps } from './icon';
3 |
4 | interface IconButtonProps extends IconProps {
5 | /**
6 | * Click callback.
7 | */
8 | onClick: (event: Event) => void;
9 |
10 | /**
11 | * Tooltip text, and accessible label for button.
12 | */
13 | label: string;
14 |
15 | /**
16 | * Tooltip position.
17 | */
18 | tooltipPosition: TooltipPosition;
19 | }
20 |
21 | /**
22 | * Returns an Icon element.
23 | */
24 | function IconButton({ onClick, label, tooltipPosition, ...iconProps }: IconButtonProps) {
25 | return (
26 |
35 |
36 |
37 | );
38 | }
39 |
40 | export default IconButton;
41 |
--------------------------------------------------------------------------------
/options/components/provider-token-error.tsx:
--------------------------------------------------------------------------------
1 | import { useDispatch } from '@streamlens/state';
2 | import { Notice, getProviderLabel } from '@streamlens/components';
3 |
4 | interface ProviderTokenErrorProps {
5 | /**
6 | * Name of provider for which token error occurred.
7 | */
8 | providerName: string;
9 | }
10 |
11 | /**
12 | * Returns a Token Errors element.
13 | */
14 | function ProviderTokenError({ providerName }: ProviderTokenErrorProps) {
15 | const dispatch = useDispatch();
16 |
17 | const label = getProviderLabel(providerName);
18 | if (!label) {
19 | return null;
20 | }
21 |
22 | const text = browser.i18n.getMessage('providerTokenError', [label]);
23 | const buttonText = browser.i18n.getMessage('providerTokenErrorFix');
24 |
25 | return (
26 | dispatch('authenticate', providerName)}
29 | text={text}
30 | buttonText={buttonText}
31 | />
32 | );
33 | }
34 |
35 | export default ProviderTokenError;
36 |
--------------------------------------------------------------------------------
/popup/components/if-authenticated.tsx:
--------------------------------------------------------------------------------
1 | import { Fragment, ComponentChildren } from 'preact';
2 | import { isEmpty } from 'lodash-es';
3 | import { useSelect } from '@streamlens/state';
4 |
5 | interface IfAuthenticatedProps {
6 | /**
7 | * Component children.
8 | */
9 | children: ComponentChildren;
10 |
11 | /**
12 | * Whether to render only if authentications exist.
13 | */
14 | hasAuth?: boolean;
15 | }
16 |
17 | /**
18 | * Component which renders its children only if the user has configured some authentications.
19 | */
20 | function IfAuthenticated({ hasAuth = true, children }: IfAuthenticatedProps) {
21 | const auth = useSelect((state) => state.auth);
22 | const hasConfiguredAuths = !isEmpty(auth);
23 |
24 | return hasConfiguredAuths === hasAuth ? <>{children}> : null;
25 | }
26 |
27 | IfAuthenticated.Else = ({ children }: Omit) => (
28 |
29 | );
30 |
31 | export default IfAuthenticated;
32 |
--------------------------------------------------------------------------------
/background/components/providers.tsx:
--------------------------------------------------------------------------------
1 | import { Fragment } from 'preact';
2 | import { useEffect } from 'preact/hooks';
3 | import { useDispatch, useSelect } from '@streamlens/state';
4 | import { providers } from '../providers';
5 | import ProviderSubscription from './provider-subscription';
6 |
7 | function Providers() {
8 | const dispatch = useDispatch();
9 | const auths = useSelect((state) => state.auth);
10 | const providerNames = useSelect((state) => state.providerNames);
11 | const isOnline = useSelect((state) => state.isOnline);
12 |
13 | useEffect(() => {
14 | Object.keys(providers).forEach((name) => dispatch('registerProviderName', name));
15 | }, []);
16 |
17 | if (!isOnline) {
18 | return null;
19 | }
20 |
21 | const subscriptions = providerNames
22 | .filter((name) => providers[name] && auths[name]?.token)
23 | .map((name) => (
24 |
25 | ));
26 |
27 | return <>{subscriptions}>;
28 | }
29 |
30 | export default Providers;
31 |
--------------------------------------------------------------------------------
/popup/components/token-errors.tsx:
--------------------------------------------------------------------------------
1 | import { findKey } from 'lodash-es';
2 | import { Notice, getProviderLabel } from '@streamlens/components';
3 | import { useSelect, useDispatch } from '@streamlens/state';
4 |
5 | /**
6 | * Returns a Token Errors element.
7 | */
8 | function TokenErrors() {
9 | const dispatch = useDispatch();
10 | const auth = useSelect((state) => state.auth);
11 |
12 | const invalidProviderName = findKey(auth, { token: null });
13 | if (!invalidProviderName) {
14 | return null;
15 | }
16 |
17 | const label = getProviderLabel(invalidProviderName);
18 | if (!label) {
19 | return null;
20 | }
21 |
22 | const text = browser.i18n.getMessage('providerTokenError', [label]);
23 | const buttonText = browser.i18n.getMessage('providerTokenErrorFix');
24 |
25 | return (
26 | {
29 | dispatch('authenticate', invalidProviderName);
30 | }}
31 | className="token-errors"
32 | text={text}
33 | buttonText={buttonText}
34 | />
35 | );
36 | }
37 |
38 | export default TokenErrors;
39 |
--------------------------------------------------------------------------------
/options/components/provider-settings.tsx:
--------------------------------------------------------------------------------
1 | import { useSelect } from '@streamlens/state';
2 | import { TabPanels, TabPanel, ProviderLabel } from '@streamlens/components';
3 | import Section from './section';
4 | import ProviderAuthorization from './provider-authorization';
5 |
6 | /**
7 | * Returns a Provider Settings element.
8 | */
9 | function ProviderSettings() {
10 | const providerNames = useSelect((state) => state.providerNames);
11 | const title = browser.i18n.getMessage('optionsProviderSettingsTitle');
12 | const description = browser.i18n.getMessage('optionsProviderSettingsDescription');
13 | const providerTabsLabel = browser.i18n.getMessage('optionsSettingsProvidersTabsLabel');
14 |
15 | return (
16 |
17 |
18 | {providerNames.map((providerName) => (
19 | }>
20 |
21 |
22 | ))}
23 |
24 |
25 | );
26 | }
27 |
28 | export default ProviderSettings;
29 |
--------------------------------------------------------------------------------
/background/providers/index.ts:
--------------------------------------------------------------------------------
1 | import { SLProviderUser, SLStream, SLAuth } from '../store';
2 | import twitch from './twitch';
3 |
4 | type SLProviderGetUser = (token: string) => SLProviderUser | Promise;
5 |
6 | type SLProviderGetStreams = (auth: SLAuth) => Promise;
7 |
8 | /**
9 | * Error thrown when provider authentication becomes invalid.
10 | */
11 | export class InvalidTokenError extends Error {}
12 |
13 | /**
14 | * Provider implementation.
15 | */
16 | export interface SLProvider {
17 | /**
18 | * Unique provider slug.
19 | */
20 | name: string;
21 |
22 | /**
23 | * OAuth endpoint from which to retrieve bearer token.
24 | */
25 | authEndpoint: string;
26 |
27 | /**
28 | * Whether the provider supports OpenID Connect.
29 | */
30 | supportsOIDC: boolean;
31 |
32 | /**
33 | * Given an OAuth bearer token, returns user details.
34 | */
35 | getUser: SLProviderGetUser;
36 |
37 | /**
38 | * Fetches and return latest stream data.
39 | */
40 | getStreams: SLProviderGetStreams;
41 | }
42 |
43 | /**
44 | * Provider implementations.
45 | */
46 | export const providers: Record = { twitch };
47 |
--------------------------------------------------------------------------------
/packages/components/notice.tsx:
--------------------------------------------------------------------------------
1 | import Icon from './icon';
2 |
3 | interface NoticeProps {
4 | /**
5 | * Icon slug, if icon to be shown.
6 | */
7 | icon?: string;
8 |
9 | /**
10 | * Notice contents.
11 | */
12 | text: string;
13 |
14 | /**
15 | * Optional additional classname.
16 | */
17 | className?: string;
18 |
19 | /**
20 | * Action button text, if button to be shown.
21 | */
22 | buttonText?: string;
23 |
24 | /**
25 | * Action button callback, if button to be shown.
26 | */
27 | buttonOnClick?: () => void;
28 | }
29 |
30 | /**
31 | * Returns a Notice element.
32 | */
33 | function Notice({ icon, text, buttonText, buttonOnClick, className }: NoticeProps) {
34 | className = ['notice', className].filter(Boolean).join(' ');
35 |
36 | return (
37 |
38 | {icon &&
}
39 |
{text}
40 | {buttonText && buttonOnClick && (
41 |
44 | )}
45 |
46 | );
47 | }
48 |
49 | export default Notice;
50 |
--------------------------------------------------------------------------------
/background/components/provider-subscription.ts:
--------------------------------------------------------------------------------
1 | import { useDispatch } from '@streamlens/state';
2 | import { useEffect } from 'preact/hooks';
3 | import { InvalidTokenError, SLProvider } from '../providers';
4 | import { SLAuth } from '../store';
5 |
6 | /**
7 | * Interval at which stream data should refresh when using default subscribe
8 | * implementation, in milliseconds.
9 | */
10 | const REFRESH_INTERVAL = 30000;
11 |
12 | interface ProviderSubscriptionProps {
13 | provider: SLProvider;
14 | auth: SLAuth;
15 | }
16 |
17 | function ProviderSubscription({ provider, auth }: ProviderSubscriptionProps) {
18 | const dispatch = useDispatch();
19 |
20 | useEffect(() => {
21 | async function refresh() {
22 | try {
23 | const streams = await provider.getStreams(auth);
24 | dispatch('updateStreams', provider.name, streams);
25 | } catch (error) {
26 | if (error instanceof InvalidTokenError) {
27 | dispatch('setTokenError', provider.name);
28 | } else {
29 | throw error;
30 | }
31 | }
32 | }
33 |
34 | refresh();
35 | const intervalId = setInterval(refresh, REFRESH_INTERVAL);
36 | return () => clearInterval(intervalId);
37 | }, [auth]);
38 |
39 | return null;
40 | }
41 |
42 | export default ProviderSubscription;
43 |
--------------------------------------------------------------------------------
/popup/components/root.tsx:
--------------------------------------------------------------------------------
1 | import { SyncStore } from 'unistore-browser-sync';
2 | import { StoreContext } from '@streamlens/state';
3 | import { ColorScheme } from '@streamlens/components';
4 | import TokenErrors from './token-errors';
5 | import GettingStarted from './getting-started';
6 | import StreamList from './stream-list';
7 | import { SearchProvider } from './search-context';
8 | import IfAuthenticated from './if-authenticated';
9 | import IfOnline from './if-online';
10 | import OfflineWarning from './offline-warning';
11 |
12 | interface RootProps {
13 | /**
14 | * Store instance.
15 | */
16 | store: SyncStore;
17 | }
18 |
19 | /**
20 | * Returns a Root element.
21 | */
22 | function Root({ store }: RootProps) {
23 | return (
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 | );
43 | }
44 |
45 | export default Root;
46 |
--------------------------------------------------------------------------------
/background/components/migrations.ts:
--------------------------------------------------------------------------------
1 | import { useEffect } from 'preact/hooks';
2 |
3 | /**
4 | * Object used for matching on update, including implementation of migration.
5 | */
6 | interface SLUpdateMigration {
7 | /**
8 | * Version to match for migration.
9 | */
10 | fromVersion: string;
11 |
12 | /**
13 | * Migration function.
14 | */
15 | migrate: () => void;
16 | }
17 |
18 | /**
19 | * Implemented migrations.
20 | */
21 | const MIGRATIONS: SLUpdateMigration[] = [
22 | {
23 | fromVersion: '1.0.0',
24 | migrate() {
25 | let { initialState } = window.localStorage;
26 | if (!initialState) {
27 | return;
28 | }
29 |
30 | try {
31 | initialState = JSON.parse(initialState);
32 | browser.storage.sync.set({ initialState });
33 | delete window.localStorage.initialState;
34 | } catch (error) {}
35 | },
36 | },
37 | ];
38 |
39 | function Migrations() {
40 | useEffect(() => {
41 | browser.runtime.onInstalled.addListener((details) => {
42 | const { reason, previousVersion } = details;
43 | if (reason !== 'update') {
44 | return;
45 | }
46 |
47 | const migrations = MIGRATIONS.filter(({ fromVersion }) => fromVersion === previousVersion);
48 | migrations.forEach(({ migrate }) => migrate());
49 | });
50 | }, []);
51 |
52 | return null;
53 | }
54 |
55 | export default Migrations;
56 |
--------------------------------------------------------------------------------
/packages/components/card.tsx:
--------------------------------------------------------------------------------
1 | import { ComponentChildren } from 'preact';
2 | import Icon from './icon';
3 |
4 | interface CardProps {
5 | /**
6 | * Icon slug, if icon to be shown.
7 | */
8 | icon?: string;
9 |
10 | /**
11 | * Card title.
12 | */
13 | title: string;
14 |
15 | /**
16 | * Card contents.
17 | */
18 | children?: ComponentChildren;
19 |
20 | /**
21 | * Optional additional classname.
22 | */
23 | className?: string;
24 |
25 | /**
26 | * Action button text, if button to be shown.
27 | */
28 | buttonText?: string;
29 |
30 | /**
31 | * Action button callback, if button to be shown.
32 | */
33 | buttonOnClick?: () => void;
34 | }
35 |
36 | /**
37 | * Returns a Card element.
38 | */
39 | function Card({ icon, title, children, className, buttonText, buttonOnClick }: CardProps) {
40 | className = ['card', className].filter(Boolean).join(' ');
41 |
42 | return (
43 |
44 | {icon &&
}
45 |
{title}
46 |
{children}
47 | {buttonText && buttonOnClick && (
48 |
51 | )}
52 |
53 | );
54 | }
55 |
56 | export default Card;
57 |
--------------------------------------------------------------------------------
/packages/components/tooltip.tsx:
--------------------------------------------------------------------------------
1 | import { h, ComponentChildren } from 'preact';
2 |
3 | /**
4 | * Valid tooltip position.
5 | */
6 | export type TooltipPosition =
7 | | 'top'
8 | | 'top-center'
9 | | 'top-left'
10 | | 'bottom'
11 | | 'bottom-center'
12 | | 'bottom-left';
13 |
14 | interface TooltipProps {
15 | /**
16 | * Optional container type.
17 | */
18 | tagName?: string;
19 |
20 | /**
21 | * Tooltip text.
22 | */
23 | text: string;
24 |
25 | /**
26 | * Tooltip position.
27 | */
28 | position?: TooltipPosition;
29 |
30 | /**
31 | * Tooltip children, used as content to position tooltip against.
32 | */
33 | children?: ComponentChildren;
34 |
35 | /**
36 | * Optional class name.
37 | */
38 | className?: string;
39 | }
40 |
41 | /**
42 | * Returns a Tooltip element.
43 | */
44 | function Tooltip({
45 | tagName = 'div',
46 | text,
47 | position = 'top',
48 | children,
49 | className,
50 | ...props
51 | }: TooltipProps & Record) {
52 | const [y, x = 'center'] = position.split('-');
53 | const classes = ['tooltip', 'is-' + y, 'is-' + x, className].filter(Boolean).join(' ');
54 |
55 | return h(
56 | tagName,
57 | {
58 | ...props,
59 | className: classes,
60 | },
61 | ,
62 | {text},
63 | children
64 | );
65 | }
66 |
67 | export default Tooltip;
68 |
--------------------------------------------------------------------------------
/background/components/persistence.ts:
--------------------------------------------------------------------------------
1 | import { useSelect } from '@streamlens/state';
2 | import { useDidUpdateEffect } from '@streamlens/hooks';
3 | import { SLState } from '../store';
4 |
5 | /**
6 | * StreamLens storage value.
7 | */
8 | export interface SLStorageValue {
9 | /**
10 | * Initial state.
11 | */
12 | initialState?: Partial;
13 | }
14 |
15 | /**
16 | * Returns initial state from storage, or an empty object if none exists.
17 | */
18 | export async function getPersistedState(): Promise> {
19 | try {
20 | const { initialState = {} }: SLStorageValue = await browser.storage.sync.get('initialState');
21 | return initialState;
22 | } catch (error) {
23 | // An error can be thrown if the get operation fails. This can happen,
24 | // for example, when loading as a temporary extension in Firefox.
25 | //
26 | // See: https://bugzil.la/1323228
27 | return {};
28 | }
29 | }
30 |
31 | function Persistence() {
32 | const auth = useSelect((state) => state.auth);
33 | const preferences = useSelect((state) => state.preferences);
34 |
35 | useDidUpdateEffect(() => {
36 | // Fire and forget to ensure consecutive `set` is called in order of
37 | // state change irrespective completion of previous persist.
38 | browser.storage.sync.set({
39 | initialState: {
40 | auth,
41 | preferences,
42 | },
43 | });
44 | }, [auth, preferences]);
45 |
46 | return null;
47 | }
48 |
49 | export default Persistence;
50 |
--------------------------------------------------------------------------------
/options/components/color-scheme-setting.tsx:
--------------------------------------------------------------------------------
1 | import { useSelect, useDispatch } from '@streamlens/state';
2 | import Section from './section';
3 |
4 | /**
5 | * Returns a Provider Authorizations element.
6 | */
7 | function ColorSchemeSetting() {
8 | const currentValue = useSelect((state) => state.preferences.colorScheme);
9 | const dispatch = useDispatch();
10 | const title = browser.i18n.getMessage('optionsColorSchemeTitle');
11 | const description = browser.i18n.getMessage('optionsColorSchemeDescription');
12 | const options = [
13 | {
14 | label: browser.i18n.getMessage('optionsColorSchemeInherit'),
15 | value: null,
16 | },
17 | {
18 | label: browser.i18n.getMessage('optionsColorSchemeLight'),
19 | value: 'light',
20 | },
21 | {
22 | label: browser.i18n.getMessage('optionsColorSchemeDark'),
23 | value: 'dark',
24 | },
25 | ];
26 |
27 | return (
28 |
49 | );
50 | }
51 |
52 | export default ColorSchemeSetting;
53 |
--------------------------------------------------------------------------------
/packages/state/index.ts:
--------------------------------------------------------------------------------
1 | import { createContext } from 'preact';
2 | import { Dispatch, SyncStore } from 'unistore-browser-sync';
3 | import { useContext, useState, useLayoutEffect } from 'preact/hooks';
4 | import { SLState } from '../../background/store';
5 |
6 | export const StoreContext = createContext(null as SyncStore | null);
7 |
8 | /**
9 | * Hook which returns the current store from context.
10 | *
11 | * @return Store from context provider.
12 | */
13 | export function useStore(): SyncStore {
14 | return useContext(StoreContext)!;
15 | }
16 |
17 | /**
18 | * Hook which returns a dispatch function, from the store context if available.
19 | */
20 | export function useDispatch(): Dispatch {
21 | const store = useStore();
22 |
23 | return store.dispatch;
24 | }
25 |
26 | /**
27 | * Hook which returns a value derived using a given selector function, updated
28 | * when state changes.
29 | *
30 | * @return Selector-derived value.
31 | */
32 | export function useSelect(selector: (state: SLState) => SLSelected): SLSelected {
33 | const store = useStore();
34 | const state = useState(getNextResult);
35 |
36 | function getNextResult() {
37 | return selector(store.getState());
38 | }
39 |
40 | useLayoutEffect(
41 | function () {
42 | function onStateChange() {
43 | state[1](getNextResult());
44 | }
45 |
46 | onStateChange();
47 |
48 | return store.subscribe(onStateChange);
49 | },
50 | [store, selector]
51 | );
52 |
53 | return state[0];
54 | }
55 |
--------------------------------------------------------------------------------
/packages/stub-global/index.ts:
--------------------------------------------------------------------------------
1 | import { before, after } from 'mocha';
2 | import { stub } from 'sinon';
3 |
4 | /**
5 | * Map of global top-level key to number of instances of `useStubbedGlobal`.
6 | */
7 | const instances: Map = new Map();
8 |
9 | export function useStubbedGlobal(path: string, value = stub()) {
10 | const pathParts = path.split('.');
11 | const topLevelKey = pathParts[0];
12 | let originalTopLevelValue;
13 |
14 | before(() => {
15 | // Only track the top-level value for the first instance of the test helper.
16 | const instance = instances.get(topLevelKey);
17 | if (!instance) {
18 | instances.set(topLevelKey, 1);
19 | originalTopLevelValue = globalThis[topLevelKey];
20 | }
21 |
22 | let target = globalThis;
23 | for (let i = 0; i < pathParts.length; i++) {
24 | const key = pathParts[i];
25 | if (i === pathParts.length - 1) {
26 | target[key] = value;
27 | } else {
28 | target[key] = { ...target[key] };
29 | target = target[key];
30 | }
31 | }
32 | });
33 |
34 | after(() => {
35 | // Restore top-level value only for the first instance of the test helper.
36 | const instance = instances.get(topLevelKey)!;
37 | if (instance === 1) {
38 | if (originalTopLevelValue === undefined) {
39 | delete globalThis[topLevelKey];
40 | } else {
41 | globalThis[topLevelKey] = originalTopLevelValue;
42 | }
43 |
44 | instances.delete(topLevelKey);
45 | } else {
46 | instances.set(topLevelKey, instance - 1);
47 | }
48 | });
49 | }
50 |
--------------------------------------------------------------------------------
/popup/components/stream.tsx:
--------------------------------------------------------------------------------
1 | import { SLStream } from '/background/store';
2 |
3 | /**
4 | * Returns a Stream element.
5 | *
6 | * @param props Component props.
7 | */
8 | function Stream({ url, title, providerName, login, avatar, activity, viewers }: SLStream) {
9 | const label = browser.i18n.getMessage('popupStreamLinkAccessibleLabel', [
10 | login,
11 | activity || '',
12 | String(viewers),
13 | ]);
14 |
15 | return (
16 | {
21 | // In Firefox, if the click handler is only responsible for
22 | // closing the popup, the navigation will not occur as expected.
23 | // Instead, emulate the navigation to ensure expected order of
24 | // window close.
25 | window.open(event.currentTarget.href, '_blank');
26 | window.close();
27 | event.preventDefault();
28 | }}
29 | className="stream"
30 | title={title}
31 | >
32 |
33 | {avatar &&

}
34 |

40 |
41 |
42 |
{login}
43 | {activity &&
{activity}
}
44 |
45 | {new Intl.NumberFormat().format(viewers)}
46 |
47 | );
48 | }
49 |
50 | export default Stream;
51 |
--------------------------------------------------------------------------------
/background/components/badge.ts:
--------------------------------------------------------------------------------
1 | import { some, isEmpty, size } from 'lodash-es';
2 | import { useSelect } from '@streamlens/state';
3 | import { useEffect } from 'preact/hooks';
4 |
5 | /**
6 | * Badge colors.
7 | */
8 | export enum Colors {
9 | /**
10 | * Badge color for error state.
11 | */
12 | ERROR = '#bc152e',
13 |
14 | /**
15 | * Badge colors for all other states.
16 | */
17 | DEFAULT = '#4285F4',
18 | }
19 |
20 | function Badge() {
21 | const auth = useSelect((state) => state.auth);
22 | const streams = useSelect((state) => state.streams);
23 | const isOnline = useSelect((state) => state.isOnline);
24 | const { lastReceived, data } = streams;
25 |
26 | useEffect(() => {
27 | let text, color;
28 |
29 | const isError = some(auth, { token: null }) || !isOnline;
30 | if (isError) {
31 | text = '?';
32 | color = Colors.ERROR;
33 | } else {
34 | // Only compute live streams if at least one authorization exists, and
35 | // each provider has received at least once.
36 | const hasFetched = !isEmpty(auth) && size(auth) === size(lastReceived);
37 | text = hasFetched ? String(data.length) : '';
38 | color = Colors.DEFAULT;
39 | }
40 |
41 | browser.browserAction.setBadgeText({ text });
42 | browser.browserAction.setBadgeBackgroundColor({ color });
43 |
44 | // Assigning badge text color is only available in Firefox, and only in
45 | // Firefox does the text otherwise appear as non-contrasting black.
46 | if (typeof browser.browserAction.setBadgeTextColor === 'function') {
47 | browser.browserAction.setBadgeTextColor({ color: '#fff' });
48 | }
49 | }, [lastReceived, data, auth, isOnline]);
50 |
51 | return null;
52 | }
53 |
54 | export default Badge;
55 |
--------------------------------------------------------------------------------
/popup/components/toolbar.tsx:
--------------------------------------------------------------------------------
1 | import { useContext, useRef, useEffect } from 'preact/hooks';
2 | import { IconButton, VisuallyHidden } from '@streamlens/components';
3 | import { SearchContext } from './search-context';
4 |
5 | /**
6 | * Returns a stream list toolbar.
7 | */
8 | function Toolbar() {
9 | const inputRef = useRef(null as HTMLInputElement | null);
10 | const [search, setSearch] = useContext(SearchContext);
11 |
12 | // Auto-focus does not appear to work correctly for Firefox popup rendering.
13 | // This forces focus when the toolbar is mounted.
14 | useEffect(() => inputRef.current?.focus(), []);
15 |
16 | /**
17 | * Opens the extension options panel and closes the popup.
18 | */
19 | function openOptionsPage() {
20 | browser.runtime.openOptionsPage();
21 | window.close();
22 | }
23 |
24 | const searchLabel = browser.i18n.getMessage('popupToolbarSearchLabel');
25 |
26 | return (
27 |
52 | );
53 | }
54 |
55 | export default Toolbar;
56 |
--------------------------------------------------------------------------------
/options/components/provider-authorization.tsx:
--------------------------------------------------------------------------------
1 | import { Fragment } from 'preact';
2 | import { useSelect, useDispatch } from '@streamlens/state';
3 | import ProviderTokenError from './provider-token-error';
4 |
5 | interface ProviderAuthorizationProps {
6 | /**
7 | * Provider name.
8 | */
9 | providerName: string;
10 | }
11 |
12 | /**
13 | * Returns a Provider Authorization element.
14 | */
15 | function ProviderAuthorization({ providerName }: ProviderAuthorizationProps) {
16 | const dispatch = useDispatch();
17 | const auth = useSelect((state) => state.auth);
18 |
19 | const providerAuth = auth[providerName];
20 |
21 | let classes = `provider-authorization__button is-provider-${providerName}`;
22 | if (providerAuth) {
23 | classes += ' is-authorized';
24 | }
25 |
26 | return (
27 | <>
28 | {providerAuth && providerAuth.token === null && (
29 |
30 | )}
31 | {providerAuth && (
32 |
33 | {browser.i18n.getMessage('optionsAuthorizationLogin')}{' '}
34 | {providerAuth.user.login}
35 |
36 | )}
37 |
58 | >
59 | );
60 | }
61 |
62 | export default ProviderAuthorization;
63 |
--------------------------------------------------------------------------------
/options.css:
--------------------------------------------------------------------------------
1 | /*
2 | * Elements
3 | */
4 |
5 | body {
6 | width: 560px;
7 | max-width: 100%;
8 | padding: 12px;
9 | background-color: var(--sl-background-color);
10 | color: var(--sl-font-color);
11 | }
12 |
13 | @-moz-document url-prefix() {
14 | @media (prefers-color-scheme: dark) {
15 | body {
16 | /* Match Firefox's specific extension settings background color */
17 | background-color: #202023;
18 | }
19 | }
20 | }
21 |
22 | /*
23 | * Section
24 | */
25 |
26 | .section {
27 | margin-bottom: 1rem;
28 | }
29 |
30 | .section__heading {
31 | margin: 0.4rem 0;
32 | font-size: 1.3rem;
33 | }
34 |
35 | .section__description {
36 | margin-top: 0;
37 | color: var(--sl-font-color-faded);
38 | font-size: 0.9rem;
39 | }
40 |
41 | /*
42 | * Provider Authorizations
43 | */
44 |
45 | .provider-authorizations {
46 | list-style-type: none;
47 | padding-left: 0;
48 | margin: 0;
49 | }
50 |
51 | .provider-authorization__user {
52 | font-size: 0.9rem;
53 | margin-bottom: 0.6rem;
54 | }
55 |
56 | .provider-authorization__button:not(.is-authorized) {
57 | display: flex;
58 | align-items: center;
59 | line-height: 20px;
60 | }
61 |
62 | .provider-authorization__button:not(.is-authorized).is-provider-twitch:hover,
63 | .provider-authorization__button:not(.is-authorized).is-provider-twitch:focus {
64 | filter: brightness(110%);
65 | }
66 |
67 | .provider-authorization__button:not(.is-authorized).is-provider-twitch {
68 | border-color: var(--sl-provider-twitch-foreground);
69 | background-color: var(--sl-provider-twitch-background);
70 | color: var(--sl-provider-twitch-foreground);
71 | }
72 |
73 | .provider-authorization__provider {
74 | margin-right: 6px;
75 | }
76 |
77 | /*
78 | * Color Scheme Setting
79 | */
80 |
81 | .color-scheme-setting {
82 | list-style-type: none;
83 | padding-left: 0;
84 | }
85 |
86 | .color-scheme-setting label {
87 | display: flex;
88 | align-items: center;
89 | cursor: pointer;
90 | font-size: 0.9rem;
91 | }
92 |
93 | .color-scheme-setting input {
94 | position: relative;
95 | top: -1px;
96 | margin: 0;
97 | margin-right: 6px;
98 | }
99 |
--------------------------------------------------------------------------------
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | ## v1.4.0 (Unreleased)
2 |
3 | ### Bug Fixes
4 |
5 | - Fix an issue where expired Twitch tokens are not correctly refreshed.
6 |
7 | ### Miscellaneous
8 |
9 | - Removed Mixer support, since Mixer is no longer.
10 |
11 | ## v1.3.2 (2020-01-03)
12 |
13 | ### Bug Fixes
14 |
15 | - Horizontal scrollbars should no longer be shown in Firefox when many streams are live.
16 |
17 | ### Improvements
18 |
19 | - Mixer: Improved efficiency of querying for live streams data.
20 |
21 | ## v1.3.1 (2020-01-02)
22 |
23 | ### Bug Fixes
24 |
25 | - Resolved an issue where not every live Mixer stream would be reported if the account follows more than 100 streams.
26 |
27 | ### Improvements
28 |
29 | - Minor performance optimizations.
30 |
31 | ## v1.3.0 (2019-12-18)
32 |
33 | ### New Features
34 |
35 | - Added keyboard support to navigate stream list options using arrow keys, and select a stream using the Enter key.
36 |
37 | ### Improvements
38 |
39 | - Tooltips will appear when the associated button has keyboard focus (e.g. the Settings button).
40 | - Increase contrast of hovered/focused buttons in light theme, for more identifiable keyboard selection.
41 |
42 | ## v1.2.0 (2019-12-17)
43 |
44 | ### New Features
45 |
46 | - Add new Color Scheme setting to override use of light or dark theme.
47 | - The stream list now includes a search field to filter by stream or activity name.
48 | - The stream popup includes a button to quickly navigate to the extension settings.
49 |
50 | ### Bug Fixes
51 |
52 | - Fix issue where Twitch stream links could navigate incorrectly when the streamer's name includes spaces.
53 |
54 | ## v1.1.2 (2019-11-17)
55 |
56 | ### Bug Fixes
57 |
58 | - Resolve an issue where the "No Streams Live" popup would show shrunken in Chrome.
59 |
60 | ## v1.1.1 (2019-11-17)
61 |
62 | ### Bug Fixes
63 |
64 | - Resolve an issue where the "Getting Started" popup would show shrunken in Chrome.
65 |
66 | ## v1.1.0 (2019-11-17)
67 |
68 | ### New Features
69 |
70 | - Settings are now stored using browser cloud sync (if configured), so connections are automatically synced across all instances of the browser you are logged in to.
71 |
72 | ### Bug Fixes
73 |
74 | - Fixed errors which could occasionally occur in Firefox when adding or removing connections.
75 | - Horizontal scrollbars should no longer be shown in Firefox when many streams are live.
76 |
77 | ## v1.0.0 (2019-11-10)
78 |
79 | - Initial release
80 |
--------------------------------------------------------------------------------
/packages/components/tab-panels.tsx:
--------------------------------------------------------------------------------
1 | import { cloneElement, ComponentProps, VNode } from 'preact';
2 | import { useRef, useState } from 'preact/hooks';
3 | import { useDidUpdateEffect, useId } from '@streamlens/hooks';
4 | import type { JSX } from 'preact';
5 | import TabPanel from './tab-panel';
6 |
7 | interface TabPanelsProps {
8 | /**
9 | * Accessible label describing purpose of tabs.
10 | */
11 | label: string;
12 |
13 | /**
14 | * Tabs content.
15 | */
16 | children: VNode>[];
17 | }
18 |
19 | function TabPanels({ label, children }: TabPanelsProps) {
20 | const activeButtonRef = useRef(null as HTMLButtonElement | null);
21 | const [activeIndex, setActiveIndex] = useState(0);
22 | const id = useId('tab-panels');
23 | useDidUpdateEffect(() => activeButtonRef.current?.focus(), [activeIndex]);
24 |
25 | function onTabButtonKeyDown(event: JSX.TargetedKeyboardEvent) {
26 | let nextActiveIndex;
27 |
28 | switch (event.key) {
29 | case 'ArrowLeft':
30 | nextActiveIndex = activeIndex - 1;
31 | break;
32 |
33 | case 'ArrowRight':
34 | nextActiveIndex = activeIndex + 1;
35 | break;
36 |
37 | case 'Home':
38 | nextActiveIndex = 0;
39 | break;
40 |
41 | case 'End':
42 | nextActiveIndex = children.length - 1;
43 | break;
44 | }
45 |
46 | if (nextActiveIndex >= 0 && nextActiveIndex < children.length) {
47 | setActiveIndex(nextActiveIndex);
48 | }
49 | }
50 |
51 | return (
52 |
53 |
54 | {children.map((tab, index) => (
55 |
70 | ))}
71 |
72 | {children.map((tab, index) =>
73 | cloneElement(tab, {
74 | key: index,
75 | id: `${id}-tab-${index}`,
76 | labelId: `${id}-tab-button-${index}`,
77 | isActive: activeIndex === index,
78 | })
79 | )}
80 |
81 | );
82 | }
83 |
84 | export default TabPanels;
85 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "stream-lens",
3 | "private": true,
4 | "version": "1.3.2",
5 | "description": "Browser extension for displaying live stream status for Twitch",
6 | "workspaces": [
7 | "packages/**"
8 | ],
9 | "scripts": {
10 | "build": "esbuild background/index.js popup/index.jsx options/index.jsx --bundle --outdir=build --format=esm --minify",
11 | "dev": "esbuild background/index.js popup/index.jsx options/index.jsx --sourcemap --bundle --outdir=build --format=esm --sourcemap=inline --watch",
12 | "test": "npm run test:lint && npm run test:types && npm run test:unit",
13 | "clean": "rm -rf build",
14 | "prepare": "npm run clean && npm run build",
15 | "test:lint": "eslint .",
16 | "test:types": "tsc",
17 | "test:unit": "mocha '{background,options,packages,popup}/**/test/*'",
18 | "prebundle": "npm run prepare",
19 | "bundle": "npm-pack-zip"
20 | },
21 | "author": {
22 | "name": "Andrew Duthie",
23 | "email": "andrew@andrewduthie.com",
24 | "url": "https://andrewduthie.com"
25 | },
26 | "repository": {
27 | "type": "git",
28 | "url": "https://github.com/aduth/StreamLens.git"
29 | },
30 | "license": "GPL-3.0-or-later",
31 | "files": [
32 | "_locales",
33 | "build",
34 | "fonts",
35 | "images",
36 | "node_modules/webextension-polyfill/dist/browser-polyfill.js",
37 | "auth.js",
38 | "background.html",
39 | "common.css",
40 | "config.js",
41 | "manifest.json",
42 | "options.css",
43 | "options.html",
44 | "popup.css",
45 | "popup.html",
46 | "!.DS_Store",
47 | "!test"
48 | ],
49 | "dependencies": {
50 | "lodash-es": "^4.17.21",
51 | "preact": "^10.12.1",
52 | "unistore": "^3.5.2",
53 | "unistore-browser-sync": "^1.1.0",
54 | "webextension-polyfill": "^0.10.0"
55 | },
56 | "bundledDependencies": [
57 | "webextension-polyfill"
58 | ],
59 | "devDependencies": {
60 | "@aduth/eslint-config": "^4.4.1",
61 | "@testing-library/dom": "^8.20.0",
62 | "@testing-library/preact": "^3.2.3",
63 | "@types/chai": "^4.3.4",
64 | "@types/lodash-es": "^4.17.6",
65 | "@types/mocha": "^10.0.1",
66 | "@types/node": "^18.13.0",
67 | "@types/sinon": "^10.0.13",
68 | "@types/sinon-chai": "^3.2.9",
69 | "@typescript-eslint/eslint-plugin": "^5.51.0",
70 | "@typescript-eslint/parser": "^5.51.0",
71 | "chai": "^4.3.7",
72 | "esbuild": "^0.17.7",
73 | "esbuild-esm-loader": "^0.3.0",
74 | "eslint": "^8.34.0",
75 | "eslint-config-prettier": "^8.6.0",
76 | "eslint-plugin-import": "^2.27.5",
77 | "eslint-plugin-prettier": "^4.2.1",
78 | "eslint-plugin-react": "^7.32.2",
79 | "mocha": "^10.2.0",
80 | "npm-pack-zip": "^1.3.0",
81 | "prettier": "^2.8.4",
82 | "sinon": "^15.0.1",
83 | "sinon-chai": "^3.7.0",
84 | "typescript": "^4.9.5",
85 | "undom": "^0.4.0",
86 | "web-ext-types": "^3.2.1"
87 | }
88 | }
89 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | StreamLens
6 |
7 | StreamLens is a browser extension that helps you follow your favorite streamers across multiple supported streaming platforms. Easily connect your [Twitch](https://www.twitch.tv/) account to import your followed streams automatically. The StreamLens toolbar button provides you with an at-a-glance count of live broadcasts and, when clicked, expands to show a list of streamers from which you can choose to start watching.
8 |
9 | 
10 |
11 | ## Installation
12 |
13 | Install the extension for free from the Chrome or Firefox extension marketplace:
14 |
15 | [
](https://chrome.google.com/webstore/detail/streamlens/fofbdnkkalkhbbkegbjgaokjlplooifg) [
](https://addons.mozilla.org/en-US/firefox/addon/streamlens/)
16 |
17 | ## Usage
18 |
19 | 1. After installing the extension, the StreamLens button should be visible in your browser toolbar.
20 |
21 | 
22 |
23 | 2. Clicking the button should reveal the live streams panel. Since you haven't yet connected any accounts, click the "Connect Accounts" button to proceed to the extension settings page.
24 |
25 | 
26 |
27 | 3. On the settings page, choose among the available supported platforms to link an account.
28 |
29 | 
30 |
31 | 4. After connecting one or more accounts, the toolbar button and corresponding popup will immediately update to show your followed streams currently live (if any).
32 |
33 | 
34 |
35 | ## License
36 |
37 | Copyright 2019 Andrew Duthie
38 |
39 | Released under the GPLv3 License. See [LICENSE.md](./LICENSE.md).
40 |
--------------------------------------------------------------------------------
/background/store.ts:
--------------------------------------------------------------------------------
1 | import { Store } from 'unistore';
2 | import { getPersistedState } from './components/persistence';
3 |
4 | /**
5 | * Stream details object.
6 | */
7 | export type SLStream = {
8 | /**
9 | * Username of streamer.
10 | */
11 | login: string;
12 |
13 | /**
14 | * Unique stream URI.
15 | */
16 | url: string;
17 |
18 | /**
19 | * Platform provider on which stream is hosted.
20 | */
21 | providerName: string;
22 |
23 | /**
24 | * Current stream title.
25 | */
26 | title: string;
27 |
28 | /**
29 | * Avatar image URL.
30 | */
31 | avatar?: string;
32 |
33 | /**
34 | * Active viewers for stream, if live.
35 | */
36 | viewers: number;
37 |
38 | /**
39 | * Current game or activity, if live.
40 | */
41 | activity?: string;
42 | };
43 |
44 | /**
45 | * Store stream state shape.
46 | */
47 | export type SLStreamState = {
48 | /**
49 | * User followed streams.
50 | */
51 | data: SLStream[];
52 |
53 | /**
54 | * Time of last received data, per provider name key.
55 | */
56 | lastReceived: {
57 | [provider: string]: number;
58 | };
59 | };
60 |
61 | /**
62 | * Provider user details.
63 | */
64 | export type SLProviderUser = {
65 | /**
66 | * User login.
67 | */
68 | login: string;
69 |
70 | /**
71 | * User ID;
72 | */
73 | id?: string | number;
74 | };
75 |
76 | /**
77 | * Provider authorization details.
78 | */
79 | export type SLAuth = {
80 | /**
81 | * Current authorization token, or null if the token has become invalid.
82 | */
83 | token: string | null;
84 |
85 | /**
86 | * Provider user details.
87 | */
88 | user: SLProviderUser;
89 | };
90 |
91 | /**
92 | * Store auth state shape.
93 | */
94 | export type SLAuthState = {
95 | [provider: string]: SLAuth;
96 | };
97 |
98 | /**
99 | * Store provider names state shape.
100 | */
101 | export type SLProviderNamesState = string[];
102 |
103 | /**
104 | * Store preferences state shape.
105 | */
106 | export type SLPreferencesState = {
107 | /**
108 | * Preferred color scheme.
109 | */
110 | colorScheme: 'dark' | 'light' | null;
111 | };
112 |
113 | /**
114 | * Store state shape.
115 | */
116 | export type SLState = {
117 | /**
118 | * Stream state.
119 | */
120 | streams: SLStreamState;
121 |
122 | /**
123 | * Provider authorizations, keyed by platform name.
124 | */
125 | auth: SLAuthState;
126 |
127 | /**
128 | * Registered providers names.
129 | */
130 | providerNames: SLProviderNamesState;
131 |
132 | /**
133 | * User preferences.
134 | */
135 | preferences: SLPreferencesState;
136 |
137 | /**
138 | * Whether network connectivity is available.
139 | */
140 | isOnline: boolean;
141 | };
142 |
143 | export type SLStore = Store;
144 |
145 | /**
146 | * Default store state.
147 | */
148 | export const DEFAULT_STATE: SLState = {
149 | providerNames: [],
150 | streams: {
151 | data: [],
152 | lastReceived: {},
153 | },
154 | auth: {},
155 | preferences: {
156 | colorScheme: null,
157 | },
158 | isOnline: globalThis.navigator?.onLine,
159 | };
160 |
161 | /**
162 | * Returns a promise resolving with initial store state.
163 | */
164 | export async function getInitialState(): Promise {
165 | // Merge provided initial state (e.g. from persistence) with default.
166 | return {
167 | ...DEFAULT_STATE,
168 | ...(await getPersistedState()),
169 | };
170 | }
171 |
--------------------------------------------------------------------------------
/packages/components/icon.tsx:
--------------------------------------------------------------------------------
1 | /**
2 | * Icon details.
3 | */
4 | interface SLIconDetails {
5 | /**
6 | * Width to assign in SVG `viewBox` attribute.
7 | */
8 | viewBoxWidth?: number;
9 |
10 | /**
11 | * SVG Path element `d` attribute.
12 | */
13 | path: string;
14 | }
15 |
16 | /**
17 | * Icon component props.
18 | */
19 | export interface IconProps {
20 | /**
21 | * Icon slug.
22 | */
23 | icon: string;
24 |
25 | /**
26 | * Optional explicit width.
27 | */
28 | width?: string;
29 |
30 | /**
31 | * Optional explicit height.
32 | */
33 | height?: string;
34 |
35 | /**
36 | * Optional additional class name.
37 | */
38 | className?: string;
39 | }
40 |
41 | /**
42 | * Icon details, keyed by icon slug.
43 | */
44 | const ICONS: Record = {
45 | alert: {
46 | viewBoxWidth: 576,
47 | path: 'M569.517 440.013C587.975 472.007 564.806 512 527.94 512H48.054c-36.937 0-59.999-40.055-41.577-71.987L246.423 23.985c18.467-32.009 64.72-31.951 83.154 0l239.94 416.028zM288 354c-25.405 0-46 20.595-46 46s20.595 46 46 46 46-20.595 46-46-20.595-46-46-46zm-43.673-165.346l7.418 136c.347 6.364 5.609 11.346 11.982 11.346h48.546c6.373 0 11.635-4.982 11.982-11.346l7.418-136c.375-6.874-5.098-12.654-11.982-12.654h-63.383c-6.884 0-12.356 5.78-11.981 12.654z',
48 | },
49 | video: {
50 | viewBoxWidth: 576,
51 | path: 'M336.2 64H47.8C21.4 64 0 85.4 0 111.8v288.4C0 426.6 21.4 448 47.8 448h288.4c26.4 0 47.8-21.4 47.8-47.8V111.8c0-26.4-21.4-47.8-47.8-47.8zm189.4 37.7L416 177.3v157.4l109.6 75.5c21.2 14.6 50.4-.3 50.4-25.8V127.5c0-25.4-29.1-40.4-50.4-25.8z',
52 | },
53 | 'video-slash': {
54 | viewBoxWidth: 640,
55 | path: 'M633.8 458.1l-55-42.5c15.4-1.4 29.2-13.7 29.2-31.1v-257c0-25.5-29.1-40.4-50.4-25.8L448 177.3v137.2l-32-24.7v-178c0-26.4-21.4-47.8-47.8-47.8H123.9L45.5 3.4C38.5-2 28.5-.8 23 6.2L3.4 31.4c-5.4 7-4.2 17 2.8 22.4L42.7 82 416 370.6l178.5 138c7 5.4 17 4.2 22.5-2.8l19.6-25.3c5.5-6.9 4.2-17-2.8-22.4zM32 400.2c0 26.4 21.4 47.8 47.8 47.8h288.4c11.2 0 21.4-4 29.6-10.5L32 154.7v245.5z',
56 | },
57 | cog: {
58 | path: 'M487.4 315.7l-42.6-24.6c4.3-23.2 4.3-47 0-70.2l42.6-24.6c4.9-2.8 7.1-8.6 5.5-14-11.1-35.6-30-67.8-54.7-94.6-3.8-4.1-10-5.1-14.8-2.3L380.8 110c-17.9-15.4-38.5-27.3-60.8-35.1V25.8c0-5.6-3.9-10.5-9.4-11.7-36.7-8.2-74.3-7.8-109.2 0-5.5 1.2-9.4 6.1-9.4 11.7V75c-22.2 7.9-42.8 19.8-60.8 35.1L88.7 85.5c-4.9-2.8-11-1.9-14.8 2.3-24.7 26.7-43.6 58.9-54.7 94.6-1.7 5.4.6 11.2 5.5 14L67.3 221c-4.3 23.2-4.3 47 0 70.2l-42.6 24.6c-4.9 2.8-7.1 8.6-5.5 14 11.1 35.6 30 67.8 54.7 94.6 3.8 4.1 10 5.1 14.8 2.3l42.6-24.6c17.9 15.4 38.5 27.3 60.8 35.1v49.2c0 5.6 3.9 10.5 9.4 11.7 36.7 8.2 74.3 7.8 109.2 0 5.5-1.2 9.4-6.1 9.4-11.7v-49.2c22.2-7.9 42.8-19.8 60.8-35.1l42.6 24.6c4.9 2.8 11 1.9 14.8-2.3 24.7-26.7 43.6-58.9 54.7-94.6 1.5-5.5-.7-11.3-5.6-14.1zM256 336c-44.1 0-80-35.9-80-80s35.9-80 80-80 80 35.9 80 80-35.9 80-80 80z',
59 | },
60 | wifi: {
61 | viewBoxWidth: 640,
62 | path: 'M634.91 154.88C457.74-8.99 182.19-8.93 5.09 154.88c-6.66 6.16-6.79 16.59-.35 22.98l34.24 33.97c6.14 6.1 16.02 6.23 22.4.38 145.92-133.68 371.3-133.71 517.25 0 6.38 5.85 16.26 5.71 22.4-.38l34.24-33.97c6.43-6.39 6.3-16.82-.36-22.98zM320 352c-35.35 0-64 28.65-64 64s28.65 64 64 64 64-28.65 64-64-28.65-64-64-64zm202.67-83.59c-115.26-101.93-290.21-101.82-405.34 0-6.9 6.1-7.12 16.69-.57 23.15l34.44 33.99c6 5.92 15.66 6.32 22.05.8 83.95-72.57 209.74-72.41 293.49 0 6.39 5.52 16.05 5.13 22.05-.8l34.44-33.99c6.56-6.46 6.33-17.06-.56-23.15z',
63 | },
64 | };
65 |
66 | /**
67 | * Returns an Icon element.
68 | */
69 | function Icon({ icon, width, height, className }: IconProps) {
70 | const { viewBoxWidth = 512, path } = ICONS[icon];
71 | const classes = ['icon', className].filter(Boolean).join(' ');
72 |
73 | return (
74 |
84 |
85 |
86 | );
87 | }
88 |
89 | export default Icon;
90 |
--------------------------------------------------------------------------------
/background/components/test/badge.tsx:
--------------------------------------------------------------------------------
1 | import { render } from '@testing-library/preact';
2 | import { StoreContext } from '@streamlens/state';
3 | import { useStubbedGlobal } from '@streamlens/stub-global';
4 | import { expect } from 'chai';
5 | import createStore from 'unistore';
6 | import { SyncStore } from 'unistore-browser-sync';
7 | import Badge, { Colors } from '../badge';
8 | import { SLState, SLStream, DEFAULT_STATE } from '../../store';
9 |
10 | describe('Badge', () => {
11 | useStubbedGlobal('browser.browserAction.setBadgeText');
12 | useStubbedGlobal('browser.browserAction.setBadgeBackgroundColor');
13 |
14 | function renderWithState(state: Partial) {
15 | const store = createStore({ ...DEFAULT_STATE, ...state }) as SyncStore;
16 | return render(, {
17 | wrapper({ children }) {
18 | return ;
19 | },
20 | });
21 | }
22 |
23 | context('offline', () => {
24 | it('sets error state', () => {
25 | renderWithState({ isOnline: false });
26 |
27 | expect(browser.browserAction.setBadgeText).to.have.been.calledWith({ text: '?' });
28 | expect(browser.browserAction.setBadgeBackgroundColor).to.have.been.calledWith({
29 | color: Colors.ERROR,
30 | });
31 | });
32 |
33 | it('sets error state after going offline', () => {
34 | const { rerender } = renderWithState({ isOnline: true });
35 | rerender({ isOnline: false });
36 |
37 | expect(browser.browserAction.setBadgeText).to.have.been.calledWith({ text: '?' });
38 | expect(browser.browserAction.setBadgeBackgroundColor).to.have.been.calledWith({
39 | color: Colors.ERROR,
40 | });
41 | });
42 |
43 | it('sets default state after coming offline', () => {
44 | const { rerender } = renderWithState({ isOnline: false });
45 | rerender({ isOnline: false });
46 |
47 | expect(browser.browserAction.setBadgeText).to.have.been.calledWith({ text: '' });
48 | expect(browser.browserAction.setBadgeBackgroundColor).to.have.been.calledWith({
49 | color: Colors.DEFAULT,
50 | });
51 | });
52 | });
53 |
54 | context('error token', () => {
55 | it('sets error state', () => {
56 | renderWithState({ auth: { twitch: { token: null, user: { login: '' } } }, isOnline: true });
57 |
58 | expect(browser.browserAction.setBadgeText).to.have.been.calledWith({ text: '?' });
59 | expect(browser.browserAction.setBadgeBackgroundColor).to.have.been.calledWith({
60 | color: Colors.ERROR,
61 | });
62 | });
63 | });
64 |
65 | context('without initial fetch', () => {
66 | it('sets empty text', () => {
67 | renderWithState({ auth: { twitch: { token: '', user: { login: '' } } }, isOnline: true });
68 |
69 | expect(browser.browserAction.setBadgeText).to.have.been.calledWith({ text: '' });
70 | expect(browser.browserAction.setBadgeBackgroundColor).to.have.been.calledWith({
71 | color: Colors.DEFAULT,
72 | });
73 | });
74 | });
75 |
76 | context('with fetched data', () => {
77 | it('sets stream count', () => {
78 | renderWithState({
79 | auth: { twitch: { token: '', user: { login: '' } } },
80 | streams: {
81 | data: [{} as SLStream, {} as SLStream],
82 | lastReceived: {
83 | twitch: Date.now(),
84 | },
85 | },
86 | isOnline: true,
87 | });
88 |
89 | expect(browser.browserAction.setBadgeText).to.have.been.calledWith({ text: '2' });
90 | expect(browser.browserAction.setBadgeBackgroundColor).to.have.been.calledWith({
91 | color: Colors.DEFAULT,
92 | });
93 | });
94 |
95 | it('sets zero count', () => {
96 | renderWithState({
97 | auth: { twitch: { token: '', user: { login: '' } } },
98 | streams: {
99 | data: [],
100 | lastReceived: {
101 | twitch: Date.now(),
102 | },
103 | },
104 | isOnline: true,
105 | });
106 |
107 | expect(browser.browserAction.setBadgeText).to.have.been.calledWith({ text: '0' });
108 | expect(browser.browserAction.setBadgeBackgroundColor).to.have.been.calledWith({
109 | color: Colors.DEFAULT,
110 | });
111 | });
112 | });
113 | });
114 |
--------------------------------------------------------------------------------
/popup.css:
--------------------------------------------------------------------------------
1 | /*
2 | * Explicit widths for popup contents
3 | */
4 |
5 | .card,
6 | .loading-indicator {
7 | width: 360px;
8 | }
9 |
10 | .stream-list {
11 | /*
12 | * Must be assigned as a maximum width, and rely on intrinsic width of its
13 | * inner content. Setting an explicit width would cause horizontal overflow
14 | * in Firefox.
15 | *
16 | * See: https://bugzilla.mozilla.org/show_bug.cgi?id=1395025
17 | */
18 | max-width: 360px;
19 | }
20 |
21 | /*
22 | * Toolbar
23 | */
24 |
25 | .toolbar {
26 | position: sticky;
27 | top: 0;
28 | z-index: 1;
29 | display: flex;
30 | border-bottom: 1px solid var(--sl-border-color);
31 | }
32 |
33 | .toolbar__search {
34 | flex-basis: 100%;
35 | }
36 |
37 | .toolbar__controls {
38 | position: relative;
39 | background: var(--sl-button-background-color);
40 | flex-shrink: 0;
41 | border-left: 1px solid var(--sl-border-color);
42 | }
43 |
44 | .toolbar__controls .icon-button {
45 | padding: 6px 4px;
46 | }
47 |
48 | .toolbar__controls .icon-button:active {
49 | background-color: var(--sl-button-background-color-active);
50 | }
51 |
52 | .toolbar__controls .icon-button:focus {
53 | background-color: var(--sl-button-background-color-focus);
54 | }
55 |
56 | .toolbar__controls .icon-button:first-child {
57 | padding-left: 8px;
58 | }
59 |
60 | .toolbar__controls .icon-button:last-child {
61 | padding-right: 8px;
62 | }
63 |
64 | .toolbar__search-input {
65 | display: block;
66 | width: 100%;
67 | padding: 7px 9px;
68 | border: none;
69 | border-radius: 0;
70 | font-size: 0.8rem;
71 | color: var(--sl-font-color);
72 | }
73 |
74 | .toolbar__search-input::placeholder {
75 | opacity: 0.7;
76 | color: var(--sl-font-color-faded);
77 | }
78 |
79 | .toolbar__search-input:focus {
80 | outline: none;
81 | }
82 |
83 | /*
84 | * Stream List
85 | */
86 |
87 | .stream-list__list {
88 | list-style-type: none;
89 | margin: 0;
90 | padding-left: 0;
91 | }
92 |
93 | /*
94 | * Token Errors
95 | */
96 |
97 | .token-errors.notice {
98 | margin: 0;
99 | border-width: 0;
100 | border-bottom-width: 1px;
101 | }
102 |
103 | /*
104 | * Stream
105 | */
106 |
107 | .stream {
108 | display: flex;
109 | align-items: center;
110 | padding: 8px;
111 | color: currentColor;
112 | border-bottom: 1px solid var(--sl-border-color);
113 | }
114 |
115 | .stream-list__item:last-child .stream {
116 | border-bottom-width: 0;
117 | }
118 |
119 | .stream-list__item.is-hovered .stream {
120 | background-color: var(--sl-button-background-color-focus);
121 | }
122 |
123 | .stream:focus {
124 | outline: none;
125 | }
126 |
127 | .stream:active {
128 | background-color: var(--sl-button-background-color-active);
129 | }
130 |
131 | .stream__avatar-provider {
132 | position: relative;
133 | flex-shrink: 0;
134 | width: 40px;
135 | margin-right: 8px;
136 | padding: 4px;
137 | }
138 |
139 | .stream__avatar {
140 | display: block;
141 | width: 100%;
142 | border-radius: 50%;
143 | }
144 |
145 | .stream__provider {
146 | position: absolute;
147 | top: 0;
148 | left: 0;
149 | }
150 |
151 | .stream__login-activity {
152 | display: flex;
153 | flex-direction: column;
154 | flex-grow: 1;
155 | flex-shrink: 1;
156 | /*
157 | * The explicit width should be enough to occupy the fullest possible width
158 | * of the stream list, relying on flex resizing to shrink as necessary. An
159 | * alternative could be to assign a width such that the sum total of the
160 | * stream item would occupy the same width as the stream list maximum, but
161 | * considering that the viewer count can fluctuate the width of its label,
162 | * this is not deterministic.
163 | */
164 | width: 360px;
165 | }
166 |
167 | .stream__login {
168 | font-weight: bold;
169 | }
170 |
171 | .stream__activity {
172 | font-size: 0.8rem;
173 | color: var(--sl-font-color-faded);
174 | }
175 |
176 | .stream__viewers {
177 | display: flex;
178 | margin-left: 8px;
179 | align-items: center;
180 | flex-shrink: 0;
181 | align-self: flex-start;
182 | font-size: 0.8rem;
183 | color: var(--sl-font-color-faded);
184 | }
185 |
186 | .stream__viewers::before {
187 | content: '';
188 | width: 8px;
189 | height: 8px;
190 | margin-right: 4px;
191 | border-radius: 50%;
192 | background-color: #e91916;
193 | }
194 |
--------------------------------------------------------------------------------
/background/store/actions.ts:
--------------------------------------------------------------------------------
1 | import { omit, reject } from 'lodash-es';
2 | import { applications } from '../../config';
3 | import { launchOAuthFlow } from '../oauth';
4 | import { providers } from '../providers';
5 | import { SLState, SLStream, SLPreferencesState } from '../store';
6 |
7 | /**
8 | * Registers a new provider.
9 | *
10 | * @param state Current state.
11 | * @param name Provider name.
12 | */
13 | export function registerProviderName(state: SLState, name: string): Partial {
14 | return {
15 | providerNames: [...new Set([...state.providerNames, name])],
16 | };
17 | }
18 |
19 | /**
20 | * Resets the current live streams for a provider to the given set.
21 | *
22 | * @param state Current state.
23 | * @param providerName Provider name.
24 | * @param streams Live stream objects.
25 | * @param receivedAt Time at which receive should be recorded as having occurred (defaults to now).
26 | *
27 | * @return State patch object.
28 | */
29 | export function updateStreams(
30 | state: SLState,
31 | providerName: string,
32 | streams: SLStream[],
33 | receivedAt: number = Date.now()
34 | ): Partial {
35 | return {
36 | streams: {
37 | data: [...reject(state.streams.data, { providerName }), ...streams].sort(
38 | (a, b) => b.viewers - a.viewers
39 | ),
40 | lastReceived: {
41 | ...state.streams.lastReceived,
42 | [providerName]: receivedAt,
43 | },
44 | },
45 | };
46 | }
47 |
48 | /**
49 | * Launches authorization flow for a given provider.
50 | *
51 | * @param state Current state.
52 | * @param providerName Name of provider to authenticate.
53 | *
54 | * @return State patch object.
55 | */
56 | export async function authenticate(
57 | state: SLState,
58 | providerName: string
59 | ): Promise> {
60 | if (!providers.hasOwnProperty(providerName)) {
61 | return {};
62 | }
63 |
64 | const { clientId } = applications[providerName];
65 | const { authEndpoint, getUser } = providers[providerName];
66 |
67 | const token = await launchOAuthFlow({
68 | authEndpoint,
69 | interactive: true,
70 | params: { clientId },
71 | });
72 |
73 | if (!token) {
74 | return {};
75 | }
76 |
77 | let user;
78 | try {
79 | user = await getUser(token);
80 | } catch (error) {
81 | return {};
82 | }
83 |
84 | return {
85 | auth: {
86 | ...state.auth,
87 | [providerName]: { token, user },
88 | },
89 | };
90 | }
91 |
92 | /**
93 | * Removes current authentication details for a given provider.
94 | *
95 | * @param state Current state.
96 | * @param providerName Name of provider to deauthenticate.
97 | *
98 | * @return State patch object.
99 | */
100 | export function deauthenticate(state: SLState, providerName: string): Partial {
101 | return {
102 | streams: {
103 | data: reject(state.streams.data, { providerName }),
104 | lastReceived: omit(state.streams.lastReceived, providerName),
105 | },
106 | auth: omit(state.auth, providerName),
107 | };
108 | }
109 |
110 | /**
111 | * Marks token as invalid for provider.
112 | *
113 | * @param state Current state.
114 | * @param providerName Name of provider on which token error occurred.
115 | *
116 | * @return State patch object.
117 | */
118 | export async function setTokenError(
119 | state: SLState,
120 | providerName: string
121 | ): Promise> {
122 | const { clientId } = applications[providerName];
123 | const { authEndpoint, supportsOIDC } = providers[providerName];
124 |
125 | let nextToken;
126 | if (supportsOIDC) {
127 | // If the provider supports OpenID Connect, an attempt can be made to
128 | // silently refresh the authorization token via the `prompt` parameter.
129 | nextToken = await launchOAuthFlow({
130 | authEndpoint,
131 | params: { clientId },
132 | });
133 | }
134 |
135 | return {
136 | streams: deauthenticate(state, providerName).streams,
137 | auth: {
138 | ...state.auth,
139 | [providerName]: {
140 | ...state.auth[providerName],
141 | token: nextToken || null,
142 | },
143 | },
144 | };
145 | }
146 |
147 | /**
148 | * Marks token as invalid for provider.
149 | *
150 | * @param state Current state.
151 | * @param preferences Preferences to update.
152 | *
153 | * @return State patch object.
154 | */
155 | export function setPreferences(
156 | state: SLState,
157 | preferences: Partial
158 | ): Partial {
159 | return {
160 | preferences: {
161 | ...state.preferences,
162 | ...preferences,
163 | },
164 | };
165 | }
166 |
167 | /**
168 | * Toggle online status, defaulting to inverse of current state.
169 | *
170 | * @param state Current state.
171 | * @param isOnline Whether online.
172 | *
173 | * @return State patch object.
174 | */
175 | export function toggleIsOnline(state: SLState, isOnline = !state.isOnline): Partial {
176 | return {
177 | isOnline,
178 | };
179 | }
180 |
--------------------------------------------------------------------------------
/_locales/en/messages.json:
--------------------------------------------------------------------------------
1 | {
2 | "extDescription": {
3 | "message": "Live status updates for your followed streams on Twitch",
4 | "description": "Extension description"
5 | },
6 | "commonLoadingIndicatorLabel": {
7 | "message": "Loading",
8 | "description": "Status label for loading indicator"
9 | },
10 | "optionsProviderSettingsTitle": {
11 | "message": "Platform Settings",
12 | "description": "Title for Options page Provider Settings section"
13 | },
14 | "optionsProviderSettingsDescription": {
15 | "message": "Configure stream settings for each of the supported platforms listed below.",
16 | "description": "Description for Options page Provider Settings section"
17 | },
18 | "optionsSettingsProvidersTabsLabel": {
19 | "message": "Providers",
20 | "description": "Accessible label for provider settings tab panel"
21 | },
22 | "optionsAuthorizationLogin": {
23 | "message": "Currently connected as:",
24 | "description": "Active authorization login label"
25 | },
26 | "optionsAuthorizationConnect": {
27 | "message": "Connect Account",
28 | "description": "Button label for provider authorization action"
29 | },
30 | "optionsAuthorizationDisconnect": {
31 | "message": "Disconnect",
32 | "description": "Button label for provider deauthorization action"
33 | },
34 | "optionsColorSchemeTitle": {
35 | "message": "Color Scheme",
36 | "description": "Title for Options page Color Scheme section"
37 | },
38 | "optionsColorSchemeDescription": {
39 | "message": "By default, the StreamLens popup is themed to match your configured system preference. Use this setting to always use light or dark theme instead.",
40 | "description": "Description for Options page Color Scheme section"
41 | },
42 | "optionsColorSchemeInherit": {
43 | "message": "Use system default",
44 | "description": "Option label for color scheme inherit system setting"
45 | },
46 | "optionsColorSchemeLight": {
47 | "message": "Light theme",
48 | "description": "Option label for color scheme light theme"
49 | },
50 | "optionsColorSchemeDark": {
51 | "message": "Dark theme",
52 | "description": "Option label for color scheme dark theme"
53 | },
54 | "popupGettingStartedWelcome": {
55 | "message": "Welcome to StreamLens!",
56 | "description": "Welcome message title for new users"
57 | },
58 | "popupGettingStartedSettings": {
59 | "message": "Open Settings",
60 | "description": "Welcome message button text for open settings action"
61 | },
62 | "popupGettingStartedDescription": {
63 | "message": "To get started, connect one or more accounts to import your followed streams.",
64 | "description": "Welcome message description text for next steps"
65 | },
66 | "popupNoStreamsLiveTitle": {
67 | "message": "No Streams Live",
68 | "description": "Empty streams panel title"
69 | },
70 | "popupNoStreamsLiveDescription": {
71 | "message": "Can't get enough? Consider following more streams to see more content here.",
72 | "description": "Empty streams panel description"
73 | },
74 | "popupNoSearchResultsTitle": {
75 | "message": "No Results Found",
76 | "description": "Streams empty search result panel title"
77 | },
78 | "popupNoSearchResultsDescription": {
79 | "message": "Try a different search. Search by streamer name, game, or stream title.",
80 | "description": "Streams empty search result panel description"
81 | },
82 | "popupOfflineWarningTitle": {
83 | "message": "Offline",
84 | "description": "Popup offline warning title"
85 | },
86 | "popupOfflineWarningDescription": {
87 | "message": "Connect to the internet to see who's live.",
88 | "description": "Popup offline warning description"
89 | },
90 | "popupStreamLinkAccessibleLabel": {
91 | "message": "$streamer$ is streaming $activity$ for $viewers$ viewers",
92 | "description": "Label used to describe stream status to assistive technologies",
93 | "placeholders": {
94 | "streamer": {
95 | "content": "$1",
96 | "example": "Shroud"
97 | },
98 | "activity": {
99 | "content": "$2",
100 | "example": "Call of Duty: Modern Warfare"
101 | },
102 | "viewers": {
103 | "content": "$3",
104 | "example": "18408"
105 | }
106 | }
107 | },
108 | "popupToolbarSearchLabel": {
109 | "message": "Search by game or stream name",
110 | "description": "Message describing popup stream search input"
111 | },
112 | "popupToolbarSettings": {
113 | "message": "Settings",
114 | "description": "Popup settings button tooltip"
115 | },
116 | "providerTokenError": {
117 | "message": "There's an issue connecting to $providerLabel$",
118 | "description": "Label used to indicate an error with a provider authorization",
119 | "placeholders": {
120 | "providerLabel": {
121 | "content": "$1",
122 | "example": "Twitch"
123 | }
124 | }
125 | },
126 | "providerTokenErrorFix": {
127 | "message": "Fix",
128 | "description": "Button label for provider authorization error fix action"
129 | }
130 | }
131 |
--------------------------------------------------------------------------------
/popup/components/stream-list.tsx:
--------------------------------------------------------------------------------
1 | import { size, reject, deburr, clamp } from 'lodash-es';
2 | import { useContext, useState, useRef } from 'preact/hooks';
3 | import { LoadingIndicator } from '@streamlens/components';
4 | import { useSelect } from '@streamlens/state';
5 | import Stream from './stream';
6 | import Toolbar from './toolbar';
7 | import NoStreamsLive from './no-streams-live';
8 | import NoSearchResults from './no-search-results';
9 | import { SearchContext } from './search-context';
10 | import { SLStream } from '/background/store';
11 |
12 | /**
13 | * Returns a term normnalized for search comparison. Normalization includes
14 | * diacritical marks and case, collapses whitespace, and removes common
15 | * punctuation.
16 | *
17 | * @param term Original term.
18 | *
19 | * @return Normalized term.
20 | */
21 | function getNormalSearchTerm(term: string): string {
22 | return deburr(term)
23 | .toLocaleLowerCase()
24 | .replace(/\s+/, ' ')
25 | .replace(/[!"#$%&'()*+,-./:;<=>?@[\]^_`{|}~]/g, '');
26 | }
27 |
28 | /**
29 | * Returns true if the haystack candidate term includes the given search needle,
30 | * or false otherwise. Performs a tolerant search, normalizing diacritical marks
31 | * and case, collapsing whitespace, and removing most punctuation.
32 | *
33 | * @param needle Search term.
34 | * @param haystack Candidate term.
35 | *
36 | * @return Whether candidate includes search term.
37 | */
38 | export function isTolerantStringMatch(needle: string, haystack: string): boolean {
39 | return getNormalSearchTerm(haystack).includes(getNormalSearchTerm(needle));
40 | }
41 |
42 | /**
43 | * Returns true if the search term is a match for the given stream, or false
44 | * otherwise.
45 | *
46 | * @param search Search term.
47 | * @param stream Stream object to test.
48 | *
49 | * @return Whether stream is match for search term.
50 | */
51 | function isSearchMatch(search: string, stream: SLStream): boolean {
52 | return (
53 | !search ||
54 | (stream.activity && isTolerantStringMatch(search, stream.activity)) ||
55 | isTolerantStringMatch(search, stream.login) ||
56 | isTolerantStringMatch(search, stream.title)
57 | );
58 | }
59 |
60 | /**
61 | * Returns a Stream List element.
62 | */
63 | function StreamList() {
64 | const auth = useSelect((state) => state.auth);
65 | const streams = useSelect((state) => state.streams);
66 | const [search] = useContext(SearchContext);
67 | const [hoverIndex, setHoverIndex] = useState(null as number | null);
68 | const listRef = useRef(null as HTMLUListElement | null);
69 |
70 | const numberOfValidConnections = size(reject(auth, { token: null }));
71 | const hasFetched = size(streams.lastReceived) === numberOfValidConnections;
72 | if (hasFetched && streams.data.length === 0) {
73 | return ;
74 | }
75 |
76 | const filteredStreams = streams.data.filter(isSearchMatch.bind(null, search));
77 |
78 | // Ensure that if stream state updates or search filtering reduces the
79 | // number of streams shown, the hover index is effectively constrained to
80 | // the maximum number of streams.
81 | const effectiveHoverIndex =
82 | hoverIndex === null || filteredStreams.length === 0
83 | ? null
84 | : clamp(hoverIndex, filteredStreams.length - 1);
85 |
86 | /**
87 | * Returns the link element for the stream at a given zero-based index, or
88 | * null if it cannot be determined or does not exist. Ideally, this would
89 | * not pierce the abstraction of the Stream component and would instead be
90 | * implemented as agnostic to the focusable elements within a list.
91 | *
92 | * @param index Index
93 | *
94 | * @return Link element, if known.
95 | */
96 | function getStreamLink(index: number): HTMLElement | null {
97 | return listRef.current ? listRef.current.querySelector(`li:nth-child(${index + 1}) a`) : null;
98 | }
99 |
100 | /**
101 | * Interprets an intent to set hover index as a focus action if focus is
102 | * already within the stream list. This allows tab focus behavior to proceed
103 | * as expected after a hover index changes. If focus is not already within
104 | * the list, the default hover index behavior is used instead.
105 | *
106 | * @param index Intended hover index.
107 | */
108 | function setHoverIndexOrFocus(index: number) {
109 | const isFocusInList = listRef.current && listRef.current.contains(document.activeElement);
110 | if (isFocusInList) {
111 | const target = getStreamLink(index);
112 | if (target) {
113 | target.focus();
114 | }
115 | } else {
116 | setHoverIndex(index);
117 | }
118 | }
119 |
120 | /**
121 | * Interpets a key down to increment the hover index if key pressed is an
122 | * arrow key. This must occur in response to a `keydown` event, since
123 | * `keypress` events do not emit for arrow keys.
124 | *
125 | * @param event Key event.
126 | */
127 | function incrementHoverIndex(event: KeyboardEvent) {
128 | if (event.key === 'ArrowUp' || event.key === 'ArrowDown') {
129 | // Increment the hover index by an increment corresponding to the
130 | // key pressed. The hover index is clamped to be constrained to a
131 | // valid value based on the current number of filtered streams. The
132 | // effective hover index is used to assure that the change is most
133 | // accurate in respect to what is seen by the user.
134 | const increment = event.key === 'ArrowUp' ? -1 : 1;
135 | const nextHoverIndex =
136 | effectiveHoverIndex === null
137 | ? 0
138 | : clamp(effectiveHoverIndex + increment, 0, filteredStreams.length - 1);
139 |
140 | setHoverIndexOrFocus(nextHoverIndex);
141 |
142 | event.preventDefault();
143 | }
144 | }
145 |
146 | /**
147 | * Interpets a key press to select a stream if key pressed is an enter key.
148 | * This must occur in response to a `keypress` event, since popups created
149 | * during a `keydown` event would be blocked by Firefox popup blocker,
150 | * presumably because they're not considered an allowable user interaction.
151 | *
152 | * @param event Key event.
153 | */
154 | function selectStream(event: KeyboardEvent) {
155 | if (event.key === 'Enter') {
156 | event.preventDefault();
157 |
158 | if (effectiveHoverIndex !== null) {
159 | const stream = filteredStreams[effectiveHoverIndex];
160 | if (stream) {
161 | window.open(stream.url);
162 | window.close();
163 | }
164 | }
165 | }
166 | }
167 |
168 | return (
169 |
170 |
171 | {hasFetched && filteredStreams.length === 0 &&
}
172 |
173 | {filteredStreams.map((stream, index) => (
174 | - setHoverIndex(index)}
180 | onBlurCapture={() => setHoverIndex(null)}
181 | onMouseEnter={() => setHoverIndex(index)}
182 | onMouseLeave={() => setHoverIndex(null)}
183 | >
184 |
185 |
186 | ))}
187 |
188 | {!hasFetched &&
}
189 |
190 | );
191 | }
192 |
193 | export default StreamList;
194 |
--------------------------------------------------------------------------------
/background/oauth.ts:
--------------------------------------------------------------------------------
1 | import { snakeCase } from 'lodash-es';
2 | import { authRedirectURL } from '../config';
3 |
4 | /**
5 | * Suported authorization request parameters, values serving as defaults.
6 | *
7 | * @see https://tools.ietf.org/html/rfc6749#section-4.2.1
8 | * @see https://openid.net/specs/openid-connect-core-1_0.html#AuthRequest
9 | */
10 | interface SLOAuthParameters {
11 | /**
12 | * Client identifier.
13 | */
14 | clientId?: string;
15 |
16 | /**
17 | * Expected response type.
18 | */
19 | responseType?: string;
20 |
21 | /**
22 | * URL to which user should be redirected.
23 | */
24 | redirectURI?: string;
25 |
26 | /**
27 | * Scope(s) to request with authorization.
28 | */
29 | scope?: string;
30 |
31 | /**
32 | * Whether to issue interactive authorization.
33 | */
34 | prompt?: string;
35 |
36 | /**
37 | * Hint to server about login identifier.
38 | */
39 | loginHint?: string;
40 | }
41 |
42 | const PARAMETERS: SLOAuthParameters = {
43 | clientId: undefined,
44 | responseType: 'token',
45 | redirectURI: authRedirectURL,
46 | scope: undefined,
47 | prompt: undefined,
48 | loginHint: undefined,
49 | };
50 |
51 | /**
52 | * Width of interactive popup.
53 | */
54 | const POPUP_WIDTH = 520;
55 |
56 | /**
57 | * Height of interactive popup.
58 | */
59 | const POPUP_HEIGHT = 780;
60 |
61 | interface GetAuthURLOptions {
62 | /**
63 | * URL to which user should be redirected.
64 | */
65 | authEndpoint: string;
66 |
67 | /**
68 | * Additional parameters to include in authorization request.
69 | */
70 | params: SLOAuthParameters;
71 |
72 | /**
73 | * Whether to complete auth interactively vs. silent refresh.
74 | */
75 | interactive: boolean;
76 | }
77 |
78 | /**
79 | * Generates and returns OAuth authorization URL.
80 | *
81 | * @return Authorization URL.
82 | */
83 | function getAuthURL({ authEndpoint, params, interactive }: GetAuthURLOptions): string {
84 | const url = new URL(authEndpoint);
85 |
86 | for (const key in PARAMETERS) {
87 | // Assign value from constant as default.
88 | let value = PARAMETERS[key];
89 |
90 | // Defer to passed value.
91 | if (params.hasOwnProperty(key)) {
92 | value = params[key];
93 | }
94 |
95 | // Only set if defined.
96 | if (value !== undefined) {
97 | url.searchParams.set(snakeCase(key), value);
98 | }
99 | }
100 |
101 | // Generate nonce for CSRF protection, verified upon a received token.
102 | const nonce = getRandomString();
103 | url.searchParams.set('state', nonce);
104 |
105 | // Non-interactive is effected via `prompt` parameter.
106 | //
107 | // See: https://openid.net/specs/openid-connect-core-1_0.html#Authenticates
108 | if (!interactive) {
109 | url.searchParams.set('prompt', 'none');
110 | }
111 |
112 | return url.toString();
113 | }
114 |
115 | /**
116 | * Returns a character string of cryptographically-strong random values.
117 | *
118 | * @param length Length of string.
119 | *
120 | * @return Nonce string.
121 | */
122 | export function getRandomString(length = 32): string {
123 | return Array.from(crypto.getRandomValues(new Uint32Array(length)))
124 | .map((i) => i.toString(36).slice(-1))
125 | .join('');
126 | }
127 |
128 | interface LaunchOAuthFlowOptions {
129 | /**
130 | * URL to which user should be redirected.
131 | */
132 | authEndpoint: string;
133 |
134 | /**
135 | * Additional parameters to include in authorization request.
136 | */
137 | params?: SLOAuthParameters;
138 |
139 | /**
140 | * Whether to complete auth interactively vs. silent refresh.
141 | */
142 | interactive?: boolean;
143 | }
144 |
145 | /**
146 | * Launches OAuth authentication flow.
147 | *
148 | * @return Promise resolving to token if successful, `undefined` if declined, or `null` if failed
149 | * non-interactive refresh.
150 | */
151 | export function launchOAuthFlow({
152 | authEndpoint,
153 | params = {},
154 | interactive = false,
155 | }: LaunchOAuthFlowOptions): Promise {
156 | const url = getAuthURL({ authEndpoint, params, interactive });
157 |
158 | /**
159 | * Attempts to extract token from message if message is a URL with state,
160 | * access token parameters. Validates state to verify nonce match.
161 | *
162 | * @param message Browser message.
163 | *
164 | * @return Token, if extracted from message. A null value indicates a completed authorization
165 | * for which the token was omitted (denied).
166 | */
167 | function getTokenFromMessage(message: any): string | undefined | null {
168 | let hash;
169 | try {
170 | ({ hash } = new URL(message));
171 | } catch (error) {
172 | return;
173 | }
174 |
175 | const messageParams = new URLSearchParams(hash.slice(1));
176 | const nonce = new URLSearchParams(url).get('state');
177 |
178 | if (messageParams.get('state') === nonce) {
179 | // At this point, it can be certain that the message is the response
180 | // from the endpoint. It's not guaranteed that the access token is
181 | // present in the parameters (e.g. in case of error or denied
182 | // request), but since URLSearchParams#get will return `null` in
183 | // case of a missing value, the token can be differentiated between
184 | // `undefined` and `null` as indicating whether a response (valid or
185 | // not) was received.
186 | return messageParams.get('access_token');
187 | }
188 | }
189 |
190 | return interactive
191 | ? new Promise(async (resolve) => {
192 | const currentWindow = await browser.windows.getCurrent();
193 | const { left = 0, width = 0, top = 0, height = 0 } = currentWindow;
194 | const authWindow = await browser.windows.create({
195 | url,
196 | type: 'popup',
197 | width: POPUP_WIDTH,
198 | height: POPUP_HEIGHT,
199 | left: Math.floor(left + width / 2 - POPUP_WIDTH / 2),
200 | top: Math.floor(top + height / 2 - POPUP_HEIGHT / 2),
201 | });
202 |
203 | /**
204 | * Resolve with token, if received, and remove event listeners.
205 | *
206 | * @param token Token, if received.
207 | */
208 | function onAuthComplete(token: string | undefined | null) {
209 | browser.runtime.onMessage.removeListener(checkForToken);
210 | browser.windows.onRemoved.removeListener(onWindowClosed);
211 | resolve(token);
212 | }
213 |
214 | /**
215 | * Check browser message for received message, and complete
216 | * authorization if message originates from auth window.
217 | *
218 | * @param message Browser message.
219 | * @param sender Message sender.
220 | */
221 | function checkForToken(message: any, sender: browser.runtime.MessageSender) {
222 | const token = getTokenFromMessage(message);
223 | if (sender.tab && sender.tab.windowId === authWindow.id) {
224 | onAuthComplete(token);
225 | browser.windows.remove(authWindow.id);
226 | }
227 | }
228 |
229 | /**
230 | * Completes authorization if window is closed prematurely (users
231 | * closes prompt).
232 | *
233 | * @param windowId ID of window closed.
234 | */
235 | function onWindowClosed(windowId: number) {
236 | if (windowId === authWindow.id) {
237 | onAuthComplete(undefined);
238 | }
239 | }
240 |
241 | browser.windows.onRemoved.addListener(onWindowClosed);
242 | browser.runtime.onMessage.addListener(checkForToken);
243 | })
244 | : new Promise((resolve) => {
245 | const iframe = document.createElement('iframe');
246 | iframe.src = url;
247 |
248 | /**
249 | * Check browser message for received message, and complete
250 | * authorization if message originates from auth window.
251 | *
252 | * @param message Browser message.
253 | */
254 | function checkForToken(message: any) {
255 | const token = getTokenFromMessage(message);
256 |
257 | // See above note in `getTokenFromMessage`. A non-undefined
258 | // token, whether null or valid token, is indicative of the
259 | // completion of the authorization flow for this request.
260 | if (token !== undefined) {
261 | resolve(token);
262 | browser.runtime.onMessage.removeListener(checkForToken);
263 | document.body.removeChild(iframe);
264 | }
265 | }
266 |
267 | browser.runtime.onMessage.addListener(checkForToken);
268 | document.body.appendChild(iframe);
269 | });
270 | }
271 |
--------------------------------------------------------------------------------
/background/providers/twitch.ts:
--------------------------------------------------------------------------------
1 | /* eslint-disable camelcase */
2 |
3 | import { find, chunk } from 'lodash-es';
4 | import { applications } from '../../config';
5 | import { InvalidTokenError, SLProvider } from './';
6 | import { SLStream } from '../store';
7 |
8 | /**
9 | * Twitch token details, from validation endpoint.
10 | */
11 | interface TwitchTokenDetails {
12 | /**
13 | * Application client ID.
14 | */
15 | client_id: string;
16 |
17 | /**
18 | * Authorized user login.
19 | */
20 | login: string;
21 |
22 | /**
23 | * Requested scopes.
24 | */
25 | scopes: string[];
26 |
27 | /**
28 | * Authorized user ID.
29 | */
30 | user_id: string;
31 | }
32 |
33 | /**
34 | * Twitch `/follows` API entity.
35 | */
36 | interface TwitchFollow {
37 | /**
38 | * ID of the user following the `to_id` user.
39 | */
40 | from_id: string;
41 |
42 | /**
43 | * Display name corresponding to `from_id`.
44 | */
45 | from_name: string;
46 |
47 | /**
48 | * ID of the user being followed by the `from_id` user.
49 | */
50 | to_id: string;
51 |
52 | /**
53 | * Display name corresponding to `to_id`.
54 | */
55 | to_name: string;
56 |
57 | /**
58 | * Date and time when the from_id user followed the to_id user.
59 | */
60 | followed_at: string;
61 | }
62 |
63 | /**
64 | * Twitch `/games` API entity.
65 | */
66 | interface TwitchGame {
67 | /**
68 | * Template URL for the game’s box art.
69 | */
70 | box_art_url: string;
71 |
72 | /**
73 | * Game ID.
74 | */
75 | id: string;
76 |
77 | /**
78 | * Game name.
79 | */
80 | name: string;
81 | }
82 |
83 | /**
84 | * Twitch `/users` API entity.
85 | */
86 | interface TwitchUser {
87 | /**
88 | * User’s broadcaster type: "partner", "affiliate", or "".
89 | */
90 | broadcaster_type: string;
91 |
92 | /**
93 | * User’s channel description.
94 | */
95 | description: string;
96 |
97 | /**
98 | * User’s display name.
99 | */
100 | display_name: string;
101 |
102 | /**
103 | * User’s email address. Returned if the request includes the `user:read:email` scope.
104 | */
105 | email: string;
106 |
107 | /**
108 | * User’s ID.
109 | */
110 | id: string;
111 |
112 | /**
113 | * User’s login name.
114 | */
115 | login: string;
116 |
117 | /**
118 | * URL of the user’s offline image.
119 | */
120 | offline_image_url: string;
121 |
122 | /**
123 | * URL of the user’s profile image.
124 | */
125 | profile_image_url: string;
126 |
127 | /**
128 | * User’s type: "staff", "admin", "global_mod", or "".
129 | */
130 | type: string;
131 |
132 | /**
133 | * Total number of views of the user’s channel.
134 | */
135 | view_count: number;
136 | }
137 |
138 | /**
139 | * Twitch `/streams` API entity.
140 | */
141 | interface TwitchStream {
142 | /**
143 | * ID of the game being played on the stream.
144 | */
145 | game_id: string;
146 |
147 | /**
148 | * Stream ID.
149 | */
150 | id: string;
151 |
152 | /**
153 | * Stream language.
154 | */
155 | language: string;
156 |
157 | /**
158 | * UTC timestamp.
159 | */
160 | started_at: string;
161 |
162 | /**
163 | * Shows tag IDs that apply to the stream.
164 | */
165 | tag_ids: string;
166 |
167 | /**
168 | * Thumbnail URL of the stream. All image URLs have variable width and height. You can replace {width} and {height} with any values to get that size image.
169 | */
170 | thumbnail_url: string;
171 |
172 | /**
173 | * Stream title.
174 | */
175 | title: string;
176 |
177 | /**
178 | * Stream type: "live" or "" (in case of error).
179 | */
180 | type: string;
181 |
182 | /**
183 | * ID of the user who is streaming.
184 | */
185 | user_id: string;
186 |
187 | /**
188 | * Display name corresponding to user_id.
189 | */
190 | user_name: string;
191 |
192 | /**
193 | * Number of viewers watching the stream at the time of the query.
194 | */
195 | viewer_count: number;
196 | }
197 |
198 | /**
199 | * Twitch API pagination cursor.
200 | */
201 | type TwitchAPIPaginationCursor = string | undefined;
202 |
203 | /**
204 | * Twitch API response pagination details.
205 | */
206 | interface TwitchAPIPagination {
207 | /**
208 | * Pagination cursor ID, if a next page exists.
209 | */
210 | cursor?: TwitchAPIPaginationCursor;
211 | }
212 |
213 | /**
214 | * Twitch API response payload.
215 | */
216 | interface TwitchAPIResponse {
217 | /**
218 | * Response data.
219 | */
220 | data: T;
221 | }
222 |
223 | /**
224 | * Twitch API paginated response payload.
225 | */
226 | interface TwitchAPIPaginatedResponse extends TwitchAPIResponse {
227 | /**
228 | * Pagination data.
229 | */
230 | pagination: TwitchAPIPagination;
231 |
232 | /**
233 | * Total number of results.
234 | */
235 | total: number;
236 | }
237 |
238 | /**
239 | * Twitch base API URL.
240 | */
241 | const API_BASE = 'https://api.twitch.tv/helix';
242 |
243 | /**
244 | * Provider name.
245 | */
246 | const name = 'twitch';
247 |
248 | /**
249 | * Maximum number of entities to request per API page.
250 | */
251 | const MAX_PER_PAGE = 100;
252 |
253 | export default {
254 | name,
255 |
256 | authEndpoint: 'https://id.twitch.tv/oauth2/authorize',
257 |
258 | async getUser(token) {
259 | const response = await window.fetch('https://id.twitch.tv/oauth2/validate', {
260 | headers: {
261 | Authorization: 'OAuth ' + token,
262 | },
263 | });
264 |
265 | if (response.status !== 200) {
266 | throw new InvalidTokenError();
267 | }
268 |
269 | const json: TwitchTokenDetails = await response.json();
270 |
271 | return {
272 | login: json.login,
273 | id: json.user_id,
274 | };
275 | },
276 |
277 | async getStreams(auth) {
278 | /**
279 | * Performs a fetch assuming to return JSON, including client ID and
280 | * current authorization token in the request.
281 | *
282 | * @param url URL of resource to fetch.
283 | *
284 | * @return Promise resolving to response JSON.
285 | */
286 | async function fetchJSONWithClientId(url: string): Promise {
287 | const response = await window.fetch(url, {
288 | headers: {
289 | 'Content-Type': 'application/json',
290 | 'Client-Id': applications.twitch.clientId,
291 | Authorization: 'Bearer ' + auth.token,
292 | },
293 | });
294 |
295 | if (response.status === 401) {
296 | throw new InvalidTokenError();
297 | } else {
298 | return response.json();
299 | }
300 | }
301 |
302 | /**
303 | * Fetches Twitch user follows, returning a promise resolving to a
304 | * formatted array of followed stream user IDs.
305 | *
306 | * @param userId User ID.
307 | *
308 | * @return Promise resolving to user followed IDs.
309 | */
310 | async function fetchFollows(userId: number | string): Promise {
311 | const url = new URL(`${API_BASE}/users/follows`);
312 | url.searchParams.set('first', MAX_PER_PAGE.toString());
313 | url.searchParams.set('from_id', userId.toString());
314 |
315 | const results: string[] = [];
316 |
317 | let cursor: TwitchAPIPaginationCursor;
318 | do {
319 | if (cursor) {
320 | url.searchParams.set('after', cursor);
321 | }
322 |
323 | const json: TwitchAPIPaginatedResponse = await fetchJSONWithClientId(
324 | url.toString()
325 | );
326 |
327 | results.push(...json.data.map((follow) => follow.to_id));
328 |
329 | // Even if response includes all results, a pagination cursor will
330 | // be assigned. Abort early if safe to assume results complete.
331 | if (json.data.length === json.total) {
332 | break;
333 | }
334 |
335 | cursor = json.pagination.cursor;
336 | } while (cursor);
337 |
338 | return results;
339 | }
340 |
341 | /**
342 | * Fetches streams from an array of stream user IDs, returning a promise
343 | * resolving to an array of stream objects.
344 | *
345 | * @param userIds User IDs of streams to fetch.
346 | *
347 | * @return Promise resolving to array of stream objects.
348 | */
349 | async function fetchStreams(userIds: string[]): Promise {
350 | const pages = chunk(userIds, MAX_PER_PAGE);
351 |
352 | return (
353 | await Promise.all(
354 | pages.map(async (page) => {
355 | const streamsURL = new URL(API_BASE + '/streams');
356 | streamsURL.searchParams.set('first', MAX_PER_PAGE.toString());
357 |
358 | const usersURL = new URL(API_BASE + '/users');
359 | usersURL.searchParams.set('first', MAX_PER_PAGE.toString());
360 |
361 | page.forEach((userId) => {
362 | streamsURL.searchParams.append('user_id', userId);
363 | usersURL.searchParams.append('id', userId);
364 | });
365 |
366 | const streams: TwitchAPIPaginatedResponse = await fetchJSONWithClientId(
367 | streamsURL.toString()
368 | );
369 | if (!streams.data.length) {
370 | return [];
371 | }
372 |
373 | const gamesURL = new URL(API_BASE + '/games');
374 | gamesURL.searchParams.set('first', MAX_PER_PAGE.toString());
375 | streams.data.forEach((stream) => {
376 | gamesURL.searchParams.append('id', stream.game_id);
377 | });
378 |
379 | const [games, users]: [
380 | TwitchAPIResponse,
381 | TwitchAPIPaginatedResponse
382 | ] = await Promise.all([
383 | fetchJSONWithClientId(gamesURL.toString()),
384 | fetchJSONWithClientId(usersURL.toString()),
385 | ]);
386 |
387 | return streams.data.reduce((result, stream) => {
388 | const user = find(users.data, {
389 | id: stream.user_id,
390 | });
391 | const game = find(games.data, {
392 | id: stream.game_id,
393 | });
394 |
395 | if (user) {
396 | result.push({
397 | providerName: name,
398 | login: stream.user_name,
399 | url: 'https://twitch.tv/' + user.login,
400 | viewers: stream.viewer_count,
401 | title: stream.title,
402 | avatar: user.profile_image_url,
403 | activity: game ? game.name : undefined,
404 | } as SLStream);
405 | }
406 |
407 | return result;
408 | }, [] as SLStream[]);
409 | })
410 | )
411 | ).flat();
412 | }
413 |
414 | const follows = await fetchFollows(auth.user.id as string);
415 | return fetchStreams(follows);
416 | },
417 | } as SLProvider;
418 |
--------------------------------------------------------------------------------
/common.css:
--------------------------------------------------------------------------------
1 | /*
2 | * Fonts
3 | */
4 |
5 | @font-face {
6 | font-family: Roboto;
7 | src: url('fonts/roboto.woff') format('woff');
8 | font-weight: normal;
9 | font-style: normal;
10 | }
11 |
12 | @font-face {
13 | font-family: Roboto;
14 | src: url('fonts/roboto-bold.woff') format('woff');
15 | font-weight: bold;
16 | font-style: normal;
17 | }
18 |
19 | /*
20 | * Custom Properties
21 | */
22 |
23 | :root {
24 | /* Color scheme options */
25 | --sl-scheme-light-background-color: #fff;
26 | --sl-scheme-light-button-background-color: #fcfcfc;
27 | --sl-scheme-light-button-background-color-focus: #f5f5f5;
28 | --sl-scheme-light-button-background-color-active: #f0f0f0;
29 | --sl-scheme-light-input-background-color: #fcfcfc;
30 | --sl-scheme-light-input-border-color: #999;
31 | --sl-scheme-light-border-color: #ccc;
32 | --sl-scheme-light-font-color: #212529;
33 | --sl-scheme-light-font-color-faded: #495057;
34 | --sl-scheme-light-tab-panel-background-color: #fff;
35 | --sl-scheme-dark-background-color: #323234;
36 | --sl-scheme-dark-button-background-color: #424242;
37 | --sl-scheme-dark-button-background-color-focus: #4a4a4f;
38 | --sl-scheme-dark-button-background-color-active: #666;
39 | --sl-scheme-dark-input-background-color: #2d2d2f;
40 | --sl-scheme-dark-input-border-color: #ccc;
41 | --sl-scheme-dark-border-color: #292a2d;
42 | --sl-scheme-dark-font-color: #e8eaed;
43 | --sl-scheme-dark-font-color-faded: #d2d2d2;
44 | --sl-scheme-dark-tab-panel-background-color: #292929;
45 |
46 | /* Color scheme defaults */
47 | --sl-background-color: var(--sl-scheme-light-background-color);
48 | --sl-button-background-color: var(--sl-scheme-light-button-background-color);
49 | --sl-button-background-color-focus: var(--sl-scheme-light-button-background-color-focus);
50 | --sl-button-background-color-active: var(--sl-scheme-light-button-background-color-active);
51 | --sl-input-background-color: var(--sl-scheme-light-input-background-color);
52 | --sl-input-border-color: var(--sl-scheme-light-input-border-color);
53 | --sl-border-color: var(--sl-scheme-light-border-color);
54 | --sl-font-color: var(--sl-scheme-light-font-color);
55 | --sl-font-color-faded: var(--sl-scheme-light-font-color-faded);
56 | --sl-tab-panel-background-color: var(--sl-scheme-light-tab-panel-background-color);
57 |
58 | /* Provider-specific */
59 | --sl-provider-twitch-background: #9145ff;
60 | --sl-provider-twitch-foreground: #fff;
61 | }
62 |
63 | @media (prefers-color-scheme: dark) {
64 | :root {
65 | --sl-background-color: var(--sl-scheme-dark-background-color);
66 | --sl-button-background-color: var(--sl-scheme-dark-button-background-color);
67 | --sl-button-background-color-focus: var(--sl-scheme-dark-button-background-color-focus);
68 | --sl-button-background-color-active: var(--sl-scheme-dark-button-background-color-active);
69 | --sl-input-background-color: var(--sl-scheme-dark-input-background-color);
70 | --sl-input-border-color: var(--sl-scheme-dark-input-border-color);
71 | --sl-border-color: var(--sl-scheme-dark-border-color);
72 | --sl-font-color: var(--sl-scheme-dark-font-color);
73 | --sl-font-color-faded: var(--sl-scheme-dark-font-color-faded);
74 | --sl-tab-panel-background-color: var(--sl-scheme-dark-tab-panel-background-color);
75 | }
76 | }
77 |
78 | /*
79 | * Elements
80 | */
81 |
82 | *,
83 | *::before,
84 | *::after {
85 | box-sizing: border-box;
86 | }
87 |
88 | html {
89 | font-size: 16px;
90 | }
91 |
92 | body {
93 | padding: 0;
94 | margin: 0;
95 | font-family: Roboto, sans-serif;
96 | font-size: 100%;
97 | background-color: var(--sl-background-color);
98 | color: var(--sl-font-color);
99 | }
100 |
101 | body[data-theme='light'] {
102 | --sl-background-color: var(--sl-scheme-light-background-color);
103 | --sl-button-background-color: var(--sl-scheme-light-button-background-color);
104 | --sl-button-background-color-focus: var(--sl-scheme-light-button-background-color-focus);
105 | --sl-button-background-color-active: var(--sl-scheme-light-button-background-color-active);
106 | --sl-input-background-color: var(--sl-scheme-light-input-background-color);
107 | --sl-input-border-color: var(--sl-scheme-light-input-border-color);
108 | --sl-border-color: var(--sl-scheme-light-border-color);
109 | --sl-font-color: var(--sl-scheme-light-font-color);
110 | --sl-font-color-faded: var(--sl-scheme-light-font-color-faded);
111 | }
112 |
113 | body[data-theme='dark'] {
114 | --sl-background-color: var(--sl-scheme-dark-background-color);
115 | --sl-button-background-color: var(--sl-scheme-dark-button-background-color);
116 | --sl-button-background-color-focus: var(--sl-scheme-dark-button-background-color-focus);
117 | --sl-button-background-color-active: var(--sl-scheme-dark-button-background-color-active);
118 | --sl-input-background-color: var(--sl-scheme-dark-input-background-color);
119 | --sl-input-border-color: var(--sl-scheme-dark-input-border-color);
120 | --sl-border-color: var(--sl-scheme-dark-border-color);
121 | --sl-font-color: var(--sl-scheme-dark-font-color);
122 | --sl-font-color-faded: var(--sl-scheme-dark-font-color-faded);
123 | }
124 |
125 | a {
126 | text-decoration: none;
127 | }
128 |
129 | button {
130 | padding: 8px 12px;
131 | background-color: var(--sl-button-background-color);
132 | border: 1px solid var(--sl-input-border-color);
133 | border-radius: 6px;
134 | color: currentColor;
135 | font-size: 0.9rem;
136 | cursor: pointer;
137 | }
138 |
139 | button:active {
140 | background-color: var(--sl-button-background-color-active);
141 | }
142 |
143 | button:focus,
144 | button:hover {
145 | background-color: var(--sl-button-background-color-focus);
146 | }
147 |
148 | button.is-compact {
149 | padding: 4px 8px;
150 | }
151 |
152 | input {
153 | background-color: var(--sl-input-background-color);
154 | border: 1px solid var(--sl-input-border-color);
155 | border-radius: 6px;
156 | }
157 |
158 | /*
159 | * Card
160 | */
161 |
162 | .card {
163 | display: flex;
164 | padding: 20px;
165 | flex-direction: column;
166 | justify-content: center;
167 | text-align: center;
168 | }
169 |
170 | .card__title {
171 | margin: 1rem 0 0;
172 | font-size: 1.3rem;
173 | line-height: 1;
174 | }
175 |
176 | .card__description {
177 | margin: 1.2rem 0 0;
178 | font-size: 0.9rem;
179 | }
180 |
181 | .card__button {
182 | margin-top: 1.2rem;
183 | }
184 |
185 | /*
186 | * Notice
187 | */
188 |
189 | .notice {
190 | display: flex;
191 | align-items: center;
192 | margin: 8px 0;
193 | padding: 4px 6px;
194 | background-color: #fead9a;
195 | border: 1px solid #721c24;
196 | font-size: 0.9rem;
197 | color: #721c24;
198 | }
199 |
200 | .notice__icon {
201 | margin-left: 2px;
202 | margin-right: 6px;
203 | }
204 |
205 | .notice__text {
206 | flex-basis: 100%;
207 | }
208 |
209 | .notice__button {
210 | background-color: #bb4f36;
211 | border-color: #721c24;
212 | color: #fff;
213 | }
214 |
215 | .notice__button:focus,
216 | .notice__button:hover {
217 | background-color: #d0583c;
218 | }
219 |
220 | /*
221 | * Loading Indicator
222 | */
223 |
224 | @keyframes loading-indicator__dot__pulse {
225 | from {
226 | opacity: 0.4;
227 | }
228 |
229 | to {
230 | opacity: 0.8;
231 | }
232 | }
233 |
234 | .loading-indicator {
235 | display: flex;
236 | flex-direction: row;
237 | justify-content: center;
238 | padding: 20px 0;
239 | }
240 |
241 | .loading-indicator__dot {
242 | width: 12px;
243 | height: 12px;
244 | margin: 0 2px;
245 | border-radius: 50%;
246 | background: #6c6c6c;
247 | animation-name: loading-indicator__dot__pulse;
248 | animation-duration: 0.3s;
249 | animation-iteration-count: infinite;
250 | animation-direction: alternate;
251 | }
252 |
253 | .loading-indicator__dot:nth-child(2) {
254 | animation-delay: 0.1s;
255 | }
256 |
257 | .loading-indicator__dot:nth-child(3) {
258 | animation-delay: 0.2s;
259 | }
260 |
261 | /*
262 | * Icon Button
263 | */
264 |
265 | .icon-button,
266 | .icon-button:focus,
267 | .icon-button:hover {
268 | padding: 0;
269 | background: transparent;
270 | border: none;
271 | border-radius: 0;
272 | font-size: 1rem;
273 | }
274 |
275 | .icon-button .icon {
276 | display: block;
277 | }
278 |
279 | /*
280 | * Visually Hidden
281 | */
282 |
283 | .visually-hidden {
284 | clip: rect(1px, 1px, 1px, 1px);
285 | clip-path: inset(50%);
286 | height: 1px;
287 | width: 1px;
288 | margin: -1px;
289 | overflow: hidden;
290 | padding: 0;
291 | position: absolute;
292 | }
293 |
294 | /*
295 | * Tab Panels
296 | */
297 |
298 | .tab-panels__tabs-list {
299 | margin-bottom: -1px;
300 | }
301 |
302 | .tab-panels__tab-button {
303 | border-bottom-left-radius: 0;
304 | border-bottom-right-radius: 0;
305 | }
306 |
307 | .tab-panels__tab-button[aria-selected='true'] {
308 | background-color: var(--sl-tab-panel-background-color);
309 | border-bottom-color: var(--sl-tab-panel-background-color);
310 | }
311 |
312 | /*
313 | * Tab Panel
314 | */
315 |
316 | .tab-panel {
317 | display: none;
318 | padding: 12px;
319 | background-color: var(--sl-tab-panel-background-color);
320 | border: 1px solid var(--sl-input-border-color);
321 | border-radius: 6px;
322 | border-top-left-radius: 0;
323 | border-top-right-radius: 0;
324 | }
325 |
326 | .tab-panel.tab-panel--active {
327 | display: block;
328 | }
329 |
330 | /*
331 | * Tooltip
332 | */
333 |
334 | .tooltip {
335 | position: relative;
336 | }
337 |
338 | .tooltip__arrow,
339 | .tooltip__text {
340 | will-change: opacity;
341 | opacity: 0;
342 | transition: 0.2s opacity;
343 | transition-delay: 0.2s;
344 | }
345 |
346 | .tooltip__text {
347 | position: absolute;
348 | left: 50%;
349 | padding: 6px 8px;
350 | transform: translateX(-50%);
351 | background-color: rgba(40, 40, 40, 0.9);
352 | border: 1px solid var(--sl-scheme-dark-border-color);
353 | color: #fff;
354 | text-align: center;
355 | border-radius: 6px;
356 | font-size: 0.8rem;
357 | }
358 |
359 | .tooltip.is-left .tooltip__text {
360 | left: auto;
361 | right: 1px;
362 | transform: none;
363 | pointer-events: none;
364 | }
365 |
366 | .tooltip__arrow {
367 | position: absolute;
368 | left: 50%;
369 | margin-left: -5px;
370 | border-width: 5px;
371 | border-style: solid;
372 | }
373 |
374 | .tooltip:focus-within .tooltip__arrow,
375 | .tooltip:focus-within .tooltip__text,
376 | .tooltip:hover .tooltip__arrow,
377 | .tooltip:hover .tooltip__text {
378 | opacity: 1;
379 | }
380 |
381 | .tooltip.is-top .tooltip__text,
382 | .tooltip.is-top .tooltip__arrow {
383 | bottom: 100%;
384 | }
385 |
386 | .tooltip.is-top .tooltip__arrow {
387 | margin-bottom: -10px;
388 | border-color: rgba(40, 40, 40, 0.9) transparent transparent transparent;
389 | }
390 |
391 | .tooltip.is-bottom .tooltip__text,
392 | .tooltip.is-bottom .tooltip__arrow {
393 | top: 100%;
394 | }
395 |
396 | .tooltip.is-bottom .tooltip__arrow {
397 | margin-top: -10px;
398 | border-color: transparent transparent rgba(40, 40, 40, 0.9) transparent;
399 | }
400 |
--------------------------------------------------------------------------------
/LICENSE.md:
--------------------------------------------------------------------------------
1 | StreamLens
2 |
3 | Copyright 2019 Andrew Duthie
4 |
5 | This program is free software: you can redistribute it and/or modify
6 | it under the terms of the GNU General Public License as published by
7 | the Free Software Foundation, either version 3 of the License, or
8 | (at your option) any later version.
9 |
10 | This program is distributed in the hope that it will be useful,
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | GNU General Public License for more details.
14 |
15 | You should have received a copy of the GNU General Public License
16 | along with this program. If not, see https://www.gnu.org/licenses/.
17 |
18 | ### GNU GENERAL PUBLIC LICENSE
19 |
20 | Version 3, 29 June 2007
21 |
22 | Copyright (C) 2007 Free Software Foundation, Inc.
23 |
24 |
25 | Everyone is permitted to copy and distribute verbatim copies of this
26 | license document, but changing it is not allowed.
27 |
28 | ### Preamble
29 |
30 | The GNU General Public License is a free, copyleft license for
31 | software and other kinds of works.
32 |
33 | The licenses for most software and other practical works are designed
34 | to take away your freedom to share and change the works. By contrast,
35 | the GNU General Public License is intended to guarantee your freedom
36 | to share and change all versions of a program--to make sure it remains
37 | free software for all its users. We, the Free Software Foundation, use
38 | the GNU General Public License for most of our software; it applies
39 | also to any other work released this way by its authors. You can apply
40 | it to your programs, too.
41 |
42 | When we speak of free software, we are referring to freedom, not
43 | price. Our General Public Licenses are designed to make sure that you
44 | have the freedom to distribute copies of free software (and charge for
45 | them if you wish), that you receive source code or can get it if you
46 | want it, that you can change the software or use pieces of it in new
47 | free programs, and that you know you can do these things.
48 |
49 | To protect your rights, we need to prevent others from denying you
50 | these rights or asking you to surrender the rights. Therefore, you
51 | have certain responsibilities if you distribute copies of the
52 | software, or if you modify it: responsibilities to respect the freedom
53 | of others.
54 |
55 | For example, if you distribute copies of such a program, whether
56 | gratis or for a fee, you must pass on to the recipients the same
57 | freedoms that you received. You must make sure that they, too, receive
58 | or can get the source code. And you must show them these terms so they
59 | know their rights.
60 |
61 | Developers that use the GNU GPL protect your rights with two steps:
62 | (1) assert copyright on the software, and (2) offer you this License
63 | giving you legal permission to copy, distribute and/or modify it.
64 |
65 | For the developers' and authors' protection, the GPL clearly explains
66 | that there is no warranty for this free software. For both users' and
67 | authors' sake, the GPL requires that modified versions be marked as
68 | changed, so that their problems will not be attributed erroneously to
69 | authors of previous versions.
70 |
71 | Some devices are designed to deny users access to install or run
72 | modified versions of the software inside them, although the
73 | manufacturer can do so. This is fundamentally incompatible with the
74 | aim of protecting users' freedom to change the software. The
75 | systematic pattern of such abuse occurs in the area of products for
76 | individuals to use, which is precisely where it is most unacceptable.
77 | Therefore, we have designed this version of the GPL to prohibit the
78 | practice for those products. If such problems arise substantially in
79 | other domains, we stand ready to extend this provision to those
80 | domains in future versions of the GPL, as needed to protect the
81 | freedom of users.
82 |
83 | Finally, every program is threatened constantly by software patents.
84 | States should not allow patents to restrict development and use of
85 | software on general-purpose computers, but in those that do, we wish
86 | to avoid the special danger that patents applied to a free program
87 | could make it effectively proprietary. To prevent this, the GPL
88 | assures that patents cannot be used to render the program non-free.
89 |
90 | The precise terms and conditions for copying, distribution and
91 | modification follow.
92 |
93 | ### TERMS AND CONDITIONS
94 |
95 | #### 0. Definitions.
96 |
97 | "This License" refers to version 3 of the GNU General Public License.
98 |
99 | "Copyright" also means copyright-like laws that apply to other kinds
100 | of works, such as semiconductor masks.
101 |
102 | "The Program" refers to any copyrightable work licensed under this
103 | License. Each licensee is addressed as "you". "Licensees" and
104 | "recipients" may be individuals or organizations.
105 |
106 | To "modify" a work means to copy from or adapt all or part of the work
107 | in a fashion requiring copyright permission, other than the making of
108 | an exact copy. The resulting work is called a "modified version" of
109 | the earlier work or a work "based on" the earlier work.
110 |
111 | A "covered work" means either the unmodified Program or a work based
112 | on the Program.
113 |
114 | To "propagate" a work means to do anything with it that, without
115 | permission, would make you directly or secondarily liable for
116 | infringement under applicable copyright law, except executing it on a
117 | computer or modifying a private copy. Propagation includes copying,
118 | distribution (with or without modification), making available to the
119 | public, and in some countries other activities as well.
120 |
121 | To "convey" a work means any kind of propagation that enables other
122 | parties to make or receive copies. Mere interaction with a user
123 | through a computer network, with no transfer of a copy, is not
124 | conveying.
125 |
126 | An interactive user interface displays "Appropriate Legal Notices" to
127 | the extent that it includes a convenient and prominently visible
128 | feature that (1) displays an appropriate copyright notice, and (2)
129 | tells the user that there is no warranty for the work (except to the
130 | extent that warranties are provided), that licensees may convey the
131 | work under this License, and how to view a copy of this License. If
132 | the interface presents a list of user commands or options, such as a
133 | menu, a prominent item in the list meets this criterion.
134 |
135 | #### 1. Source Code.
136 |
137 | The "source code" for a work means the preferred form of the work for
138 | making modifications to it. "Object code" means any non-source form of
139 | a work.
140 |
141 | A "Standard Interface" means an interface that either is an official
142 | standard defined by a recognized standards body, or, in the case of
143 | interfaces specified for a particular programming language, one that
144 | is widely used among developers working in that language.
145 |
146 | The "System Libraries" of an executable work include anything, other
147 | than the work as a whole, that (a) is included in the normal form of
148 | packaging a Major Component, but which is not part of that Major
149 | Component, and (b) serves only to enable use of the work with that
150 | Major Component, or to implement a Standard Interface for which an
151 | implementation is available to the public in source code form. A
152 | "Major Component", in this context, means a major essential component
153 | (kernel, window system, and so on) of the specific operating system
154 | (if any) on which the executable work runs, or a compiler used to
155 | produce the work, or an object code interpreter used to run it.
156 |
157 | The "Corresponding Source" for a work in object code form means all
158 | the source code needed to generate, install, and (for an executable
159 | work) run the object code and to modify the work, including scripts to
160 | control those activities. However, it does not include the work's
161 | System Libraries, or general-purpose tools or generally available free
162 | programs which are used unmodified in performing those activities but
163 | which are not part of the work. For example, Corresponding Source
164 | includes interface definition files associated with source files for
165 | the work, and the source code for shared libraries and dynamically
166 | linked subprograms that the work is specifically designed to require,
167 | such as by intimate data communication or control flow between those
168 | subprograms and other parts of the work.
169 |
170 | The Corresponding Source need not include anything that users can
171 | regenerate automatically from other parts of the Corresponding Source.
172 |
173 | The Corresponding Source for a work in source code form is that same
174 | work.
175 |
176 | #### 2. Basic Permissions.
177 |
178 | All rights granted under this License are granted for the term of
179 | copyright on the Program, and are irrevocable provided the stated
180 | conditions are met. This License explicitly affirms your unlimited
181 | permission to run the unmodified Program. The output from running a
182 | covered work is covered by this License only if the output, given its
183 | content, constitutes a covered work. This License acknowledges your
184 | rights of fair use or other equivalent, as provided by copyright law.
185 |
186 | You may make, run and propagate covered works that you do not convey,
187 | without conditions so long as your license otherwise remains in force.
188 | You may convey covered works to others for the sole purpose of having
189 | them make modifications exclusively for you, or provide you with
190 | facilities for running those works, provided that you comply with the
191 | terms of this License in conveying all material for which you do not
192 | control copyright. Those thus making or running the covered works for
193 | you must do so exclusively on your behalf, under your direction and
194 | control, on terms that prohibit them from making any copies of your
195 | copyrighted material outside their relationship with you.
196 |
197 | Conveying under any other circumstances is permitted solely under the
198 | conditions stated below. Sublicensing is not allowed; section 10 makes
199 | it unnecessary.
200 |
201 | #### 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
202 |
203 | No covered work shall be deemed part of an effective technological
204 | measure under any applicable law fulfilling obligations under article
205 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or
206 | similar laws prohibiting or restricting circumvention of such
207 | measures.
208 |
209 | When you convey a covered work, you waive any legal power to forbid
210 | circumvention of technological measures to the extent such
211 | circumvention is effected by exercising rights under this License with
212 | respect to the covered work, and you disclaim any intention to limit
213 | operation or modification of the work as a means of enforcing, against
214 | the work's users, your or third parties' legal rights to forbid
215 | circumvention of technological measures.
216 |
217 | #### 4. Conveying Verbatim Copies.
218 |
219 | You may convey verbatim copies of the Program's source code as you
220 | receive it, in any medium, provided that you conspicuously and
221 | appropriately publish on each copy an appropriate copyright notice;
222 | keep intact all notices stating that this License and any
223 | non-permissive terms added in accord with section 7 apply to the code;
224 | keep intact all notices of the absence of any warranty; and give all
225 | recipients a copy of this License along with the Program.
226 |
227 | You may charge any price or no price for each copy that you convey,
228 | and you may offer support or warranty protection for a fee.
229 |
230 | #### 5. Conveying Modified Source Versions.
231 |
232 | You may convey a work based on the Program, or the modifications to
233 | produce it from the Program, in the form of source code under the
234 | terms of section 4, provided that you also meet all of these
235 | conditions:
236 |
237 | - a) The work must carry prominent notices stating that you modified
238 | it, and giving a relevant date.
239 | - b) The work must carry prominent notices stating that it is
240 | released under this License and any conditions added under
241 | section 7. This requirement modifies the requirement in section 4
242 | to "keep intact all notices".
243 | - c) You must license the entire work, as a whole, under this
244 | License to anyone who comes into possession of a copy. This
245 | License will therefore apply, along with any applicable section 7
246 | additional terms, to the whole of the work, and all its parts,
247 | regardless of how they are packaged. This License gives no
248 | permission to license the work in any other way, but it does not
249 | invalidate such permission if you have separately received it.
250 | - d) If the work has interactive user interfaces, each must display
251 | Appropriate Legal Notices; however, if the Program has interactive
252 | interfaces that do not display Appropriate Legal Notices, your
253 | work need not make them do so.
254 |
255 | A compilation of a covered work with other separate and independent
256 | works, which are not by their nature extensions of the covered work,
257 | and which are not combined with it such as to form a larger program,
258 | in or on a volume of a storage or distribution medium, is called an
259 | "aggregate" if the compilation and its resulting copyright are not
260 | used to limit the access or legal rights of the compilation's users
261 | beyond what the individual works permit. Inclusion of a covered work
262 | in an aggregate does not cause this License to apply to the other
263 | parts of the aggregate.
264 |
265 | #### 6. Conveying Non-Source Forms.
266 |
267 | You may convey a covered work in object code form under the terms of
268 | sections 4 and 5, provided that you also convey the machine-readable
269 | Corresponding Source under the terms of this License, in one of these
270 | ways:
271 |
272 | - a) Convey the object code in, or embodied in, a physical product
273 | (including a physical distribution medium), accompanied by the
274 | Corresponding Source fixed on a durable physical medium
275 | customarily used for software interchange.
276 | - b) Convey the object code in, or embodied in, a physical product
277 | (including a physical distribution medium), accompanied by a
278 | written offer, valid for at least three years and valid for as
279 | long as you offer spare parts or customer support for that product
280 | model, to give anyone who possesses the object code either (1) a
281 | copy of the Corresponding Source for all the software in the
282 | product that is covered by this License, on a durable physical
283 | medium customarily used for software interchange, for a price no
284 | more than your reasonable cost of physically performing this
285 | conveying of source, or (2) access to copy the Corresponding
286 | Source from a network server at no charge.
287 | - c) Convey individual copies of the object code with a copy of the
288 | written offer to provide the Corresponding Source. This
289 | alternative is allowed only occasionally and noncommercially, and
290 | only if you received the object code with such an offer, in accord
291 | with subsection 6b.
292 | - d) Convey the object code by offering access from a designated
293 | place (gratis or for a charge), and offer equivalent access to the
294 | Corresponding Source in the same way through the same place at no
295 | further charge. You need not require recipients to copy the
296 | Corresponding Source along with the object code. If the place to
297 | copy the object code is a network server, the Corresponding Source
298 | may be on a different server (operated by you or a third party)
299 | that supports equivalent copying facilities, provided you maintain
300 | clear directions next to the object code saying where to find the
301 | Corresponding Source. Regardless of what server hosts the
302 | Corresponding Source, you remain obligated to ensure that it is
303 | available for as long as needed to satisfy these requirements.
304 | - e) Convey the object code using peer-to-peer transmission,
305 | provided you inform other peers where the object code and
306 | Corresponding Source of the work are being offered to the general
307 | public at no charge under subsection 6d.
308 |
309 | A separable portion of the object code, whose source code is excluded
310 | from the Corresponding Source as a System Library, need not be
311 | included in conveying the object code work.
312 |
313 | A "User Product" is either (1) a "consumer product", which means any
314 | tangible personal property which is normally used for personal,
315 | family, or household purposes, or (2) anything designed or sold for
316 | incorporation into a dwelling. In determining whether a product is a
317 | consumer product, doubtful cases shall be resolved in favor of
318 | coverage. For a particular product received by a particular user,
319 | "normally used" refers to a typical or common use of that class of
320 | product, regardless of the status of the particular user or of the way
321 | in which the particular user actually uses, or expects or is expected
322 | to use, the product. A product is a consumer product regardless of
323 | whether the product has substantial commercial, industrial or
324 | non-consumer uses, unless such uses represent the only significant
325 | mode of use of the product.
326 |
327 | "Installation Information" for a User Product means any methods,
328 | procedures, authorization keys, or other information required to
329 | install and execute modified versions of a covered work in that User
330 | Product from a modified version of its Corresponding Source. The
331 | information must suffice to ensure that the continued functioning of
332 | the modified object code is in no case prevented or interfered with
333 | solely because modification has been made.
334 |
335 | If you convey an object code work under this section in, or with, or
336 | specifically for use in, a User Product, and the conveying occurs as
337 | part of a transaction in which the right of possession and use of the
338 | User Product is transferred to the recipient in perpetuity or for a
339 | fixed term (regardless of how the transaction is characterized), the
340 | Corresponding Source conveyed under this section must be accompanied
341 | by the Installation Information. But this requirement does not apply
342 | if neither you nor any third party retains the ability to install
343 | modified object code on the User Product (for example, the work has
344 | been installed in ROM).
345 |
346 | The requirement to provide Installation Information does not include a
347 | requirement to continue to provide support service, warranty, or
348 | updates for a work that has been modified or installed by the
349 | recipient, or for the User Product in which it has been modified or
350 | installed. Access to a network may be denied when the modification
351 | itself materially and adversely affects the operation of the network
352 | or violates the rules and protocols for communication across the
353 | network.
354 |
355 | Corresponding Source conveyed, and Installation Information provided,
356 | in accord with this section must be in a format that is publicly
357 | documented (and with an implementation available to the public in
358 | source code form), and must require no special password or key for
359 | unpacking, reading or copying.
360 |
361 | #### 7. Additional Terms.
362 |
363 | "Additional permissions" are terms that supplement the terms of this
364 | License by making exceptions from one or more of its conditions.
365 | Additional permissions that are applicable to the entire Program shall
366 | be treated as though they were included in this License, to the extent
367 | that they are valid under applicable law. If additional permissions
368 | apply only to part of the Program, that part may be used separately
369 | under those permissions, but the entire Program remains governed by
370 | this License without regard to the additional permissions.
371 |
372 | When you convey a copy of a covered work, you may at your option
373 | remove any additional permissions from that copy, or from any part of
374 | it. (Additional permissions may be written to require their own
375 | removal in certain cases when you modify the work.) You may place
376 | additional permissions on material, added by you to a covered work,
377 | for which you have or can give appropriate copyright permission.
378 |
379 | Notwithstanding any other provision of this License, for material you
380 | add to a covered work, you may (if authorized by the copyright holders
381 | of that material) supplement the terms of this License with terms:
382 |
383 | - a) Disclaiming warranty or limiting liability differently from the
384 | terms of sections 15 and 16 of this License; or
385 | - b) Requiring preservation of specified reasonable legal notices or
386 | author attributions in that material or in the Appropriate Legal
387 | Notices displayed by works containing it; or
388 | - c) Prohibiting misrepresentation of the origin of that material,
389 | or requiring that modified versions of such material be marked in
390 | reasonable ways as different from the original version; or
391 | - d) Limiting the use for publicity purposes of names of licensors
392 | or authors of the material; or
393 | - e) Declining to grant rights under trademark law for use of some
394 | trade names, trademarks, or service marks; or
395 | - f) Requiring indemnification of licensors and authors of that
396 | material by anyone who conveys the material (or modified versions
397 | of it) with contractual assumptions of liability to the recipient,
398 | for any liability that these contractual assumptions directly
399 | impose on those licensors and authors.
400 |
401 | All other non-permissive additional terms are considered "further
402 | restrictions" within the meaning of section 10. If the Program as you
403 | received it, or any part of it, contains a notice stating that it is
404 | governed by this License along with a term that is a further
405 | restriction, you may remove that term. If a license document contains
406 | a further restriction but permits relicensing or conveying under this
407 | License, you may add to a covered work material governed by the terms
408 | of that license document, provided that the further restriction does
409 | not survive such relicensing or conveying.
410 |
411 | If you add terms to a covered work in accord with this section, you
412 | must place, in the relevant source files, a statement of the
413 | additional terms that apply to those files, or a notice indicating
414 | where to find the applicable terms.
415 |
416 | Additional terms, permissive or non-permissive, may be stated in the
417 | form of a separately written license, or stated as exceptions; the
418 | above requirements apply either way.
419 |
420 | #### 8. Termination.
421 |
422 | You may not propagate or modify a covered work except as expressly
423 | provided under this License. Any attempt otherwise to propagate or
424 | modify it is void, and will automatically terminate your rights under
425 | this License (including any patent licenses granted under the third
426 | paragraph of section 11).
427 |
428 | However, if you cease all violation of this License, then your license
429 | from a particular copyright holder is reinstated (a) provisionally,
430 | unless and until the copyright holder explicitly and finally
431 | terminates your license, and (b) permanently, if the copyright holder
432 | fails to notify you of the violation by some reasonable means prior to
433 | 60 days after the cessation.
434 |
435 | Moreover, your license from a particular copyright holder is
436 | reinstated permanently if the copyright holder notifies you of the
437 | violation by some reasonable means, this is the first time you have
438 | received notice of violation of this License (for any work) from that
439 | copyright holder, and you cure the violation prior to 30 days after
440 | your receipt of the notice.
441 |
442 | Termination of your rights under this section does not terminate the
443 | licenses of parties who have received copies or rights from you under
444 | this License. If your rights have been terminated and not permanently
445 | reinstated, you do not qualify to receive new licenses for the same
446 | material under section 10.
447 |
448 | #### 9. Acceptance Not Required for Having Copies.
449 |
450 | You are not required to accept this License in order to receive or run
451 | a copy of the Program. Ancillary propagation of a covered work
452 | occurring solely as a consequence of using peer-to-peer transmission
453 | to receive a copy likewise does not require acceptance. However,
454 | nothing other than this License grants you permission to propagate or
455 | modify any covered work. These actions infringe copyright if you do
456 | not accept this License. Therefore, by modifying or propagating a
457 | covered work, you indicate your acceptance of this License to do so.
458 |
459 | #### 10. Automatic Licensing of Downstream Recipients.
460 |
461 | Each time you convey a covered work, the recipient automatically
462 | receives a license from the original licensors, to run, modify and
463 | propagate that work, subject to this License. You are not responsible
464 | for enforcing compliance by third parties with this License.
465 |
466 | An "entity transaction" is a transaction transferring control of an
467 | organization, or substantially all assets of one, or subdividing an
468 | organization, or merging organizations. If propagation of a covered
469 | work results from an entity transaction, each party to that
470 | transaction who receives a copy of the work also receives whatever
471 | licenses to the work the party's predecessor in interest had or could
472 | give under the previous paragraph, plus a right to possession of the
473 | Corresponding Source of the work from the predecessor in interest, if
474 | the predecessor has it or can get it with reasonable efforts.
475 |
476 | You may not impose any further restrictions on the exercise of the
477 | rights granted or affirmed under this License. For example, you may
478 | not impose a license fee, royalty, or other charge for exercise of
479 | rights granted under this License, and you may not initiate litigation
480 | (including a cross-claim or counterclaim in a lawsuit) alleging that
481 | any patent claim is infringed by making, using, selling, offering for
482 | sale, or importing the Program or any portion of it.
483 |
484 | #### 11. Patents.
485 |
486 | A "contributor" is a copyright holder who authorizes use under this
487 | License of the Program or a work on which the Program is based. The
488 | work thus licensed is called the contributor's "contributor version".
489 |
490 | A contributor's "essential patent claims" are all patent claims owned
491 | or controlled by the contributor, whether already acquired or
492 | hereafter acquired, that would be infringed by some manner, permitted
493 | by this License, of making, using, or selling its contributor version,
494 | but do not include claims that would be infringed only as a
495 | consequence of further modification of the contributor version. For
496 | purposes of this definition, "control" includes the right to grant
497 | patent sublicenses in a manner consistent with the requirements of
498 | this License.
499 |
500 | Each contributor grants you a non-exclusive, worldwide, royalty-free
501 | patent license under the contributor's essential patent claims, to
502 | make, use, sell, offer for sale, import and otherwise run, modify and
503 | propagate the contents of its contributor version.
504 |
505 | In the following three paragraphs, a "patent license" is any express
506 | agreement or commitment, however denominated, not to enforce a patent
507 | (such as an express permission to practice a patent or covenant not to
508 | sue for patent infringement). To "grant" such a patent license to a
509 | party means to make such an agreement or commitment not to enforce a
510 | patent against the party.
511 |
512 | If you convey a covered work, knowingly relying on a patent license,
513 | and the Corresponding Source of the work is not available for anyone
514 | to copy, free of charge and under the terms of this License, through a
515 | publicly available network server or other readily accessible means,
516 | then you must either (1) cause the Corresponding Source to be so
517 | available, or (2) arrange to deprive yourself of the benefit of the
518 | patent license for this particular work, or (3) arrange, in a manner
519 | consistent with the requirements of this License, to extend the patent
520 | license to downstream recipients. "Knowingly relying" means you have
521 | actual knowledge that, but for the patent license, your conveying the
522 | covered work in a country, or your recipient's use of the covered work
523 | in a country, would infringe one or more identifiable patents in that
524 | country that you have reason to believe are valid.
525 |
526 | If, pursuant to or in connection with a single transaction or
527 | arrangement, you convey, or propagate by procuring conveyance of, a
528 | covered work, and grant a patent license to some of the parties
529 | receiving the covered work authorizing them to use, propagate, modify
530 | or convey a specific copy of the covered work, then the patent license
531 | you grant is automatically extended to all recipients of the covered
532 | work and works based on it.
533 |
534 | A patent license is "discriminatory" if it does not include within the
535 | scope of its coverage, prohibits the exercise of, or is conditioned on
536 | the non-exercise of one or more of the rights that are specifically
537 | granted under this License. You may not convey a covered work if you
538 | are a party to an arrangement with a third party that is in the
539 | business of distributing software, under which you make payment to the
540 | third party based on the extent of your activity of conveying the
541 | work, and under which the third party grants, to any of the parties
542 | who would receive the covered work from you, a discriminatory patent
543 | license (a) in connection with copies of the covered work conveyed by
544 | you (or copies made from those copies), or (b) primarily for and in
545 | connection with specific products or compilations that contain the
546 | covered work, unless you entered into that arrangement, or that patent
547 | license was granted, prior to 28 March 2007.
548 |
549 | Nothing in this License shall be construed as excluding or limiting
550 | any implied license or other defenses to infringement that may
551 | otherwise be available to you under applicable patent law.
552 |
553 | #### 12. No Surrender of Others' Freedom.
554 |
555 | If conditions are imposed on you (whether by court order, agreement or
556 | otherwise) that contradict the conditions of this License, they do not
557 | excuse you from the conditions of this License. If you cannot convey a
558 | covered work so as to satisfy simultaneously your obligations under
559 | this License and any other pertinent obligations, then as a
560 | consequence you may not convey it at all. For example, if you agree to
561 | terms that obligate you to collect a royalty for further conveying
562 | from those to whom you convey the Program, the only way you could
563 | satisfy both those terms and this License would be to refrain entirely
564 | from conveying the Program.
565 |
566 | #### 13. Use with the GNU Affero General Public License.
567 |
568 | Notwithstanding any other provision of this License, you have
569 | permission to link or combine any covered work with a work licensed
570 | under version 3 of the GNU Affero General Public License into a single
571 | combined work, and to convey the resulting work. The terms of this
572 | License will continue to apply to the part which is the covered work,
573 | but the special requirements of the GNU Affero General Public License,
574 | section 13, concerning interaction through a network will apply to the
575 | combination as such.
576 |
577 | #### 14. Revised Versions of this License.
578 |
579 | The Free Software Foundation may publish revised and/or new versions
580 | of the GNU General Public License from time to time. Such new versions
581 | will be similar in spirit to the present version, but may differ in
582 | detail to address new problems or concerns.
583 |
584 | Each version is given a distinguishing version number. If the Program
585 | specifies that a certain numbered version of the GNU General Public
586 | License "or any later version" applies to it, you have the option of
587 | following the terms and conditions either of that numbered version or
588 | of any later version published by the Free Software Foundation. If the
589 | Program does not specify a version number of the GNU General Public
590 | License, you may choose any version ever published by the Free
591 | Software Foundation.
592 |
593 | If the Program specifies that a proxy can decide which future versions
594 | of the GNU General Public License can be used, that proxy's public
595 | statement of acceptance of a version permanently authorizes you to
596 | choose that version for the Program.
597 |
598 | Later license versions may give you additional or different
599 | permissions. However, no additional obligations are imposed on any
600 | author or copyright holder as a result of your choosing to follow a
601 | later version.
602 |
603 | #### 15. Disclaimer of Warranty.
604 |
605 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
606 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
607 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT
608 | WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT
609 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
610 | A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND
611 | PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE
612 | DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR
613 | CORRECTION.
614 |
615 | #### 16. Limitation of Liability.
616 |
617 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
618 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR
619 | CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
620 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES
621 | ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT
622 | NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR
623 | LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM
624 | TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER
625 | PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
626 |
627 | #### 17. Interpretation of Sections 15 and 16.
628 |
629 | If the disclaimer of warranty and limitation of liability provided
630 | above cannot be given local legal effect according to their terms,
631 | reviewing courts shall apply local law that most closely approximates
632 | an absolute waiver of all civil liability in connection with the
633 | Program, unless a warranty or assumption of liability accompanies a
634 | copy of the Program in return for a fee.
635 |
636 | END OF TERMS AND CONDITIONS
637 |
638 | ### How to Apply These Terms to Your New Programs
639 |
640 | If you develop a new program, and you want it to be of the greatest
641 | possible use to the public, the best way to achieve this is to make it
642 | free software which everyone can redistribute and change under these
643 | terms.
644 |
645 | To do so, attach the following notices to the program. It is safest to
646 | attach them to the start of each source file to most effectively state
647 | the exclusion of warranty; and each file should have at least the
648 | "copyright" line and a pointer to where the full notice is found.
649 |
650 |
651 | Copyright (C)
652 |
653 | This program is free software: you can redistribute it and/or modify
654 | it under the terms of the GNU General Public License as published by
655 | the Free Software Foundation, either version 3 of the License, or
656 | (at your option) any later version.
657 |
658 | This program is distributed in the hope that it will be useful,
659 | but WITHOUT ANY WARRANTY; without even the implied warranty of
660 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
661 | GNU General Public License for more details.
662 |
663 | You should have received a copy of the GNU General Public License
664 | along with this program. If not, see .
665 |
666 | Also add information on how to contact you by electronic and paper
667 | mail.
668 |
669 | If the program does terminal interaction, make it output a short
670 | notice like this when it starts in an interactive mode:
671 |
672 | Copyright (C)
673 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
674 | This is free software, and you are welcome to redistribute it
675 | under certain conditions; type `show c' for details.
676 |
677 | The hypothetical commands \`show w' and \`show c' should show the
678 | appropriate parts of the General Public License. Of course, your
679 | program's commands might be different; for a GUI interface, you would
680 | use an "about box".
681 |
682 | You should also get your employer (if you work as a programmer) or
683 | school, if any, to sign a "copyright disclaimer" for the program, if
684 | necessary. For more information on this, and how to apply and follow
685 | the GNU GPL, see .
686 |
687 | The GNU General Public License does not permit incorporating your
688 | program into proprietary programs. If your program is a subroutine
689 | library, you may consider it more useful to permit linking proprietary
690 | applications with the library. If this is what you want to do, use the
691 | GNU Lesser General Public License instead of this License. But first,
692 | please read .
693 |
--------------------------------------------------------------------------------