Skip to content

Commit

Permalink
feat: different styles for different components
Browse files Browse the repository at this point in the history
  • Loading branch information
dbajpeyi committed Sep 26, 2024
1 parent 999c3a8 commit ed50452
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions src/features/password-import.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import ContentFeature from '../content-feature'
import { DDGProxy, DDGReflect, withExponentialBackoff } from '../utils'
import { getElement } from './broker-protection/utils'


const URL_ELEMENT_MAP = {
'/': {
name: 'cogWheel',
Expand All @@ -12,18 +11,18 @@ const URL_ELEMENT_MAP = {
}
},
'/options': {
name: 'exportButton',
name: 'exportButton',
style: {
scale: 1.01,
backgroundColor: 'rgba(0, 39, 142, 0.5)'
}
},
'/intro': {
name: 'signInButton',
name: 'signInButton',
style: {
scale: 1.5,
backgroundColor: 'rgba(0, 39, 142, 0.3)'
},
backgroundColor: 'rgba(0, 39, 142, 0.5)'
}
}
}

Expand All @@ -40,9 +39,9 @@ export default class PasswordImport extends ContentFeature {
inline: 'center'
}) // Scroll into view
const keyframes = [
{ backgroundColor: 'rgba(0, 0, 255, 0)', offset: 0 }, // Start: transparent
{ backgroundColor: style.backgroundColor, offset: 0.5, transform: `scale(${style.scale})` }, // Midpoint: blue with 50% opacity
{ backgroundColor: 'rgba(0, 0, 255, 0)', offset: 1 } // End: transparent
{ backgroundColor: 'rgba(0, 0, 255, 0)', offset: 0 }, // Start: transparent
{ backgroundColor: style.backgroundColor, offset: 0.5, transform: `scale(${style.scale})` }, // Midpoint: blue with 50% opacity
{ backgroundColor: 'rgba(0, 0, 255, 0)', offset: 1 } // End: transparent
]

// Define the animation options
Expand All @@ -60,7 +59,7 @@ export default class PasswordImport extends ContentFeature {
}

findSignInButton () {
return document.querySelector('[aria-label="Sign in"]:not([target="_top"])');
return document.querySelector('[aria-label="Sign in"]:not([target="_top"])')
}

async findElement (name) {
Expand Down Expand Up @@ -90,7 +89,7 @@ export default class PasswordImport extends ContentFeature {
const historyMethodProxy = new DDGProxy(this, History.prototype, 'pushState', {
async apply (target, thisArg, args) {
const pageURL = args[2].split('?')[0]
const {name, style} = URL_ELEMENT_MAP[pageURL]
const { name, style } = URL_ELEMENT_MAP[pageURL]
const element = await findElement(name)
animateElement(element, style)
return DDGReflect.apply(target, thisArg, args)
Expand All @@ -100,14 +99,14 @@ export default class PasswordImport extends ContentFeature {
// listen for popstate events in order to run on back/forward navigations
window.addEventListener('popstate', async () => {
console.log('pushState URL', window.location.pathname)
const {name, style} = URL_ELEMENT_MAP[window.location.pathname]
const { name, style } = URL_ELEMENT_MAP[window.location.pathname]
const element = await findElement(name)
animateElement(element, style)
})

document.addEventListener('DOMContentLoaded', async () => {
console.log('pushState URL', window.location.pathname)
const {name, style} = URL_ELEMENT_MAP[window.location.pathname]
const { name, style } = URL_ELEMENT_MAP[window.location.pathname]
const element = await findElement(name)
animateElement(element, style)
})
Expand Down

0 comments on commit ed50452

Please sign in to comment.