Results 1 to 8 of 8

Thread: [Java] How to use Google Chrome's .storage API?

  1. #1
    CaptainNight's Avatar
    Joined
    Jul 2014
    Posts
    306
    Userbars
    7
    Thanks
    81
    Thanked
    199/84
    DL/UL
    29/3
    Mentioned
    27 times
    Time Online
    12d 5h 51m
    Avg. Time Online
    4m

    [Java] How to use Google Chrome's .storage API?

    So uh, im trying to make a google chrome extension that I eventually plan on sharing with this forum. This is literally my first ever coding project besides "Hello World" stuff in a highschool class several years ago. So excuse how noob I am.

    All im trying to do is make a semi-legit RS Chrome extension that greys out junk items and highlights UBs.

    Right now im just abusing IF loops and have all these shop lists directly in the content_script. So blah blah IF =shop&obj_type=30 THEN it sets var Junk to be Spooky Foods junk list and var UB to a Spooky Foods UB list.

    Then I have it where it simply iterates all the image URLs through the var Junk and greys out all the Junk images, then iterates through UB list and expands those images. That leaves the junk items greyed out, UBs highly visible, and the other profitable items (like 5k-99k) normal.

    This is functional right now and does exactly what I want it to do for the shops I have loaded. HOWEVER, the lists are typed directly into the content script and immutable :/ If I want to add or remove items I have to physically open up my extension files and its really annoying to have to dredge through the wall of image URLs to add to them. Not to mention that I have to repack the extension every time.

    Ideally I would have something like in adblock where I can right click and add/remove to Junk/UB list for that particular shop, and also have some way to load text files provided by the user. Its also stupidly inefficient right now since it iterates through the whole list for every image, but that is not too bad. Mostly I want to have the read to and from storage functionality and I can figure out the rest from there. Iv found decent tutorials for the other stuff.

    I can't for the life of me figure out how to host the lists NOT directly within the content_script. I would like to be able to edit the lists individually. I tried mucking around in adblockplus's source code for help but I can't actually find the functions that write to lists? Obviously it stores the whitelists/blacklists somewhere. The chrome documentation talks about the storage API but it doesn't tell me how to actually use it..

    If someone could point me in the right direction to a noob tutorial that would be nice. Or provide a very simple example of using the API to store something in a list and then how to access that list?

    It (you need an account to see links) right now and is kinda shitty but it actually REALLY helps in restocking semi-legit. Its like training wheels. Even if no one else ever uses it I think its a good project for myself.
    Last edited by CaptainNight; 11-19-2014 at 10:36 AM.
    [CENTER]Lazy and Paranoid

  2. The Following 3 Users Say Thank You to CaptainNight For This Useful Post:

    Ghosts (11-19-2014),j03 (11-19-2014),reestoquer (11-19-2014)

  3. #2
    Saiyan Race
    j03's Avatar
    Joined
    Dec 2011
    Posts
    13,756
    Userbars
    176
    Thanks
    5,936
    Thanked
    33,184/6,625
    DL/UL
    23/36
    Mentioned
    3,871 times
    Time Online
    564d 11h 47m
    Avg. Time Online
    3h 13m
    This is looking really good and with the new restock system in place, it will definitely have some interest from other members of the forum. Unfortunately, I do not have experience developing chrome extensions. Maybe someone else can help..
    (you need an account to see links)
    (you need an account to see links)(you need an account to see links)

    ------------------------
    [02/24/2013] Stealth CORE is made into the first standalone Neopets auto-player.
    ------------------------


  4. #3
    reestoquer's Avatar
    Joined
    Nov 2012
    Posts
    198
    Userbars
    2
    Thanks
    37
    Thanked
    27/16
    DL/UL
    14/0
    Mentioned
    38 times
    Time Online
    12d 10h 30m
    Avg. Time Online
    4m
    Wow nice job. You intends to make available in this way for other users to work upon?

  5. #4
    CaptainNight's Avatar
    Joined
    Jul 2014
    Posts
    306
    Userbars
    7
    Thanks
    81
    Thanked
    199/84
    DL/UL
    29/3
    Mentioned
    27 times
    Time Online
    12d 5h 51m
    Avg. Time Online
    4m
    lol how helpful Joe ;P

    I had hoped someone on this forum would be able to help but I guess the next step is go to a Chrome extension dev forum or something and hope they don't laugh at me too much for making a neopets tool.

    I could also just do it in firefox but from what I see, its mostly the same. It has a strange storage API. Plus I personally use Chrome and im not wasting my time making a tool for a browser that I dislike Especially since I am just now learning to code and every small thing takes forever. Baby steps. When its finished ill try to port it though since I know lots of people use that... or ill give it to someone who can port it for me.

    I do plan on putting it on clraik. I don't know the procedure for that but yeah. I think its something we "need" around here. Most people who semi-legit restock seem to use the adblock lists, which are kinda clunky. And there is no way to make it only block the images on the shop page and not say, in your inventory or in the trades. Plus sometimes I want to buy unprofitable items and not have all the images hidden... just greyed out.

    ANYWAY.

    Ill figure this out eventually.

    EDIT:

    So if no one actively KNOWS chrome, do any of you think you could de-jargon the documentation? It doesn't look very long. Sorry I am a noob.

    (you need an account to see links) - basic overview of chrome extensions themselves

    (you need an account to see links) - storage API stuff

    (you need an account to see links)

    (you need an account to see links) - This is a question someone else asked that I think I understand the API itself, but still doesn't help with storing a list.

    It assumes I already know some things that I do not know. I can see how to store a value, but how do I store and edit a list in the API? I don't know how to compare the individual items/images I have to the stored values to actually check if its in the storage. If that even makes sense. The examples look like storing settings and individual bits of info.
    Last edited by CaptainNight; 11-19-2014 at 04:14 PM.
    [CENTER]Lazy and Paranoid

  6. #5
    Saiyan Race
    j03's Avatar
    Joined
    Dec 2011
    Posts
    13,756
    Userbars
    176
    Thanks
    5,936
    Thanked
    33,184/6,625
    DL/UL
    23/36
    Mentioned
    3,871 times
    Time Online
    564d 11h 47m
    Avg. Time Online
    3h 13m
    Maybe post some code snippets and I might be able to help. Working from one language to another isn't very hard.
    (you need an account to see links)
    (you need an account to see links)(you need an account to see links)

    ------------------------
    [02/24/2013] Stealth CORE is made into the first standalone Neopets auto-player.
    ------------------------


  7. #6

    Joined
    Sep 2012
    Posts
    39
    Userbars
    0
    Thanks
    0
    Thanked
    31/15
    Mentioned
    11 times
    Time Online
    2d 8h 38m
    Avg. Time Online
    N/A
    You might want to correct your title, Chrome uses a subset of Javascript for extensions (not Java which is a completely different and unrelated language).

    As far as the API goes:

    Code:
    function saveChanges() {
        // Get a value saved in a form.
        var theValue = textarea.value;
        // Check that there's some code there.
        if (!theValue) {
          message('Error: No value specified');
          return;
        }
        // Save it using the Chrome extension storage API.
        chrome.storage.sync.set({'value': theValue}, function() {
          // Notify that we saved.
          message('Settings saved');
        });
    }
    The above code is taking the content of a TextArea HTML element (which is assumed to exist as part of a form) and saving it to Chrome's internal storage. In the above case, they are using the Sync API which stores the information in the cloud and travels with the user.

    For saving, they are passing key/value pairs along with a callback function. It looks like the keys are string values used for identifying stored information and the values can be basically anything that can be serialized by JSON. So, if you're storing a list of items, I'd imagine you'd want to do this:

    Code:
    function saveItems() {
        // The list of items
        items = ['Carrot', 'Yellow Snowball', 'Poop']
         // Save them
        chrome.storage.sync.set({'General Shop': items});
    }
    And to retrieve it later:

    Code:
    function getItems() {
        // Get the items and do something....
        items = chrome.storage.sync.get('General Shop')
    }
    However, as far as I can tell you won't be able to edit these values outside of your extension (as they will be stored in the cloud). If you go this route you'd need to code a user interface for editing your saved lists (which wouldn't be too difficult).

  8. The Following User Says Thank You to AliasXNeo For This Useful Post:

    CaptainNight (11-19-2014)

  9. #7
    CaptainNight's Avatar
    Joined
    Jul 2014
    Posts
    306
    Userbars
    7
    Thanks
    81
    Thanked
    199/84
    DL/UL
    29/3
    Mentioned
    27 times
    Time Online
    12d 5h 51m
    Avg. Time Online
    4m
    Ahhhhhhh so I can just save the list under some name??? Like 'General Shop Junk'?? I kept trying to store the list itself as a var in the local part of the API and it wouldn't work and I was getting frustrated. Haha.

    I can easily just call the function and assign the list to the var junk/UB im already using. Perfect.

    I had already planned on making some kind of interface for adding in lists. In the last few hours I found some good info on the GUIs that I can adapt to this really well. For now I can at least have it load some "default" lists on the first run time I think.

    Thank you so much. Iv only used python prior to this and it was years ago so a lot of this looks like moon runes to me. I want to rep you 20 times.

    If I hit another wall, ill be back
    [CENTER]Lazy and Paranoid

  10. #8

    Joined
    Sep 2012
    Posts
    39
    Userbars
    0
    Thanks
    0
    Thanked
    31/15
    Mentioned
    11 times
    Time Online
    2d 8h 38m
    Avg. Time Online
    N/A
    Quote Originally Posted by flytenyte View Post
    Ahhhhhhh so I can just save the list under some name??? Like 'General Shop Junk'?? I kept trying to store the list itself as a var in the local part of the API and it wouldn't work and I was getting frustrated. Haha.

    I can easily just call the function and assign the list to the var junk/UB im already using. Perfect.

    I had already planned on making some kind of interface for adding in lists. In the last few hours I found some good info on the GUIs that I can adapt to this really well. For now I can at least have it load some "default" lists on the first run time I think.

    Thank you so much. Iv only used python prior to this and it was years ago so a lot of this looks like moon runes to me. I want to rep you 20 times.

    If I hit another wall, ill be back
    No worries. It might be worth your time to go through something like (you need an account to see links) to get yourself familiar with the syntax. I don't recall exactly what Chrome uses for extensions (I think it's related to Google Apps Script), but it's really nothing more than a sandboxed version of javascript (meaning certain functionalities removed for the safety of the end-user).

Posting Permissions

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