MediaWiki:Gadget-site.js

From Caiyun Wiki
Revision as of 03:04, 30 August 2018 by Mingli (talk | contribs)
Jump to: navigation, search
//  _________________________________________________________________________________________
// |                                                                                         |
// |                    === 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. |
// |_________________________________________________________________________________________|
//

function buildTianqi(placename, skycon, temp) {
    return "<link href='https://fonts.googleapis.com/css?family=Roboto:400,300' rel='stylesheet' type='text/css'><div class='card'><span class='city'>" + placename + "</span> <br> <div class='" + skycon + "'> </div> <span class='temp'>" + temp + "&#176;C</span> <span> <ul class='variations'><li>" + skycon + "</li></ul> </span> </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 + '/forecast.jsonp';

$.ajax({
    "url": url,
    "jsonp": "callback",
    "dataType": "jsonp",
    "data": {
        "getplacename": true,
    },
    "success": function( response ) {
        console.log( response );
    }
});

$('.tianqi').html(tianqi);