Skip to content

Commit 822dff1

Browse files
committed
Cleaned up popup
1 parent 66de125 commit 822dff1

File tree

6 files changed

+80
-48
lines changed

6 files changed

+80
-48
lines changed

manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99

1010
"browser_action": {
11-
"default_popup": "src/options/options.html"
11+
"default_popup": "src/popup/popup.html"
1212
},
1313
"permissions": [
1414
"activeTab",

src/main.js

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
var 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+
*/
48
function 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+
*/
1826
function addLevelDetailChecks(userLevels){
1927
$(".questdetails-info > ul > li").each(function(index){
2028
var textArr = $(this).text().split(" ");
@@ -41,19 +49,23 @@ function addLevelDetailChecks(userLevels){
4149

4250
function 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+
*/
4760
function 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+
*/
96114
function getConfig(func){
97115
chrome.storage.sync.get({
98116
username: ""
99117
}, func);
100118
}
101119

120+
/**
121+
* Load the config and start everything.
122+
*/
102123
function init(){
103124
getConfig(function(config){
104-
loadUserData(config.username, 1);
125+
loadUserData(config.username, 5);
105126
});
106127
}
107128

src/options/options.html

Lines changed: 0 additions & 12 deletions
This file was deleted.

src/options/options.js

Lines changed: 0 additions & 23 deletions
This file was deleted.

src/popup/popup.html

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<html style="height:180px">
2+
<head>
3+
<script src="/assets/js/jquery-3.2.1.min.js"></script>
4+
<script src="/src/popup/popup.js"></script>
5+
</head>
6+
<body style="height:180px">
7+
<div>
8+
<h3> Options: </h3>
9+
<h4 style="margin-bottom:5px"> Username: </h4>
10+
<input type=text id="options_username">
11+
<button id="options_save_button" style="margin-top:10px">Save options</button>
12+
<span id=status style="text-align:center"></span>
13+
</div>
14+
<div style="text-align:center;margin-top:20px">
15+
Want to help? Found a bug? <br>
16+
<i>Or want an extra feature?</i> <br>
17+
Create an issue on <strong><a href="https://github.com/MidasLamb/RS-Wiki-Quest-Checker/issues" target=>GitHub</a></strong>
18+
</div>
19+
</body>
20+
</html>

src/popup/popup.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
function saveOptions(){
2+
var userName = $("#options_username").val();
3+
chrome.storage.sync.set({
4+
username: userName
5+
}, function(){
6+
$('#status').html("Options Set!");
7+
setTimeout(function() {
8+
$('#status').html("");
9+
}, 1000);
10+
});
11+
}
12+
13+
$(document).ready(function(){
14+
$('body').on('click', 'a', function(){
15+
chrome.tabs.create({url: $(this).attr('href')});
16+
return false;
17+
});
18+
19+
chrome.storage.sync.get({
20+
username: ""
21+
}, function(items){
22+
$("#options_username").val(items.username);
23+
});
24+
25+
$("#options_save_button").click(saveOptions);
26+
});

0 commit comments

Comments
 (0)