src/options.js
/**
 * Saves the entered data textarea to synchronized storage.
 */
Saves the entered data textarea to synchronized storage.
Saves the entered data textarea to synchronized storage .
function textareaSave () {
  let textarea = document.getElementById('domainFilter').value
  textarea = textarea.replace(/[\n\r]/g, ',') 
  textarea = textarea.split(',').map(s => s.trim()) 
  for (let i = textarea.length - 1; i >= 0; i--) {
    const dotCount = (textarea[i].match(/./g) || []).length
    if (dotCount === 0) {
      textarea.splice(i, 1)
      continue
    } else if (dotCount > 1) {
      textarea[i] = textarea[i].replace(/^\w+:?\/\/(?:www\.)?\.?([^/]+)\/?.*$/, '$1').split('.') 
      if (textarea[i][textarea[i].length - 1] === 'uk') {
        textarea[i] = textarea[i].slice(-3).join('.')
      } else {
        textarea[i] = textarea[i].slice(-2).join('.')
      }
    }
  }
  chrome.storage.sync.set({ domainfilter: textarea })
}
function textareaSave ( ) { let textarea = document . getElementById ( 'domainFilter' ) . value textarea = textarea . replace ( / [\n\r] / g , ',' ) textarea = textarea . split ( ',' ) . map ( s => s . trim ( ) ) for ( let i = textarea . length - 1 ; i >= 0 ; i -- ) { const dotCount = ( textarea [ i ] . match ( / . / g ) || [ ] ) . length if ( dotCount === 0 ) { textarea . splice ( i , 1 ) continue } else if ( dotCount > 1 ) { textarea [ i ] = textarea [ i ] . replace ( / ^\w+:?\/\/(?:www\.)?\.?([^/]+)\/?.*$ / , '$1' ) . split ( '.' ) if ( textarea [ i ] [ textarea [ i ] . length - 1 ] === 'uk' ) { textarea [ i ] = textarea [ i ] . slice ( - 3 ) . join ( '.' ) } else { textarea [ i ] = textarea [ i ] . slice ( - 2 ) . join ( '.' ) } } } chrome . storage . sync . set ( { domainfilter : textarea } ) }
Saves the entered data textarea to synchronized storage.
Saves the entered data textarea to synchronized storage .
// replaced newline with comma // Split and trim array // Removes www and everything after domain name // Fix for uk domains, cant handel domain suffixes with only ".uk" but will handle domains like ".co.uk"