From b1037390ccf7c61bcd7b0cc698c487e5c6dc4cfd Mon Sep 17 00:00:00 2001 From: CephHunter Date: Sun, 22 Apr 2018 18:22:54 +0200 Subject: [PATCH 1/3] Added a class to higlighted list elements on quick guides to make it easier to integrate with custom css --- src/main.js | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/main.js b/src/main.js index 8d5ff5b..689b436 100644 --- a/src/main.js +++ b/src/main.js @@ -21,12 +21,12 @@ 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()); - } + // var thieving = false; + // if($(this).attr("alt") == "Thieving"){ + // console.log($(this)); + // thieving = true; + // console.log($(this).parent().parent().text()); + // } var onQuestPage = window.location.href.indexOf("/wiki/Quests") !== -1; if (onQuestPage){ var textArr = $(this).parent().parent().text().split(new RegExp("> ")); @@ -134,6 +134,7 @@ function loadUserSkills(username, tries){ msg["skillvalues"].forEach(function(item, index){ userLevels[skills[item["id"]]] = item["level"]; }); + // console.log(userLevels); addLevelDetailChecks(userLevels); } } @@ -152,16 +153,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'){ @@ -172,9 +174,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 ); } } From 2d0bfc6c90581f6b4af923a128b27aebeb199bb6 Mon Sep 17 00:00:00 2001 From: CephHunter Date: Mon, 23 Apr 2018 03:26:05 +0200 Subject: [PATCH 2/3] Fixed an issue when multiple skills where given in a single element. Also completed the quest namechanging list. --- src/dataArrays.js | 34 +++++++++++++++++++++++----- src/main.js | 56 +++++++++++++++++++++++++++++++---------------- 2 files changed, 66 insertions(+), 24 deletions(-) diff --git a/src/dataArrays.js b/src/dataArrays.js index d55455b..af206ae 100644 --- a/src/dataArrays.js +++ b/src/dataArrays.js @@ -2,10 +2,34 @@ 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"; \ No newline at end of file +apiQuestNamesCorrections["Fairy Tale III - Battle at Orks Rift"] = "Fairy Tale 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["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"; +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"; \ No newline at end of file diff --git a/src/main.js b/src/main.js index 689b436..501a207 100644 --- a/src/main.js +++ b/src/main.js @@ -21,42 +21,61 @@ function addQuestCompletedChecks(userQuests){ */ function addLevelDetailChecks(userLevels){ $("img").each(function(index){ + if (!($(this).attr("alt") in userLevels)){ + return; + } + // var thieving = false; // if($(this).attr("alt") == "Thieving"){ // console.log($(this)); // thieving = true; - // console.log($(this).parent().parent().text()); + // 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(' '); - + if (textInfront){ + $(this).parent().append(' '); + } else { + $(this).parent().parent().append(' '); + } + } 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(' '); } 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(' '); } - $(this).parent().parent().append(' '); } - $(this).parent().parent().css("white-space", "nowrap"); + $(this).parent().css("white-space", "nowrap"); } }); @@ -134,7 +153,6 @@ function loadUserSkills(username, tries){ msg["skillvalues"].forEach(function(item, index){ userLevels[skills[item["id"]]] = item["level"]; }); - // console.log(userLevels); addLevelDetailChecks(userLevels); } } From 9a3d28afc4880f25531ae8c4339af38a09549132 Mon Sep 17 00:00:00 2001 From: CephHunter Date: Mon, 23 Apr 2018 23:39:10 +0200 Subject: [PATCH 3/3] Added some commonly mistyped links on the wiki --- src/dataArrays.js | 10 ++++++++-- src/main.js | 23 ++++++++++++++++++----- 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/src/dataArrays.js b/src/dataArrays.js index af206ae..9aa959a 100644 --- a/src/dataArrays.js +++ b/src/dataArrays.js @@ -7,11 +7,17 @@ apiQuestNamesCorrections["As A First Resort..."] = "As a First Resort"; apiQuestNamesCorrections["Chosen Commander"] = "The Chosen Commander"; apiQuestNamesCorrections["Curse of Arrav"] = "The Curse of Arrav"; apiQuestNamesCorrections["Dig Site"] = "The Dig Site"; -apiQuestNamesCorrections["Fairy Tale III - Battle at Orks Rift"] = "Fairy Tale III - Battle at Ork's Rift"; +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"; @@ -25,7 +31,7 @@ apiQuestNamesCorrections["Recipe for Disaster: Sir Amik Varze"] = "Recipe for Di 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"; +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"; diff --git a/src/main.js b/src/main.js index 501a207..b5a9c51 100644 --- a/src/main.js +++ b/src/main.js @@ -9,7 +9,7 @@ function addQuestCompletedChecks(userQuests){ var questTitle = $(this).html(); if (questTitle in userQuests){ userQuests[questTitle].handleQuest($(this)); - } + } } }); @@ -75,7 +75,13 @@ function addLevelDetailChecks(userLevels){ $(this).parent().parent().append(' '); } } - $(this).parent().css("white-space", "nowrap"); + + if (textInfront) { + $(this).parent().css("white-space", "nowrap"); + } else { + $(this).parent().parent().css("white-space", "nowrap"); + } + } }); @@ -121,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); }