MediaWiki:Common.js: Difference between revisions
Content added Content deleted
No edit summary |
mNo edit summary |
||
(4 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
/* Any JavaScript here will be loaded for all users on every page load. */ |
/* Any JavaScript here will be loaded for all users on every page load. */ |
||
if ( mw.config.get('wgPageName') === 'Current_worldguards' ) { |
|||
function fetch_worldguard_data() { |
function fetch_worldguard_data() { |
||
fetch("https://puucraft-dynmap-regionsworldjson-test.mixarium.repl.co/", {"method": "GET", "mode": 'cors', |
fetch("https://puucraft-dynmap-regionsworldjson-test.mixarium.repl.co/", {"method": "GET", "mode": 'cors', "content-security-policy": "connect-src 'self'"}) |
||
.then(function(response) { |
.then(function(response) { |
||
if (response.ok) { |
if (response.ok) { |
||
return response.json() |
return response.json(); |
||
} else { |
} else { |
||
throw new Error("NETWORK RESPONSE ERROR") |
throw new Error("NETWORK RESPONSE ERROR"); |
||
}; |
}; |
||
}) |
}) |
||
Line 21: | Line 21: | ||
}; |
}; |
||
}) |
}) |
||
.catch(function (error) {console.error( |
.catch(function (error) {console.error(error)}) |
||
}; |
}; |
||
fetch_worldguard_data() |
fetch_worldguard_data() |
||
}; |
}; |
||
*/ |
|||
if ( mw.config.get('wgPageName') === 'Puucraft' ) { |
if ( mw.config.get('wgPageName') === 'Puucraft' ) { |
||
function get_time_difference_from_current(unix_in_ms) { |
function get_time_difference_from_current(unix_in_ms) { |
Latest revision as of 11:42, 24 September 2022
/* Any JavaScript here will be loaded for all users on every page load. */
if ( mw.config.get('wgPageName') === 'Current_worldguards' ) {
function fetch_worldguard_data() {
fetch("https://puucraft-dynmap-regionsworldjson-test.mixarium.repl.co/", {"method": "GET", "mode": 'cors', "content-security-policy": "connect-src 'self'"})
.then(function(response) {
if (response.ok) {
return response.json();
} else {
throw new Error("NETWORK RESPONSE ERROR");
};
})
.then(function(data) {
var div_for_worldguard_list = document.getElementById('load_fetched_json_worldguard_data');
var list = document.createElement('ul');
for (var i = 0; i < Object.keys(data).length; i++) {
var li = document.createElement('li');
li.innerHTML = data[i]['name'];
list.appendChild(li);
div_for_worldguard_list.appendChild(list);
};
})
.catch(function (error) {console.error(error)})
};
fetch_worldguard_data()
};
if ( mw.config.get('wgPageName') === 'Puucraft' ) {
function get_time_difference_from_current(unix_in_ms) {
var map_launch = new Date(unix_in_ms);
var current_date = new Date();
var diff = new Date(current_date.getTime() - map_launch.getTime() - 10800000);
var to_modify = document.getElementById('map_age')
to_modify.innerHTML = "The current map, Map 11, is " + (diff.getYear() - 70) + " year(s), " + diff.getMonth() + " month(s), " + diff.getDate() + " day(s), " + diff.getHours() + " hour(s), " + diff.getMinutes() + " minute(s), " + diff.getSeconds() + " second(s) old."
};
get_time_difference_from_current(1628798400000)
};