Difference between revisions of "MediaWiki:Gadget-site.js"

From Caiyun Wiki
Jump to: navigation, search
Line 40: Line 40:
 
     "success": function( response ) {
 
     "success": function( response ) {
 
         $('.tianqi').html(buildTianqi(response.placename, response.result.realtime.skycon, response.result.realtime.temperature));
 
         $('.tianqi').html(buildTianqi(response.placename, response.result.realtime.skycon, response.result.realtime.temperature));
 +
    }
 +
});
 +
 +
 +
var url = 'http://poetrydb.org/author';
 +
$.ajax({
 +
    "url": url,
 +
    "jsonp": "callback",
 +
    "dataType": "jsonp",
 +
    "success": function( response ) {
 +
        console.log(response);
 
     }
 
     }
 
});
 
});

Revision as of 06:28, 31 August 2018

//  _________________________________________________________________________________________
// |                                                                                         |
// |                    === WARNING: GLOBAL GADGET FILE ===                                  |
// |                  Changes to this page affect many users.                                |
// | Please discuss changes on the talk page or on [[Wikipedia_talk:Gadget]] before editing. |
// |_________________________________________________________________________________________|
//

var skyconword = {
    'RAIN': 'rain',
    'SNOW': 'snow',
    'HAZE': 'fog',
    'WIND': 'wind',
    'CLOUDY': 'cloudy',
    'PARTLY_CLOUDY_DAY': 'partly cloudy',
    'PARTLY_CLOUDY_NIGHT': 'partly cloudy',
    'CLEAR_DAY': 'clear',
    'CLEAR_NIGHT': 'clear',
};

function buildTianqi(placename, skycon, temp) {
    var desc = skyconword[skycon];
    return "<link href='https://fonts.googleapis.com/css?family=Roboto:400,300' rel='stylesheet' type='text/css'><div class='card'><div class='city'>" + placename + "</div><div class='temp'>" + temp + "&#176;C</div><div class='skycon'>" + desc + "</div></div>";
}

var latlng = $('.tianqi').text();
var pair = latlng.split(',');
var lat = pair[0], lng = pair[1];

var url = 'https://api.caiyunapp.com/v2/5AoOwKgLgmqmy=2i/' + lng + ',' + lat + '/weather.jsonp';

$.ajax({
    "url": url,
    "jsonp": "callback",
    "dataType": "jsonp",
    "data": {
        "getplacename": "True",
        "lang": "en"
    },
    "success": function( response ) {
        $('.tianqi').html(buildTianqi(response.placename, response.result.realtime.skycon, response.result.realtime.temperature));
    }
});


var url = 'http://poetrydb.org/author';
$.ajax({
    "url": url,
    "jsonp": "callback",
    "dataType": "jsonp",
    "success": function( response ) {
        console.log(response);
    }
});