diff --git a/index.html b/index.html index 2ea8f4d..1022361 100644 --- a/index.html +++ b/index.html @@ -1,33 +1,192 @@ - - - - - - -
- -
-
- - { - -
+ + + + + + +
+

Transfermarkt Scraper

+

+ Please choose the starting year and ending year which you want to scrape from: +

+
+
+ +
- - } - -
-
-

Scraping...

-

-      
+      
+ + +
+ + +
+
+ + { + +
+ +
- - + + } + +
+
+

Scraping...

+

+    
+    
+  
+ + + + diff --git a/main.js b/main.js index 73cf3a0..14d7a1b 100644 --- a/main.js +++ b/main.js @@ -1,20 +1,21 @@ var startDate = 1956; // first year a transfer fee was recorded on transfermarkt.com var endDate = new Date().getFullYear(); // current Year var getUrl = "https://www.transfermarkt.com/transfers/transferrekorde/statistik/top/saison_id/"; // ADD Year after saison_id/ -function ajaxCall(iterate){ +function ajaxCall(startyear, endyear){ $.ajax({ - url: getUrl + iterate, + url: getUrl + startyear, type: 'GET', beforeSend: function() { $(".copy .loadingScrape").addClass("visible"); + $(".form").removeClass("visible"); }, complete: function() { }, success: function(data) { - var currentYearString = '"'+iterate+'"'; - $(".json").append('
'+currentYearString+': [
'); - $(".json").append('
'); + var currentYearString = '"'+startyear+'"'; + $(".json").append('
'+currentYearString+': [
'); + $(".json").append('
'); var tableRows = $(data).find(".items>tbody>tr"); tableRows.each(function() { var rank = $(this).find(">td:first-of-type").text(); // get rank within year @@ -82,13 +83,13 @@ function ajaxCall(iterate){ transferHistoryLink: "https://www.transfermarkt.com" + transferHistoryLink }; var playerJSON = JSON.stringify(playerObj); // object to JSON - $("."+iterate+".before").append("

"+playerJSON+"

"); // parse json to browser + $("."+startyear+".before").append("

"+playerJSON+"

"); // parse json to browser }); - $("."+iterate+".after").append("],"); + $("."+startyear+".after").append("],"); - if(iterate++ < endDate) { + if(startyear++ < endyear) { $(".loadingScrape").removeClass("visible"); - ajaxCall(iterate); + ajaxCall(startyear); } else { $(".loadingScrape").removeClass("visible"); @@ -98,6 +99,7 @@ function ajaxCall(iterate){ completeJSON = JSON.parse(completeJSON); completeJSON = JSON.stringify(completeJSON, undefined, 2); jsonoutput(syntaxHighlight(completeJSON)); + $(".copy").addClass("visible"); $(".copy").prepend('

Scraping done!

'); $(".copy button").addClass("visible"); $("#copy").addClass("visible"); @@ -108,14 +110,37 @@ function ajaxCall(iterate){ } }); } -ajaxCall(startDate); +function scrape() { + $(".form span").remove(); + var startSelect = document.getElementById("startyear"); + var endSelect = document.getElementById("endyear"); + var startValue = startSelect.options[startSelect.selectedIndex].value; + var endValue = endSelect.options[endSelect.selectedIndex].value; + if(!startValue) { + $('Error: Please select a starting year.').insertBefore("#submitButton"); + } + else if(!endValue) { + $('Error: Please select an ending year.').insertBefore("#submitButton"); + } + else if(startValue > endValue) { + $('Error: The starting year must be lower than the ending year.').insertBefore("#submitButton"); + } + else { + ajaxCall(startValue, endValue); + } +} function copyFunction() { $("#copy").select(); document.execCommand("copy"); alert("Copied to clipboard!"); } - +function scrapeReset() { + $(".copy pre").empty(); + $(".copy .doneScrape").remove(); + $(".copy, .copy pre, .copy button").removeClass("visible"); + $(".form").addClass("visible"); +} function jsonoutput(input) { document.getElementById("copy").innerHTML = input; } diff --git a/selectbox.js b/selectbox.js new file mode 100644 index 0000000..315567e --- /dev/null +++ b/selectbox.js @@ -0,0 +1,49 @@ +/* +Reference: http://jsfiddle.net/BB3JK/47/ +*/ + +$('select').each(function(){ + var $this = $(this), numberOfOptions = $(this).children('option').length; + + $this.addClass('select-hidden'); + $this.wrap('
'); + $this.after('
'); + + var $styledSelect = $this.next('div.select-styled'); + $styledSelect.text($this.children('option').eq(0).text()); + + var $list = $('