Dave Jarvis' Repositories

git clone https://repo.autonoma.ca/repo/keenwrite.com.git
const OLD_ACCENTS = [ 'rgb(246, 201, 21)', 'rgb(236, 112, 106)', ];
const NEW_ACCENTS = '#ec706a';
const BORDER_PROPS = [
  'borderTopColor',  'borderBottomColor',
  'borderLeftColor', 'borderRightColor',
];
const CHECKS = [
  {
    props: [ 'backgroundColor' ],
    set: ( el, value ) => { el.style.backgroundColor = value; }
  },
  {
    props: BORDER_PROPS,
    set: ( el, value ) => { el.style.borderColor = value; }
  },
  {
    props: [ 'color' ],
    set: ( el, value ) => { el.style.color = value; }
  }
];

function replace( oldColour ) {
  return OLD_ACCENTS.includes( oldColour ) ? NEW_ACCENTS : null;
}

function update( container ) {
  let replaced = false;

  container.querySelectorAll( '*' ).forEach( el => {
    const style = getComputedStyle( el );

    CHECKS.forEach( check => {
      replaced = check.props.some( prop => {
        const newColour = replace( style[ prop ] );
        return newColour && ( check.set( el, newColour ), true );
      }) || replaced;
    });
  });

  return replaced;
}

const container = document.querySelector( '.liberapay' );

if( !update( container ) ) {
  const observer = new MutationObserver( ( mutations, obs ) => {
    if( mutations.some( m => m.addedNodes.length ) && update( container ) ) {
      obs.disconnect();
    }
  });

  observer.observe( container, { childList: true, subtree: true, });
}