Results 1 to 6 of 6

This is a discussion on Storing global values / creating a "Settings" system within the Plugins Development section, part of the Chrome Plugins category: Hi, I was wondering, what would be the best way to create a simple settings system in a Chrome extension? ...


  1. #1
    DavidTurnbull is offline Junior Member
    Join Date
    Feb 2010
    Posts
    5

    Default Storing global values / creating a "Settings" system

    Hi,

    I was wondering, what would be the best way to create a simple
    settings system in a Chrome extension?

    All I want is there to be a "Options" page with a list of checkboxes
    and then for a content script to check the value of each box (checked
    or null) and then include or not include a bit of CSS based off that
    response.

    I'm a complete newbie when it comes to this stuff but have managed to
    make it so when I click a checkbox the value "checked" is saved in
    localStorage, and I retrieve it on the Options page, but can't seem to
    make it work with other parts of the extension. :-)

  2. #2
    Waha's Avatar
    Waha is offline Senior Member
    Join Date
    Apr 2009
    Location
    Oregon
    Posts
    788

    Default

    You can't access the localStorage of your extension from a Content Script. You will likely have to make a Background Page that will retrieve the values and tell the Content Script what's stored with communication.
    You can read this over for an idea of how communication works.
    The model I'd suggest is to make your Content Script send out a message when it runs, that the Background Page will pick up and respond with the saved data.
    ~ Projects ~
    Specialized: Carapass Auction Watcher, Kongregate Chat
    Libraries: bliplib
    Tools: manifest syntax highlighting & snippits
    ~ Happy to make extensions for pay too ;D ~
    Portfolio: Search and Share

  3. #3
    DavidTurnbull is offline Junior Member
    Join Date
    Feb 2010
    Posts
    5

    Default

    Quote Originally Posted by Waha View Post
    You can't access the localStorage of your extension from a Content Script. You will likely have to make a Background Page that will retrieve the values and tell the Content Script what's stored with communication.
    You can read this over for an idea of how communication works.
    The model I'd suggest is to make your Content Script send out a message when it runs, that the Background Page will pick up and respond with the saved data.
    Thanks for the quick and simple response. I think I've got that under control, but now I seem to have another problem.

    I'm trying to change the look of Gmail with my extension, and by using a CSS file in the manifest under content scripts that's easy enough to do and works fine. The problem arises when I try to make certain elements toggable (such as being able to disable Gmail's logo).

    For this I'm using a javascript file, also as a content script, and I have tested this code:

    document.write("<link href='../css/minimalist.css' rel='stylesheet' type='text/css' />");
    ...but although it's the same stylesheet it doesn't change the look of Gmail. at all. Any thoughts?

  4. #4
    Waha's Avatar
    Waha is offline Senior Member
    Join Date
    Apr 2009
    Location
    Oregon
    Posts
    788

    Default

    I'd first of all suggest using absolute paths in your links.
    Secondly I'd suggest to never use document.write as it's REALLY wonky.

    The best way is to just use the injectable css if that's what you want. If you want variable includes, I'd suggest using DOM commands instead.
    The equivalent would be:
    Code:
    var link = document.createElement("link");
    link.setAttribute("href",chrome.extension.getURL("css/minimalist.css"));
    link.setAttribute("rel","stylesheet");
    link.setAttribute("type","text/css");
    document.head.appendChild(link);
    It works a bit more cleanly, even if it takes more code, and it's more assured to update the browser with everything it's meaning to do.
    ~ Projects ~
    Specialized: Carapass Auction Watcher, Kongregate Chat
    Libraries: bliplib
    Tools: manifest syntax highlighting & snippits
    ~ Happy to make extensions for pay too ;D ~
    Portfolio: Search and Share

  5. #5
    DavidTurnbull is offline Junior Member
    Join Date
    Feb 2010
    Posts
    5

    Default

    I think I'm in love with you. Worked absolutely perfectly. I still have a bit to do before this version of my extension goes live but I'll definitely give you credit on the options page (could be significant if the extension's a hit). :-)

    And thanks for the other tips too.

  6. #6
    Waha's Avatar
    Waha is offline Senior Member
    Join Date
    Apr 2009
    Location
    Oregon
    Posts
    788

    Default

    lol thanks. Good luck with making a hit.
    ~ Projects ~
    Specialized: Carapass Auction Watcher, Kongregate Chat
    Libraries: bliplib
    Tools: manifest syntax highlighting & snippits
    ~ Happy to make extensions for pay too ;D ~
    Portfolio: Search and Share

Similar Threads

  1. Searched - No Luck - How to Open Chrome to the "ctrl-t" page?
    By olzab in forum Chrome Tips & Tricks
    Replies: 4
    Last Post: 02-10-2010, 03:32 PM
  2. Replies: 0
    Last Post: 02-02-2010, 05:56 PM
  3. Replies: 6
    Last Post: 09-26-2009, 04:57 PM
  4. Google Chrome "Load unpacked extension" Button Does Not Exist
    By chayimf in forum Plugins Troubleshooting
    Replies: 4
    Last Post: 09-05-2009, 10:51 AM
  5. Make a "Kill Micro$oft's ChildsPlay" option!
    By Calyp in forum Chrome Talk
    Replies: 0
    Last Post: 01-09-2009, 07:14 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •