Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 35 additions & 5 deletions src/dataArrays.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,40 @@ var skills = ["Attack","Defence","Strength","Constitution","Ranged","Prayer","Ma
]; //Used to turn skill ID's into usable names.

var apiQuestNamesCorrections = []; //Used to correct the API to the wiki names.
apiQuestNamesCorrections["Great Brain Robbery"] = "The Graet Brain Robbery";
apiQuestNamesCorrections["Curse of Arrav"] = "The Curse of Arrav";
apiQuestNamesCorrections["A Rum Deal"] = "Rum Deal";
apiQuestNamesCorrections["As A First Resort..."] = "As a First Resort";
apiQuestNamesCorrections["Chosen Commander"] = "The Chosen Commander";
apiQuestNamesCorrections["Fairy Tale III - Battle at Orks Rift"] = "Fairy Tale III - Orks Rift";
apiQuestNamesCorrections["Slug Menace"] = "The Slug Menace";
apiQuestNamesCorrections["Curse of Arrav"] = "The Curse of Arrav";
apiQuestNamesCorrections["Dig Site"] = "The Dig Site";
apiQuestNamesCorrections["Fremennik Isles"] = "The Fremennik Isles";
apiQuestNamesCorrections["Dishonour among Thieves"] = ["Dishonour among Thieves", "Dishonor Among Thieves", "Dishonour Among Thieves"];
apiQuestNamesCorrections["Evil Dave's big day out"] = "Evil Dave's Big Day Out";
apiQuestNamesCorrections["Fairy Tale I - Growing Pains"] = ["Fairy Tale I - Growing Pains", "Fairy Tale Part I - Growing Pains"];
apiQuestNamesCorrections["Fairy Tale II - Cure a Queen"] = ["Fairy Tale II - Cure a Queen", "Fairy Tale Part II - Cure a Queen"];
apiQuestNamesCorrections["Fairy Tale III - Battle at Orks Rift"] = ["Fairy Tale III - Battle at Ork's Rift", "Fairy Tale III - Battle at Orks Rift", "Fairy Tale Part III – Battle at Orks Rift", "Fairy Tale Part III - Battle at Ork's Rift"];
apiQuestNamesCorrections["Forgettable Tale of a Drunken Dwarf"] = "Forgettable Tale...";
apiQuestNamesCorrections["Fremennik Isles"] = "The Fremennik Isles";
apiQuestNamesCorrections["Garden of Tranquility"] = "Garden of Tranquillity";
apiQuestNamesCorrections["Great Brain Robbery"] = "The Great Brain Robbery";
apiQuestNamesCorrections["Horror from the Deep"] = ["Horror from the Deep", "Horror From the Deep"];
apiQuestNamesCorrections["Mourning's End Part II"] = ["Mourning's End Part II", "Mourning's End Part II (The Temple of Light)"];
apiQuestNamesCorrections["Prisoner of Glouphrie"] = "The Prisoner of Glouphrie";
apiQuestNamesCorrections["Rat Catchers"] = "Ratcatchers";
apiQuestNamesCorrections["Recipe for Disaster"] = "Recipe for Disaster: Defeating the Culinaromancer";
apiQuestNamesCorrections["Recipe for Disaster: Awowogei"] = "Recipe for Disaster: Freeing King Awowogei";
apiQuestNamesCorrections["Recipe for Disaster: Dwarf"] = "Recipe for Disaster: Freeing the Mountain dwarf";
apiQuestNamesCorrections["Recipe for Disaster: Evil Dave"] = "Recipe for Disaster: Freeing Evil Dave";
apiQuestNamesCorrections["Recipe for Disaster: Goblin Generals"] = "Recipe for Disaster: Freeing the Goblin generals";
apiQuestNamesCorrections["Recipe for Disaster: Lumbridge Sage"] = "Recipe for Disaster: Freeing the Lumbridge Sage";
apiQuestNamesCorrections["Recipe for Disaster: Pirate Pete"] = "Recipe for Disaster: Freeing Pirate Pete";
apiQuestNamesCorrections["Recipe for Disaster: Sir Amik Varze"] = "Recipe for Disaster: Freeing Sir Amik Varze";
apiQuestNamesCorrections["Recipe for Disaster: Skrach"] = "Recipe for Disaster: Freeing Skrach Uglogwee";
apiQuestNamesCorrections["Recipe for Disaster: Starting Out"] = "Recipe for Disaster: Another Cook's Quest";
apiQuestNamesCorrections["Slug Menace"] = "The Slug Menace";
apiQuestNamesCorrections["Tale of the Muspah"] = ["The Tale of the Muspah", "The Tale of Muspah"];
apiQuestNamesCorrections["Tears of Guthix"] = "Tears of Guthix (quest)";
apiQuestNamesCorrections["The Darkness of Hallowvale"] = "Darkness of Hallowvale";
apiQuestNamesCorrections["The Elemental Workshop I"] = "Elemental Workshop I";
apiQuestNamesCorrections["The Elemental Workshop II"] = "Elemental Workshop II";
apiQuestNamesCorrections["The Elemental Workshop III"] = "Elemental Workshop III";
apiQuestNamesCorrections["The Elemental Workshop IV"] = "Elemental Workshop IV";
apiQuestNamesCorrections["The Watchtower"] = "Watchtower";
97 changes: 65 additions & 32 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ function addQuestCompletedChecks(userQuests){
var questTitle = $(this).html();
if (questTitle in userQuests){
userQuests[questTitle].handleQuest($(this));
}
}

}
});
Expand All @@ -21,42 +21,67 @@ function addQuestCompletedChecks(userQuests){
*/
function addLevelDetailChecks(userLevels){
$("img").each(function(index){
var thieving = false;
if($(this).attr("alt") == "Thieving"){
console.log($(this));
thieving = true;
console.log($(this).parent().parent().text());
}
if (!($(this).attr("alt") in userLevels)){
return;
}

// var thieving = false;
// if($(this).attr("alt") == "Thieving"){
// console.log($(this));
// thieving = true;
// console.log($(this).parent()[0].nextSibling);
// // console.log($(this).parent().parent().clone().children().remove().end().text().replace(/^[^\d]*|[^\d]*$| /g, "").replace(/[^(\d+\/\d+)\d+]+/g, "\n"));
// }
var onQuestPage = window.location.href.indexOf("/wiki/Quests") !== -1;
if (onQuestPage){
var textArr = $(this).parent().parent().text().split(new RegExp("> "));
var level = textArr[1];
} else {
var textArr = $(this).parent().parent().text().split(new RegExp(" |<"));
var level = textArr[0];
var textInfront = true;
var level;
try {
// Try to read text infront of the image
var leadingText = $(this).parent()[0].previousSibling.textContent;
level = (leadingText !== null) ? (leadingText.match(/\d+(?!.*\d+)/) || [null])[0] : null;
} catch (error) {
textInfront = false;
try {
// Try to read text behind the image
var trailingText = $(this).parent()[0].nextSibling.textContent;
level = (trailingText !== null) ? (trailingText.match(/^\s\d+/) || [null])[0] : null;
} catch (error) {
// If both fail, go to next object
return;
}
}

if (isNaN(level)){ //Check if it is a number.
if (isNaN(level) || level === null){ //Check if it is a number.
return;
}
if (!($(this).attr("alt") in userLevels)){
return;
}
var skill = $(this).attr("alt");

if (level != "" && skill != ""){
if (userLevels[skill] >= level) {
$(this).parent().parent().append(' <img src=' + chrome.extension.getURL('assets/images/check.svg') + '>');

if (textInfront){
$(this).parent().append(' <img src=' + chrome.extension.getURL('assets/images/check.svg') + '>');
} else {
$(this).parent().parent().append(' <img src=' + chrome.extension.getURL('assets/images/check.svg') + '>');
}

} else {
if (onQuestPage){
$(this).parent().after(" " + userLevels[skill]+"/");
if (textInfront){
var preText = $(this).parent()[0].previousSibling.textContent.replace(/(\d+)(?!.*\d+)/, userLevels[skill] + "/$1");
$(this).parent()[0].previousSibling.textContent = preText;
$(this).parent().append(' <img src=' + chrome.extension.getURL('assets/images/cross.svg') + ' style="width:15px">');
} else {
$(this).parent().parent().prepend(userLevels[skill]+"/");
var trailingText = $(this).parent()[0].nextSibling.textContent.replace(/^ (\d+)/, " " + userLevels[skill] + "/$1");
$(this).parent()[0].nextSibling.textContent = trailingText;
$(this).parent().parent().append(' <img src=' + chrome.extension.getURL('assets/images/cross.svg') + ' style="width:15px">');
}
$(this).parent().parent().append(' <img src=' + chrome.extension.getURL('assets/images/cross.svg') + ' style="width:15px">');
}
$(this).parent().parent().css("white-space", "nowrap");

if (textInfront) {
$(this).parent().css("white-space", "nowrap");
} else {
$(this).parent().parent().css("white-space", "nowrap");
}

}

});
Expand Down Expand Up @@ -102,9 +127,16 @@ function loadUserQuests(username, tries){
userQuests[item["title"]] = questCompletionObject;

if (item["title"] in apiQuestNamesCorrections){
var correctName = apiQuestNamesCorrections[item["title"]];
userQuests[correctName] = userQuests[item["title"]];
}
if (typeof(apiQuestNamesCorrections[item["title"]]) === "object") {
for (var i = 0; i < apiQuestNamesCorrections[item["title"]].length; i++) {
var correctName = apiQuestNamesCorrections[item["title"]][i];
userQuests[correctName] = userQuests[item["title"]];
}
} else {
var correctName = apiQuestNamesCorrections[item["title"]];
userQuests[correctName] = userQuests[item["title"]];
}
}
});
addQuestCompletedChecks(userQuests);
}
Expand Down Expand Up @@ -152,16 +184,17 @@ function getConfig(func){

function attachColorChange(){
var colorGreen = "rgb(57, 234, 57)";
var highlightClassName = "rs-wiki-quest-checker-highlight";
$("li:not(.questdetails li)").each(function(){
$(this).click(function(e){
//Do nothing if the list-item was not directly clicked
if(e.target !== e.currentTarget) return;

if ($(this).css("background-color") == colorGreen){
$(this).css("background-color", "");
$(this).css("background-color", "").removeClass( highlightClassName );
} else {
$(this).css("background-color", colorGreen);
$(this).find("li").each(function(index) { $(this).css("background-color", colorGreen); });
$(this).css("background-color", colorGreen).addClass( highlightClassName );
$(this).find("li").each(function(index) { $(this).css("background-color", colorGreen).addClass( highlightClassName ); });
}
// Check if we need to color the parent.
if ($(this).parent().parent().prop('nodeName') != 'DIV'){
Expand All @@ -172,9 +205,9 @@ function attachColorChange(){
}
});
if (allGreen){
$(this).parent().parent().css("background-color", colorGreen);
$(this).parent().parent().css("background-color", colorGreen).addClass( highlightClassName );
} else {
$(this).parent().parent().css("background-color", "");
$(this).parent().parent().css("background-color", "").removeClass( highlightClassName );
}
}

Expand Down