MediaWiki:Common.js: Difference between revisions

From Puucraft Wiki
Content added Content deleted
No edit summary
Tag: Manual revert
No edit summary
Line 25: Line 25:


fetch_worldguard_data()
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(d.getTime() - map.getTime());

var to_modify = document.getElementById('map_age')
to_modify.innerHTML = (diff.getYear() - 70) + " years, " + (diff.getMonth() + 1) + " months, " + diff.getDate() + " days, " + diff.getHours() + " hours, " + diff.getMinutes() + " minutes, " + diff.getSeconds() + " seconds."
}
get_time_difference_from_current(1628798400000)
}
}

Revision as of 12:02, 26 August 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'}) /* gosh, how do i get around CSP? */
    .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("FETCH 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(d.getTime() - map.getTime());

   var to_modify = document.getElementById('map_age')
   to_modify.innerHTML = (diff.getYear() - 70) + " years, " + (diff.getMonth() + 1) + " months, " + diff.getDate() + " days, " + diff.getHours() + " hours, " + diff.getMinutes() + " minutes, " + diff.getSeconds() + " seconds."
  }
  get_time_difference_from_current(1628798400000)
}