Skip to content

Commit

Permalink
Revert "History mode (#27)" (#28)
Browse files Browse the repository at this point in the history
This reverts commit 29dabd2.
  • Loading branch information
heho authored Nov 24, 2023
1 parent 29dabd2 commit ff91464
Show file tree
Hide file tree
Showing 25 changed files with 229 additions and 472 deletions.
2 changes: 1 addition & 1 deletion .env
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ THEME_NEUTRAL="#323130"
THEME_NEUTRAL_LIGHT="#656462"
THEME_NEUTRAL_DARK="#1F1E1D"
SETTINGS_INFORMATION="<h2>BAAT</h2><div>Bookmarklet Accessibility Audit Tool v@VERSION@</div><p>BAAT is a tool for running automatic accessibility testing scripts directly in the browser and inspecting the results.</p><p>You can find the documentation on the <a href='https://github.com/mindscreen/baat'>BAAT GitHub Page</a>.</p>"
AXE_MIN_URL="https://baat.mscr.it/axe.min.js"
AXE_MIN_URL="https://cdn.jsdelivr.net/npm/axe-core/axe.min.js"
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
node_modules/
build/
intermediate/
.idea/
intermediate/
8 changes: 8 additions & 0 deletions .idea/baat.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

116 changes: 116 additions & 0 deletions .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions extras/iconset.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "baat",
"version": "1.3-alpha",
"version": "1.2.1",
"description": "Axe frontend for running axe-core tests directly in the Browser",
"main": "index.js",
"scripts": {
Expand Down
21 changes: 1 addition & 20 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,12 @@ export const config = {
defaultSettings: {
hiddenTags: [] as string[],
hiddenImpacts: [ 'moderate', 'minor' ],
hiddenResults: [] as string[],
autorun: false,
differenceMode: false,
developer: false,
showAdditionalInformation: false,
},
size: {
width: 400,
height: 650,
}
};

export const settingNames = {
hiddenTags: 'hiddenTags',
hiddenImpacts: 'hiddenImpacts',
hiddenResults: 'hiddenResults',
autorun: 'autorun',
differenceMode: 'differenceMode',
developer: 'developer',
showAdditionalInformation: 'showAdditionalInformation',
}

export const localStorageKeys = {
coreScript: 'baat_core_script',
settings: 'baat_settings',
history: 'baat_history',
view: 'baat_view',
}
};
52 changes: 12 additions & 40 deletions src/core/BAAT.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,10 @@
import { createScript } from '../util/dom'
import {config, localStorageKeys, settingNames} from '../config'
import { config } from '../config'
import { axeExists } from '../util/axe'
import * as axe from 'axe-core'
import {
AxeRunCompleted,
BAATEvent,
BAATView,
SettingsChanged,
ViewChanged,
Result,
StatusChange,
HistoryEntry
} from '../types'
import { AxeRunCompleted, BAATEvent, BAATView, SettingsChanged, ViewChanged, Result, StatusChange } from '../types'
import { baact } from '../../baact/baact'
import { highlightContainer } from './highlight'
import {convertViolationToHistoryEntry} from "../util/history";

export class BAAT extends EventTarget {
private static instance: BAAT;
Expand All @@ -30,13 +21,13 @@ export class BAAT extends EventTarget {
super();

const localStorage = window.localStorage
const possibleScript = localStorage.getItem(localStorageKeys.coreScript)
const possibleScript = localStorage.getItem('baat_core_script')

try {
this.settings = JSON.parse(localStorage.getItem(localStorageKeys.settings) ?? '{}')
this.settings = JSON.parse(localStorage.getItem('baat_settings') ?? '{}')
} catch (e) {}

this.addEventListener(BAATEvent.ChangeCore, () => { if (this.getSetting(settingNames.autorun) && axeExists()) { window.setTimeout(() => { this.runAxe() }, 100) }})
this.addEventListener(BAATEvent.ChangeCore, () => { if (this.getSetting('autorun') && axeExists()) { window.setTimeout(() => { this.runAxe() }, 100) }})

if (possibleScript) {
this.createScript(possibleScript)
Expand All @@ -50,7 +41,7 @@ export class BAAT extends EventTarget {

}

this._view = BAATView[(localStorage.getItem(localStorageKeys.view) ?? BAATView.Settings.toString()) as keyof typeof BAATView]
this._view = BAATView[(localStorage.getItem('baat_view') ?? BAATView.Settings.toString()) as keyof typeof BAATView]
if (!axeExists()) {
this._view = BAATView.Settings
}
Expand All @@ -61,7 +52,7 @@ export class BAAT extends EventTarget {
if (script.includes('axe') && script.endsWith(';')) {
new Promise((resolve) => {
createScript(script, 'axeScript')
if (writeToStorage) localStorage.setItem(localStorageKeys.coreScript, script)
if (writeToStorage) localStorage.setItem('baat_core_script', script)
this.dispatchEvent(new CustomEvent(BAATEvent.ChangeCore, { detail: { source } }))
resolve()
})
Expand All @@ -74,7 +65,7 @@ export class BAAT extends EventTarget {
unloadAxe() {
// @ts-ignore
axe = null
localStorage.setItem(localStorageKeys.coreScript, "")
localStorage.setItem('baat_core_script', "")
this.dispatchEvent(new CustomEvent(BAATEvent.ChangeCore, { detail: { source: '' } }))
}

Expand Down Expand Up @@ -106,28 +97,11 @@ export class BAAT extends EventTarget {
}))

new Promise((resolve) => {
localStorage.setItem(localStorageKeys.settings, JSON.stringify(this.settings))
localStorage.setItem('baat_settings', JSON.stringify(this.settings))
resolve()
})
}

addHistory(violations: Result[]) {
const history = localStorage.getItem(localStorageKeys.history)
const historyArray = history ? JSON.parse(history) : []
const newEntry: HistoryEntry = convertViolationToHistoryEntry(violations);
historyArray.push(newEntry);
localStorage.setItem(localStorageKeys.history, JSON.stringify(historyArray))
}

getHistory(): HistoryEntry[] {
const history = localStorage.getItem(localStorageKeys.history)
return history ? JSON.parse(history) : []
}

clearHistory() {
localStorage.setItem(localStorageKeys.history, JSON.stringify([]))
}

dispatchStatusEvent(message: string) {
this.dispatchEvent(new CustomEvent<StatusChange>(BAATEvent.StatusChange, { detail: { message } }))
}
Expand Down Expand Up @@ -161,7 +135,7 @@ export class BAAT extends EventTarget {
let violations = results.violations as Result[]

if (results.violations.length) {
if (this.getSetting(settingNames.developer))
if (this.getSetting('developer'))
console.log('violations', violations)

/*violations.forEach((violation) => {
Expand All @@ -177,8 +151,6 @@ export class BAAT extends EventTarget {

this.dispatchStatusEvent('')

this.addHistory(violations);

this.lastResults = violations
this.fullReport = results
this._hasRun = true;
Expand All @@ -193,7 +165,7 @@ export class BAAT extends EventTarget {
set view(value: BAATView) {
this._view = value
this.dispatchEvent(new CustomEvent<ViewChanged>(BAATEvent.ChangeView,{ detail: { view: value }}))
localStorage.setItem(localStorageKeys.view, value.toString())
localStorage.setItem('baat_view', value.toString())
}

get hasRun(): boolean {
Expand Down
Loading

0 comments on commit ff91464

Please sign in to comment.