forked from darkreader/darkreader
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Use as `DarkReader.enable()` - Fixed darkreader#1287 - Fixed darkreader#1315
- Loading branch information
1 parent
5da673e
commit 529b0b8
Showing
8 changed files
with
216 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
* | ||
|
||
!darkreader.js | ||
!index.d.ts | ||
!LICENSE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
declare namespace DarkReader { | ||
/** | ||
* Enables dark mode for current web page. | ||
* @param theme Theme options. | ||
* @param fixes Fixes for the generated theme. | ||
* @param isIFrame This flag should be enabled if the dark mode was enabled on a parent web page (where the current page is an IFrame). | ||
*/ | ||
function enable(theme: Partial<Theme>, fixes?: DynamicThemeFix, isIFrame?: boolean): void; | ||
|
||
/** | ||
* Disables dark mode for current web page. | ||
*/ | ||
function disable(): void; | ||
|
||
/** | ||
* Theme options. | ||
*/ | ||
interface Theme { | ||
/** | ||
* 1 - dark mode, 0 - dimmed mode. | ||
* Default 1. | ||
*/ | ||
mode: 0 | 1; | ||
/** | ||
* Brightness (0 - 100+). | ||
* Default 100. | ||
*/ | ||
brightness: number; | ||
/** | ||
* Contrast (0 - 100+). | ||
* Default 100. | ||
*/ | ||
contrast: number; | ||
/** | ||
* Grayscale (0 - 100). | ||
* Default 0. | ||
*/ | ||
grayscale: number; | ||
/** | ||
* Sepia (0 - 100). | ||
* Default 0. | ||
*/ | ||
sepia: number; | ||
/** | ||
* Specifies if custom font should be used. | ||
* Default false. | ||
*/ | ||
useFont: boolean; | ||
/** | ||
* Font family to use. | ||
*/ | ||
fontFamily: string; | ||
/** | ||
* Makes text look bolder (0 - 1px). | ||
* Default 0. | ||
*/ | ||
textStroke: number; | ||
} | ||
|
||
/** | ||
* Contains fixes for the generated theme. | ||
*/ | ||
interface DynamicThemeFix { | ||
/** | ||
* List of CSS selectors that should be inverted. | ||
* Usually icons that are contained in sprites. | ||
*/ | ||
invert: string[]; | ||
/** | ||
* Additional CSS. | ||
* ${color} template should be used to apply theme options to a color. | ||
* Example: | ||
* ``` | ||
* body { | ||
* background-color: ${white} !important; | ||
* background-image: none !important; | ||
* } | ||
* ``` | ||
*/ | ||
css: string; | ||
} | ||
} | ||
|
||
declare module 'darkreader' { | ||
export = DarkReader; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
if (!window.chrome) { | ||
window.chrome = {} as any; | ||
} | ||
if (!window.chrome.runtime) { | ||
window.chrome.runtime = { | ||
sendMessage() { | ||
throw new Error('Access to some of your resources was blocked by cross-origin policy'); | ||
}, | ||
onMessage: { | ||
addListener: Function.prototype, | ||
}, | ||
} as any; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import './chrome'; | ||
import {FilterConfig as Theme, DynamicThemeFix} from '../definitions'; | ||
import ThemeEngines from '../generators/theme-engines'; | ||
import {createOrUpdateDynamicTheme, removeDynamicTheme} from '../inject/dynamic-theme'; | ||
|
||
const defaultTheme: Theme = { | ||
mode: 1, | ||
brightness: 100, | ||
contrast: 100, | ||
grayscale: 0, | ||
sepia: 0, | ||
useFont: false, | ||
fontFamily: '', | ||
textStroke: 0, | ||
engine: ThemeEngines.dynamicTheme, | ||
stylesheet: '', | ||
}; | ||
|
||
export function enable(themeOptions: Partial<Theme>, fixes: DynamicThemeFix = null, isIFrame = false) { | ||
const theme = {...defaultTheme, ...themeOptions}; | ||
|
||
if (theme.engine !== ThemeEngines.dynamicTheme) { | ||
throw new Error('Theme engine is not supported'); | ||
} | ||
|
||
createOrUpdateDynamicTheme(theme, fixes, isIFrame); | ||
} | ||
|
||
export function disable() { | ||
removeDynamicTheme(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
const rollup = require('rollup'); | ||
const rollupPluginCommonjs = require('rollup-plugin-commonjs'); | ||
const rollupPluginNodeResolve = require('rollup-plugin-node-resolve'); | ||
const rollupPluginReplace = require('rollup-plugin-replace'); | ||
const rollupPluginTypescript = require('rollup-plugin-typescript2'); | ||
const typescript = require('typescript'); | ||
const packageJSON = require('../package.json'); | ||
|
||
async function bundleAPI() { | ||
const src = 'src/api/index.ts'; | ||
const dest = 'darkreader.js'; | ||
|
||
const bundle = await rollup.rollup({ | ||
input: src, | ||
plugins: [ | ||
rollupPluginNodeResolve(), | ||
rollupPluginCommonjs(), | ||
rollupPluginTypescript({ | ||
typescript, | ||
tsconfig: 'src/tsconfig.json', | ||
tsconfigOverride: { | ||
compilerOptions: { | ||
removeComments: true, | ||
target: 'es5', | ||
}, | ||
}, | ||
clean: true, | ||
cacheRoot: null, | ||
}), | ||
rollupPluginReplace({ | ||
'__DEBUG__': 'false', | ||
}), | ||
].filter((x) => x) | ||
}); | ||
await bundle.write({ | ||
banner: `/**\n * Dark Reader v${packageJSON.version}\n * https://darkreader.org/\n */\n`, | ||
file: dest, | ||
strict: true, | ||
format: 'umd', | ||
name: 'DarkReader', | ||
sourcemap: false, | ||
}); | ||
} | ||
|
||
module.exports = bundleAPI; |