From 10a269f89077e281d7a31107ad2a3d786261b121 Mon Sep 17 00:00:00 2001 From: Paul Datsiuk Date: Tue, 27 Jun 2017 10:11:45 +0300 Subject: [PATCH 1/6] new geoip with basic country info --- README.md | 11 +++++++++++ index.js | 26 ++++++++++++++++++++------ sample.html | 8 ++++++++ 3 files changed, 39 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index e9d1d93..a89ac91 100644 --- a/README.md +++ b/README.md @@ -46,6 +46,14 @@ The report object has the following keys and value types. "version": (string) }, "ip": (string), + "country": { + "name": (string), + "code": (string), + "city": (string), + "latitude" : (string), + "longitude": (string), + "timezone": (string) + }, "java": { "version": (string) }, @@ -105,6 +113,9 @@ In chronological order (oldest first); not in order of priority. #Change Log +*2.2.9 – June 27, 2017* +* added extended country info from freegeoip + *2.2.8 – January 18, 2017* * added test cases for detecting Opera Mobile diff --git a/index.js b/index.js index 3326cc5..e94b198 100644 --- a/index.js +++ b/index.js @@ -24,6 +24,14 @@ "version": null }, "ip": null, + "country": { + "name": null, + "code": null, + "city": null, + "latitude" : null, + "longitude": null, + "timezone": null + }, "java": { "version": null }, @@ -473,7 +481,7 @@ /* * asynchronous version includes the remote client IP address - * uses ipify.org API + * uses freegeoip.net API */ window.browserReport = window.browserReport || function (callback) { var report, newScriptTag, existingScriptTag; @@ -481,15 +489,21 @@ report = extractDataFromClient(); // use ipify.org to get the remote client ip address - // define function to handle data from ipify.org - window.getip = window.getip || function (data) { - report.ip = data.ip; + // define function to handle data from freegeoip.net + window.geoip = window.geoip || function (geoip) { + report.ip = geoip.ip; + report.country.name = geoip.country_name; + report.country.code = geoip.country_code; + report.country.city = geoip.city; + report.country.latitude = geoip.latitude; + report.country.longitude = geoip.longitude; + report.country.timezone = geoip.time_zone; callback(null, report); }; - // inject script tag get JSONP response from ipify.org + // inject script tag get JSONP response from freegeoip.net newScriptTag = document.createElement("script"); - newScriptTag.src = "https://api.ipify.org?format=jsonp&callback=getip"; + newScriptTag.src = "http://freegeoip.net/json/?callback=geoip"; existingScriptTag = document.getElementsByTagName("script")[0]; existingScriptTag.parentNode.insertBefore(newScriptTag, existingScriptTag); diff --git a/sample.html b/sample.html index 306bd54..59006d2 100644 --- a/sample.html +++ b/sample.html @@ -118,6 +118,14 @@

{{screen.colors}} + + + Country info + + + {{country.name}} {{country.city}} + +

