1111
1212import * as utils from '../BookReader/utils.js' ;
1313
14+ //contains all filters and labels for checkboxs
15+ const FILTERLIST = [
16+ {
17+ filter : "grayscale(100%)" ,
18+ label : "Grayscale"
19+ } ,
20+ {
21+ filter : "brightness(120%)" ,
22+ label : "High brightness"
23+ } ,
24+ {
25+ filter : "invert(100%)" ,
26+ label : "Inverted (dark mode)"
27+ } ,
28+ {
29+ filter : "contrast(120%)" ,
30+ label : "High contrast"
31+ } ,
32+ ]
33+
1434jQuery . extend ( BookReader . defaultOptions , {
1535 enableMobileNav : true ,
1636 mobileNavTitle : 'Internet Archive' ,
@@ -70,9 +90,8 @@ BookReader.prototype.initToolbar = (function (super_) {
7090 }
7191 } ) ;
7292
73- // High contrast button
74- $drawerEl . find ( '.high-contrast-button' ) . click (
75- ( ) => this . refs . $br . toggleClass ( 'high-contrast' ) ) ;
93+ //apply filters when checkboxs clicked
94+ $drawerEl . find ( '.BRcheckbox-filters' ) . click ( ( ) => applyFilters ( $drawerEl , this ) ) ;
7695
7796 // Bind mobile switch buttons
7897 $drawerEl . find ( '.DrawerLayoutButton.one_page_mode' ) . click (
@@ -148,13 +167,24 @@ BookReader.prototype.buildToolbarElement = (function (super_) {
148167 */
149168BookReader . prototype . buildMobileDrawerElement = function ( ) {
150169 let experimentalHtml = '' ;
170+ //builds filters checkbox html
151171 if ( this . enableExperimentalControls ) {
152172 experimentalHtml = `
153- <p class="DrawerSettingsTitle">Experimental (may not work)</p>
154- <button class="BRaction default high-contrast-button">Toggle high contrast</button>
155- ` ;
173+ <p class="DrawerSettingsTitle">Visual Adjustment</p>
174+ <div class="BRcheckbox-group-filters">
175+ ` ;
176+ FILTERLIST . forEach ( ( el , i ) => {
177+ const checkboxHtml = `
178+ <input type="checkbox" class="BRcheckbox-filters" id="filter${ i } ">
179+ <label for="filter${ i } " class="BRcheckbox-label-filters">${ el . label } </label><br>
180+
181+ ` ;
182+ experimentalHtml = experimentalHtml . concat ( checkboxHtml ) ;
183+ } )
184+ experimentalHtml = experimentalHtml . concat ( "</div>" ) ;
156185 }
157186
187+
158188 const settingsSection = `
159189 <span>
160190 <span class="DrawerIconWrapper">
@@ -232,4 +262,28 @@ BookReader.prototype.$ = (function (super_) {
232262 }
233263 return $results ;
234264 } ;
235- } ) ( BookReader . prototype . $ ) ;
265+ } ) ( BookReader . prototype . $ ) ;
266+
267+ /**
268+ * Dynamically creates styles combining different filters for BookReaders imgs
269+ * based on filters checkbox
270+ */
271+ const applyFilters = ( drawerEl , br ) => {
272+ let filterStr = "" ;
273+
274+ $ ( '.BRcheckbox-filters' ) . each (
275+ ( i , el ) => {
276+ br . refs . $br . removeClass ( "filter-applied" ) ;
277+ if ( $ ( el ) . is ( ':checked' ) ) {
278+ br . refs . $br . addClass ( $ ( el ) . attr ( "filter-applied" ) ) ;
279+ filterStr = filterStr + FILTERLIST [ i ] . filter ;
280+ }
281+ }
282+ ) ;
283+ const filtersSheet = $ ( "#filtersStyle" ) [ 0 ] || document . createElement ( 'style' ) ;
284+ filtersSheet . id = "filtersStyle" ;
285+ filtersSheet . innerHTML = `.BRpagecontainer img {
286+ filter: ${ filterStr } ;
287+ -webkit-filter: ${ filterStr } ;}` ;
288+ document . body . appendChild ( filtersSheet ) ;
289+ }
0 commit comments