11var skills = [ "Attack" , "Defence" , "Strength" , "Constitution" , "Ranged" , "Prayer" , "Magic" , "Cooking" , "Woodcutting" , "Fletching" , "Fishing" , "Firemaking" , "Crafting" , "Smithing" , "Mining" , "Herblore" , "Agility" , "Thieving" , "Slayer" , "Farming" , "Runecrafting" , "Hunter" , "Construction" , "Summoning" , "Dungeoneering" , "Divination" , "Invention"
2- ] ;
2+ ] ; //Used to turn skill ID's into usable names.
33
4+ /**
5+ * Adds the checks to the quest requirements.
6+ * @param {[quests] } userQuests
7+ */
48function addQuestCompletedChecks ( userQuests ) {
59 $ ( ".questreq a" ) . each ( function ( index ) {
610 if ( $ ( this ) . html ( ) . toLowerCase ( ) != "expand" || $ ( this ) . html ( ) . toLowerCase ( ) != "collapse" ) {
@@ -15,6 +19,10 @@ function addQuestCompletedChecks(userQuests){
1519 } ) ;
1620}
1721
22+ /**
23+ * Adds the checks to the skill requirements.
24+ * @param {[skillName: level] } userLevels
25+ */
1826function addLevelDetailChecks ( userLevels ) {
1927 $ ( ".questdetails-info > ul > li" ) . each ( function ( index ) {
2028 var textArr = $ ( this ) . text ( ) . split ( " " ) ;
@@ -41,19 +49,23 @@ function addLevelDetailChecks(userLevels){
4149
4250function loadUserData ( username , tries ) {
4351 loadUserQuests ( username , tries ) ;
44- loadUserStats ( username , tries ) ;
52+ loadUserSkills ( username , tries ) ;
4553}
4654
55+ /**
56+ * Get the user's quest data and pass it along to function addQuestCompleteChecks()
57+ * @param {string } username - The in-game username of the user.
58+ * @param {int } tries - The amount of tries to get userdata before giving up.
59+ */
4760function loadUserQuests ( username , tries ) {
4861 $ . ajax ( { // Get the quest data
4962 type :"GET" ,
5063 url :"https://apps.runescape.com/runemetrics/quests?user=" + username ,
5164 success : function ( msg ) {
5265 if ( msg [ "quests" ] . length == 0 ) {
5366 if ( tries <= 0 ) {
54- console . log ( "Could not fetch quest data!" ) ;
67+ console . error ( "Could not fetch quest data!" ) ;
5568 } else {
56- console . log ( "Trying quests again!" ) ;
5769 loadUserData ( username , tries - 1 ) ;
5870 }
5971 } else {
@@ -68,40 +80,49 @@ function loadUserQuests(username, tries){
6880 } ) ;
6981}
7082
71- function loadUserStats ( username , tries ) {
83+ /**
84+ * Loads the users skills and passes it along to the function addLevelDetailChecks().
85+ * @param {string } username - The in-game username of the user.
86+ * @param {int } tries - The amount of tries to get userdata before giving up.
87+ */
88+ function loadUserSkills ( username , tries ) {
7289 $ . ajax ( { // Get the skill data.
7390 type :"GET" ,
7491 url :"https://apps.runescape.com/runemetrics/profile/profile?user=" + username + "&activities=0" ,
7592 success : function ( msg ) {
7693 if ( "error" in msg ) {
7794 if ( tries <= 0 ) {
78- console . log ( "Could not fetch skills data!" ) ;
95+ console . error ( "Could not fetch skills data!" ) ;
7996 } else {
80- Console . log ( "Trying stats again!" ) ;
81- loadUserStats ( username , tries - 1 ) ;
97+ loadUserSkills ( username , tries - 1 ) ;
8298 }
8399 } else {
84100 var userLevels = [ ] ;
85101 msg [ "skillvalues" ] . forEach ( function ( item , index ) {
86- // console.log(skills[item["id"]] + ": " +item["level"]);
87- userLevels [ skills [ item [ "id" ] ] ] = item [ "level" ] ;
88-
102+ userLevels [ skills [ item [ "id" ] ] ] = item [ "level" ] ;
89103 } ) ;
90104 addLevelDetailChecks ( userLevels ) ;
91105 }
92106 }
93107 } ) ;
94108}
95109
110+ /**
111+ * Get the configuration with standard values in case something is missing.
112+ * @param {requestCallback } func - the function which does something with the configuration.
113+ */
96114function getConfig ( func ) {
97115 chrome . storage . sync . get ( {
98116 username : ""
99117 } , func ) ;
100118}
101119
120+ /**
121+ * Load the config and start everything.
122+ */
102123function init ( ) {
103124 getConfig ( function ( config ) {
104- loadUserData ( config . username , 1 ) ;
125+ loadUserData ( config . username , 5 ) ;
105126 } ) ;
106127}
107128
0 commit comments