Messing with Anchors and LocalStorage for Options page

Messing with Anchors and LocalStorage for Options page

I'm trying to put together a chrome extension. The options page is really messy so far. Can somebody help me figure out what's going on?

The first time I load it, the links toggle like they're supposed to. But when I reload it, it fails to highlight the stuff localStorage was supposed to have remembered, and the anchors don't seem to be working. The problem might be with localStorage, which, I guess isn't jQuery... But I need help, and whoever is helping me needs to be able to read this stuff, so I figured this was the place to ask.

Do note that this only needs to run in Webkit. Yay for not worrying about IE6!

  1. <html>
  2. <head><title>Concerto for Chrome Options</title></head>

  3. <script type="text/javascript"
  4. src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js">
  5. </script>

  6. <style type="text/css">
  7. .feed {
  8. text-decoration: none;
  9. color: #DD0000;
  10. }
  11. .on {
  12. color: #00BB00;
  13. }
  14. #status{
  15. display:none;
  16. }
  17. </style>

  18. <script type="text/javascript">

  19. jQuery(document).ready(prepare_page);

  20. function prepare_page(){
  21. restore_options();
  22. jQuery(".feed").click(toggleFeed);
  23. }

  24. function toggleFeed(e) {
  25. e.preventDefault();
  26. $(this).toggleClass("on");
  27. }

  28. // Saves options to localStorage.
  29. function save_options() {
  30. var feeds = [];
  31. jQuery(".on").each(function() { feeds.push($(this).attr("id")); });
  32. localStorage.feeds = feeds;
  33. // Update status to let user know options were saved.
  34. $("#status").show();
  35. setTimeout(hideStatus, 800);
  36. function hideStatus() { $("#status").hide("fast"); }
  37. }

  38. // Restores select box state to saved value from localStorage.
  39. function restore_options() {
  40. var feeds = localStorage.feeds;
  41. if(!feeds) { return; }
  42. var count = 0;
  43. while (count < feeds.length) {
  44. jQuery("#"+feeds[count]).addClass("on");
  45. count = count+1;
  46. }
  47. }

  48. </script>

  49. <body>

  50. <p>Desired Feeds: <br/>
  51. <a href="" class="feed" id="feed1">Feed 1</a><br/>
  52. <a href="" class="feed" id="feed2">Feed 2</a><br/>
  53. <a href="" class="feed" id="feed3">Feed 3</a><br/>
  54. <a href="" class="feed" id="feed4">Feed 4</a><br/>
  55. <br/></p>
  56. <button onclick="save_options()">Save</button>
  57. <p id="status">Options Saved!</p>
  58. </body>
  59. </html>