function main() {
  if (storageEnabled && window.localStorage.readerList)
      feedReaderList = JSON.parse(window.localStorage.readerList);
  if (!feedReaderList)
    feedReaderList = defaultReaderList();

  // Populate the list of readers.
  var readerDropdown = document.getElementById('readerDropdown');
  for (i = 0; i < feedReaderList.length; ++i) {
    readerDropdown.options[i] = new Option(feedReaderList[i].description, i);
    if (storageEnabled && isDefaultReader(feedReaderList[i].url))
      readerDropdown.selectedIndex = i;
  }

  if (storageEnabled) {
    // Add the "Manage..." entry to the dropdown and show the checkbox asking
    // if we always want to use this reader in the future (skip the preview).
    readerDropdown.options[i] =
        new Option(chrome.i18n.getMessage("rss_subscription_manage_label"), "");
    document.getElementById('alwaysUseSpan').style.display = "block";
  }

  // Set the token.
  var tokenArray  = new Uint32Array(4);
  crypto.getRandomValues(tokenArray);
  token = [].join.call(tokenArray);

  // Now fetch the data.
  req = new XMLHttpRequest();
  if (synchronousRequest) {
    // Tests that load the html page directly through a file:// url don't have
    // access to the js and css from the frame so we must load them first and
    // inject them into the src for the iframe.
    req.open("GET", "style.css", false);
    req.send(null);

    styleSheet = "<style>" + req.responseText + "</style>";

    req.open("GET", "iframe.js", false);
    req.send(null);

    if (req.responseText.indexOf('//') != -1) {
      console.log('Error: Single-line comment(s) found in iframe.js');
    } else {
      frameScript = "<script>" +
                    req.responseText +
                    "<" + "/script>";
    }
  } else {
    // Normal loading just requires links to the css and the js file.
    styleSheet = "<link rel='stylesheet' type='text/css' href='" +
                    chrome.extension.getURL("style.css") + "'>";
    frameScript = "<script src='" + chrome.extension.getURL("iframe.js") +
                  "'></" + "script>";
  }

  req.onload = handleResponse;
  req.onerror = handleError;
  req.open("GET", feedUrl, !synchronousRequest);
  // Not everyone sets the mime type correctly, which causes handleResponse
  // to fail to XML parse the response text from the server. By forcing
  // it to text/xml we avoid this.
  req.overrideMimeType('text/xml');
  req.send(null);

  document.getElementById('feedUrl').href = 'view-source:' + feedUrl;
}
/**
* The main function. Sets up the selection list for possible readers and
* fetches the data.
*/
The main function. Sets up the selection list for possible readers and
fetches the data.
The main function . Sets up the selection list for possible readers and fetches the data .
function main() {
  if (storageEnabled && window.localStorage.readerList)
      feedReaderList = JSON.parse(window.localStorage.readerList);
  if (!feedReaderList)
    feedReaderList = defaultReaderList();
  var readerDropdown = document.getElementById('readerDropdown');
  for (i = 0; i < feedReaderList.length; ++i) {
    readerDropdown.options[i] = new Option(feedReaderList[i].description, i);
    if (storageEnabled && isDefaultReader(feedReaderList[i].url))
      readerDropdown.selectedIndex = i;
  }
  if (storageEnabled) {
    readerDropdown.options[i] =
        new Option(chrome.i18n.getMessage("rss_subscription_manage_label"), "");
    document.getElementById('alwaysUseSpan').style.display = "block";
  }
  var tokenArray  = new Uint32Array(4);
  crypto.getRandomValues(tokenArray);
  token = [].join.call(tokenArray);
  req = new XMLHttpRequest();
  if (synchronousRequest) {
    req.open("GET", "style.css", false);
    req.send(null);
    styleSheet = "<style>" + req.responseText + "</style>";
    req.open("GET", "iframe.js", false);
    req.send(null);
    if (req.responseText.indexOf('//') != -1) {
      console.log('Error: Single-line comment(s) found in iframe.js');
    } else {
      frameScript = "<script>" +
                    req.responseText +
                    "<" + "/script>";
    }
  } else {
    styleSheet = "<link rel='stylesheet' type='text/css' href='" +
                    chrome.extension.getURL("style.css") + "'>";
    frameScript = "<script src='" + chrome.extension.getURL("iframe.js") +
                  "'></" + "script>";
  }
  req.onload = handleResponse;
  req.onerror = handleError;
  req.open("GET", feedUrl, !synchronousRequest);
  req.overrideMimeType('text/xml');
  req.send(null);
  document.getElementById('feedUrl').href = 'view-source:' + feedUrl;
}
function main ( ) { if ( storageEnabled && window . localStorage . readerList ) feedReaderList = JSON . parse ( window . localStorage . readerList ) ; if ( ! feedReaderList ) feedReaderList = defaultReaderList ( ) ; var readerDropdown = document . getElementById ( 'readerDropdown' ) ; for ( i = 0 ; i < feedReaderList . length ; ++ i ) { readerDropdown . options [ i ] = new Option ( feedReaderList [ i ] . description , i ) ; if ( storageEnabled && isDefaultReader ( feedReaderList [ i ] . url ) ) readerDropdown . selectedIndex = i ; } if ( storageEnabled ) { readerDropdown . options [ i ] = new Option ( chrome . i18n . getMessage ( "rss_subscription_manage_label" ) , "" ) ; document . getElementById ( 'alwaysUseSpan' ) . style . display = "block" ; } var tokenArray = new Uint32Array ( 4 ) ; crypto . getRandomValues ( tokenArray ) ; token = [ ] . join . call ( tokenArray ) ; req = new XMLHttpRequest ( ) ; if ( synchronousRequest ) { req . open ( "GET" , "style.css" , false ) ; req . send ( null ) ; styleSheet = "<style>" + req . responseText + "</style>" ; req . open ( "GET" , "iframe.js" , false ) ; req . send ( null ) ; if ( req . responseText . indexOf ( '//' ) != - 1 ) { console . log ( 'Error: Single-line comment(s) found in iframe.js' ) ; } else { frameScript = "<script>" + req . responseText + "<" + "/script>" ; } } else { styleSheet = "<link rel='stylesheet' type='text/css' href='" + chrome . extension . getURL ( "style.css" ) + "'>" ; frameScript = "<script src='" + chrome . extension . getURL ( "iframe.js" ) + "'></" + "script>" ; } req . onload = handleResponse ; req . onerror = handleError ; req . open ( "GET" , feedUrl , ! synchronousRequest ) ; req . overrideMimeType ( 'text/xml' ) ; req . send ( null ) ; document . getElementById ( 'feedUrl' ) . href = 'view-source:' + feedUrl ; }
The main function.
The main function .
// Populate the list of readers. // Add the "Manage..." entry to the dropdown and show the checkbox asking // if we always want to use this reader in the future (skip the preview). // Set the token. // Now fetch the data. // Tests that load the html page directly through a file:// url don't have // access to the js and css from the frame so we must load them first and // inject them into the src for the iframe. // Normal loading just requires links to the css and the js file. // Not everyone sets the mime type correctly, which causes handleResponse // to fail to XML parse the response text from the server. By forcing // it to text/xml we avoid this.