Your full user agent string is:
From c65fc49d3e30346779b461c9144802f79d1930d0 Mon Sep 17 00:00:00 2001 From: Paul Datsiuk Date: Tue, 27 Jun 2017 10:19:31 +0300 Subject: [PATCH 2/6] add typescript definition --- README.md | 9 +++++++++ index.d.ts | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+) create mode 100644 index.d.ts diff --git a/README.md b/README.md index a89ac91..2a6f5d1 100644 --- a/README.md +++ b/README.md @@ -83,6 +83,14 @@ The report object has the following keys and value types. "websockets": (boolean) } +## TypeScript Usage + +import 'browser-report'; + +window.browserReport((error, result) => { + console.log(result.ip + ' ' + result.browser.name); +}); + # Coverage The goal is to correctly identify all browsers included on caniuse.com according to their [browser usage table][3]. As of January 18, 2017, their browser usage table accounts for 98.19% of global usage based on data from [StatCounter GlobalStats][4]. @@ -115,6 +123,7 @@ In chronological order (oldest first); not in order of priority. *2.2.9 – June 27, 2017* * added extended country info from freegeoip +* added typescript definition *2.2.8 – January 18, 2017* diff --git a/index.d.ts b/index.d.ts new file mode 100644 index 0000000..7676e95 --- /dev/null +++ b/index.d.ts @@ -0,0 +1,56 @@ +// Type definitions for browser-report v2.2.8 +// Project: https://github.com/JTOne123/browser-report +// Definitions by: Paul Datsiuk +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +interface Window { + browserReport(result: (error: ErrorEvent, report: ReportResult) => any): void; + browserReportSync(): ReportResult; +} + +interface ReportResult { + "browser": { + "name": (string), + "version": (string) + }, + "cookies": (boolean), + "flash": { + "version": (string) + }, + "ip": (string), + "country": { + "name": (string), + "code": (string), + "city": (string), + "latitude" : (string), + "longitude": (string), + "timezone": (string) + }, + "java": { + "version": (string) + }, + "lang": (array), + "os": { + "name": (string), + "version": (string) + }, + "screen": { + "colors": (number), + "dppx": (number), + "height": (number), + "width": (number) + }, + "scripts": (boolean), + "timestamp": (string), + "userAgent": (string), + "viewport": { + "height": (number), + "layout": { + "height": (number), + "width": (number) + } + "width": (number), + "zoom": (number) + } + "websockets": (boolean) +} \ No newline at end of file From 13a6144ee685d2a65223717087fcc6612138482f Mon Sep 17 00:00:00 2001 From: Paul Datsiuk Date: Tue, 27 Jun 2017 10:52:59 +0300 Subject: [PATCH 3/6] fix version --- index.d.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/index.d.ts b/index.d.ts index 7676e95..8c7dec2 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1,4 +1,4 @@ -// Type definitions for browser-report v2.2.8 +// Type definitions for browser-report v2.2.9 // Project: https://github.com/JTOne123/browser-report // Definitions by: Paul Datsiuk // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped @@ -29,7 +29,7 @@ interface ReportResult { "java": { "version": (string) }, - "lang": (array), + "lang": (Array), "os": { "name": (string), "version": (string) From de7fe7b93e025b178eab391f03179b6fd7308725 Mon Sep 17 00:00:00 2001 From: Paul Datsiuk Date: Wed, 28 Jun 2017 11:02:29 +0300 Subject: [PATCH 4/6] parentheses was deleted --- index.d.ts | 56 +++++++++++++++++++++++++++--------------------------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/index.d.ts b/index.d.ts index 8c7dec2..c5852aa 100644 --- a/index.d.ts +++ b/index.d.ts @@ -10,47 +10,47 @@ interface Window { interface ReportResult { "browser": { - "name": (string), - "version": (string) + "name": string, + "version": string }, - "cookies": (boolean), + "cookies": boolean, "flash": { - "version": (string) + "version": string }, - "ip": (string), + "ip": string, "country": { - "name": (string), - "code": (string), - "city": (string), - "latitude" : (string), - "longitude": (string), - "timezone": (string) + "name": string, + "code": string, + "city": string, + "latitude" : string, + "longitude": string, + "timezone": string }, "java": { - "version": (string) + "version": string }, - "lang": (Array), + "lang": Array, "os": { - "name": (string), - "version": (string) + "name": string, + "version": string }, "screen": { - "colors": (number), - "dppx": (number), - "height": (number), - "width": (number) + "colors": number, + "dppx": number, + "height": number, + "width": number }, - "scripts": (boolean), - "timestamp": (string), - "userAgent": (string), + "scripts": boolean, + "timestamp": string, + "userAgent": string, "viewport": { - "height": (number), + "height": number, "layout": { - "height": (number), - "width": (number) + "height": number, + "width": number } - "width": (number), - "zoom": (number) + "width": number, + "zoom": number } - "websockets": (boolean) + "websockets": boolean } \ No newline at end of file From 1711ee79ac37017a42a62377ca58c67e53e1c05c Mon Sep 17 00:00:00 2001 From: Paul Datsiuk Date: Thu, 29 Jun 2017 09:35:20 +0300 Subject: [PATCH 5/6] move to https endpoint --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index e94b198..351f759 100644 --- a/index.js +++ b/index.js @@ -503,7 +503,7 @@ // inject script tag get JSONP response from freegeoip.net newScriptTag = document.createElement("script"); - newScriptTag.src = "http://freegeoip.net/json/?callback=geoip"; + newScriptTag.src = "https://freegeoip.net/json/?callback=geoip"; existingScriptTag = document.getElementsByTagName("script")[0]; existingScriptTag.parentNode.insertBefore(newScriptTag, existingScriptTag); From eb1ea0b846a14235bf2314799cc1df59067fd717 Mon Sep 17 00:00:00 2001 From: Paul Datsiuk Date: Thu, 29 Jun 2017 09:47:09 +0300 Subject: [PATCH 6/6] explicit type for lang, it should be an array only and always --- README.md | 12 ++++++------ index.js | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 2a6f5d1..4a3bcf2 100644 --- a/README.md +++ b/README.md @@ -57,7 +57,7 @@ The report object has the following keys and value types. "java": { "version": (string) }, - "lang": (array || string), + "lang": (array), "os": { "name": (string), "version": (string) @@ -85,11 +85,11 @@ The report object has the following keys and value types. ## TypeScript Usage -import 'browser-report'; + import 'browser-report'; -window.browserReport((error, result) => { - console.log(result.ip + ' ' + result.browser.name); -}); + window.browserReport((error, result) => { + console.log(result.ip + ' ' + result.browser.name); + }); # Coverage @@ -203,7 +203,7 @@ In chronological order (oldest first); not in order of priority. * the previous synchronous function can still be found in `browserReportSync()` * the remote client IP address is now reported from ipify.org * a random UUID is now generated for cookie test instead of using the same UUID every time -* report now includes the client's preferred language(s) for displaying pages +* report now includes the client's preferred languages for displaying pages * report now includes a timestamp with the client's locale date, time and time zone *1.0.0 — September 11, 2015* diff --git a/index.js b/index.js index 351f759..f49c741 100644 --- a/index.js +++ b/index.js @@ -467,8 +467,8 @@ report.websockets = !!window.WebSocket; - // preferred language(s) for displaying pages - report.lang = navigator.languages || navigator.language; + // preferred languages for displaying pages + report.lang = navigator.languages || [navigator.language]; // local date, time, and time zone