Welcome guest, is this your first visit? Create Account now to join.
Results 1 to 3 of 3

This is a discussion on How do you display version inside manifest within the Plugins Development section, part of the Chrome Plugins category: Anyone know how to extract the version that is inside the "manifest.json" dynamically at runtime? Eg is it possible to ...


  1. #1
    twinsen is offline Member
    Join Date
    Aug 2009
    Posts
    31

    Default [solved] How do you display version inside manifest

    Anyone know how to extract the version that is inside the "manifest.json" dynamically at runtime?

    Eg is it possible to do this?
    alert("Version: "+extension.version);
    Last edited by twinsen; 08-16-2009 at 10:53 AM.

  2. #2
    twinsen is offline Member
    Join Date
    Aug 2009
    Posts
    31

    Default XMLHttpRequest solution

    I found a way. Post if you find a simpler way. Using this technique you can read data from any txt file.
    Code:
    var req = new XMLHttpRequest();     
    req.open('GET', "manifest.json");
    req.onreadystatechange = function()
    {
    	if (req.readyState == 4)
    	{
    		var txt = req.responseText;
    		// Note: In the extension, chrome reorders it with version last like this:
    		//   "version": "0.13"
    		//}
    		txt = txt.substring(txt.indexOf("version"));
    		if (txt.indexOf(",")!=-1)
    		{
    			// If you put version earlier in the manifest this cuts everything 
    			// after the ",". This only applies if you open it directly and 
    			// not via the extension.
    			txt = txt.substring(0,txt.indexOf(","));
    		}
    		txt = txt.replace("version","");
    		txt = txt.replace(/\"/g,"");
    		txt = txt.replace(/:/g,"");
    		txt = txt.replace(/}/g,"");
    		txt = txt.replace(/\s/g,"");
    		g_version = parseFloat(txt);
    		alert(g_version);
    	}
    }
    req.send("");

  3. #3
    OpenNingia is offline Senior Member
    Join Date
    Jul 2009
    Posts
    123

    Default

    Quote Originally Posted by twinsen View Post
    I found a way. Post if you find a simpler way. Using this technique you can read data from any txt file.
    Code:
    var req = new XMLHttpRequest();     
    req.open('GET', "manifest.json");
    req.onreadystatechange = function()
    {
    	if (req.readyState == 4)
    	{
    		var txt = req.responseText;
    		// Note: In the extension, chrome reorders it with version last like this:
    		//   "version": "0.13"
    		//}
    		txt = txt.substring(txt.indexOf("version"));
    		if (txt.indexOf(",")!=-1)
    		{
    			// If you put version earlier in the manifest this cuts everything 
    			// after the ",". This only applies if you open it directly and 
    			// not via the extension.
    			txt = txt.substring(0,txt.indexOf(","));
    		}
    		txt = txt.replace("version","");
    		txt = txt.replace(/\"/g,"");
    		txt = txt.replace(/:/g,"");
    		txt = txt.replace(/}/g,"");
    		txt = txt.replace(/\s/g,"");
    		g_version = parseFloat(txt);
    		alert(g_version);
    	}
    }
    req.send("");
    a better way would be to evaluate the manifest ( it's Json ):

    Code:
    var req = new XMLHttpRequest();     
    req.open('GET', "manifest.json");
    req.onreadystatechange = function()
    {
    	if (req.readyState == 4)
    	{
    		var manifest = eval('(' + req.responseText + ')' );
                    alert(manifest.version);
            }
    }
    
    req.send("");

Similar Threads

  1. [New Ext] PageRank Display
    By nemrod in forum Chrome Plugins
    Replies: 14
    Last Post: 12-08-2009, 11:37 PM
  2. [New Ext] Alexa Rank Display
    By nemrod in forum Chrome Plugins
    Replies: 3
    Last Post: 08-18-2009, 05:19 PM
  3. New Dev Version: 3.0.187.0
    By devilslackey in forum Chrome Talk
    Replies: 3
    Last Post: 06-12-2009, 04:51 AM
  4. Login Boxes display differently in chrome and safari
    By christop049 in forum Chrome Troubleshooting
    Replies: 3
    Last Post: 06-04-2009, 01:10 PM
  5. Latest Version of AdSweep (1.5.8) Now Available
    By StevePaul in forum Chrome Plugins
    Replies: 0
    Last Post: 05-08-2009, 02:07 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
  •