-
Notifications
You must be signed in to change notification settings - Fork 84
/
create_gt_url.js
42 lines (33 loc) · 889 Bytes
/
create_gt_url.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
'use strict';
function URL_GT(keyword, country, region, year, month, length){
var start = "http://www.google.com/trends/trendsReport?hl=en-US&q=";
var end = "&cmpt=q&content=1&export=1";
var geo = "";
var date = "";
var URL = "";
var month=1;
var length=3;
//Geographic restrictions
if(typeof country!=="undefined") {
geo="&geo=";
geo=geo + country;
if(region!==undefined) geo=geo + "-" + region;
}
if(typeof keyword==="string"){
var queries=keyword;
}
if(typeof keyword==="object"){
var queries=keyword[0];
for(var i=1; i < keyword.length; i++){
queries=queries + "%2C" + keyword[i];
}
}
//Dates
if(typeof year!=="undefined"){
date="&date="
date=date + month + "%2F" + year + "%20" + length + "m"
}
URL = start + queries + geo + date + end;
URL = URL.replace(" ", "%20");
return(URL);
}