Advertisement
SteveGarman

CheckPlaystoreVersion

Jul 15th, 2016
931
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var packageName = "com.smartphoneremote.androidscriptfree";
  2. var path = "/store/apps/details";
  3. var params="id=" + packageName;
  4.  
  5. //Called when application is started.
  6. function OnStart()
  7. {
  8.     //Create a layout with objects vertically centered.
  9.     lay = app.CreateLayout( "linear", "VCenter,FillXY" );  
  10.  
  11.     //Create a text label and add it to layout.
  12.     txt = app.CreateText( packageName );
  13.     //txt.SetTextSize( 32 );
  14.     lay.AddChild( txt );
  15.    
  16.     //Add layout to app.   
  17.     app.AddLayout( lay );
  18.     app.ShowProgress( null, "NoDim" );
  19.     app.HttpRequest( "GET", "https://play.google.com", path, params, HandleReply, "" );
  20. }
  21. function HandleReply( error, response )
  22. {
  23.     if( !error )
  24.     {
  25.          analyze(response)
  26.     }
  27.  
  28.     else
  29.     {
  30.         app.HideProgress();
  31.         app.ShowPopup( "Error: " + response);
  32.     }
  33. }
  34. function analyze(rst)
  35. {
  36.      //index of the div tag with ' itemprop="softwareVersion" ' attribute.
  37.      ver_tag_index = rst.indexOf( "itemprop=\"softwareVersion\">" );
  38.  
  39.      app.HideProgress();
  40.      //If there's no such tag.    
  41.      if( ver_tag_index == -1) {
  42.        alert("can't find the version number");
  43.  
  44.        //Nothing useful ahead. Get out of the function ( won't execute instructions in this function further ).
  45.        return;
  46.      }
  47.  
  48.      //cut rst from the index of version tag.
  49.      crst = rst.substr( ver_tag_index + 27 );
  50.      
  51.      //index of first angle bracket in crst.
  52.      angle_index = crst.indexOf("<");
  53.      
  54.      //cut crst from start to the angi.
  55.      crst = crst.substr(0, angle_index );
  56.  
  57.      //Remove whitespaces ( if any ) from the beginning and the end of the crst.
  58.      //This is the version number.
  59.      ver_num = crst.trim();
  60.      
  61.      //If version number "varies with device".
  62.      if( ver_num == "Varies With Device") alert( "Version depends on device");
  63.      
  64.      txt.SetTextSize( 32 );
  65.      txt.SetText( ver_num );
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement