Add function to detect vacation mode
@@ -6,6 +6,7 @@ import (
"errors"
"fmt"
"math"
+ "net/url"
"regexp"
"strconv"
"strings"
@@ -16,6 +17,12 @@ import (
"golang.org/x/net/html"
)
+// ExtractIsInVacation ...
+func ExtractIsInVacation(pageHTML []byte) bool {
+ doc, _ := goquery.NewDocumentFromReader(bytes.NewReader(pageHTML))
+ return ExtractIsInVacationFromDoc(doc)
+}
+
// ExtractPlanets ...
func ExtractPlanets(pageHTML []byte, b *OGame) []Planet {
doc, _ := goquery.NewDocumentFromReader(bytes.NewReader(pageHTML))
@@ -211,6 +218,20 @@ func ExtractBodyIDFromDoc(doc *goquery.Document) string {
return doc.Find("body").AttrOr("id", "")
}
+// ExtractIsInVacationFromDoc ...
+func ExtractIsInVacationFromDoc(doc *goquery.Document) bool {
+ href := doc.Find("div#advice-bar a").AttrOr("href", "")
+ if href == "" {
+ return false
+ }
+ u, _ := url.Parse(href)
+ q := u.Query()
+ if q.Get("page") == "preferences" && q.Get("selectedTab") == "3" && q.Get("openGroup") == "0" {
+ return true
+ }
+ return false
+}
+
// ExtractPlanetsFromDoc ...
func ExtractPlanetsFromDoc(doc *goquery.Document, b *OGame) []Planet {
res := make([]Planet, 0)
