User:Cloned/Interwiki Language Events

From Guild Wars 2 Wiki
Jump to: navigation, search

This is my script to display all events.

How to use it[edit]

Copy-Paste this to a new textfile (not word ;) ) and change the end from .txt to .html, open the page and give it a few seconds to load. It fetches every Event-Name for every language from the API, this can take a few seconds (for me it took ~8 seconds). The results are stored in the browser so that the next time you open the page it skips the api-call and the list appears instantly. If new events are added, clear the local storage and then generate the EventList again (it can take some seconds to build it again). It's not very pretty and not fool-proof, so if you click the "Generate complete Event List" button too fast, too often ... I don't know what happens.

The underline for visited links is just temporary, if you close your browser and open it again, you won't see it. But you can see where you left off because the textfield still has the name of the last events inside (at least for me in opera)

One last thing: To change the output from the german to the english names, find the OutputList function and change dictionary["de"] to dictionary["en"].

If you want to use this for the other wikis (es, fr) feel free to modify this to show the appropriate textfields

     <meta charset="utf-8" />
     <meta http-equiv="X-UA-Compatible" content="IE=10" />
     <title>GW2 language events</title>
     <!--<link type="text/css" rel="stylesheet" href="Content/style.css" />-->
        /*#test1 ul{width:40%;}*/
        #output{  width: 50%;
                    min-height: 400px;
                    border: 1px solid black;
                    position: fixed;
                    top: 1px;
                    right: 0;}

        #test1 li{padding:5px;cursor: pointer}
 			<label for="slctLang">Language:</label>
 			<select id="slctLang">
 				<option value="de">Deutsch</option>
 				<option value="en">English</option>
 				<option value="es">Espanol</option>
 				<option value="fr">French</option>

 			<button onclick="javascript:addEvents()"> Generate complete Event List</button>
      <button onclick="javascript:localStorage.clear();$('#test1').empty();"> Clear List</button>
 		<div id="test1"></div>
        <div id="output">
            <a id="linkDE" href="http://" target="ger"> Deutsch </a> <br>
            Edit: <a id="editDE" href="http://" target="ger"> Deutsch </a> <br>
            <textarea id="interwikiDE" rows="5" cols="100"> </textarea>

            <a id="linkEN" href="http://" target="en"> Englisch </a> </br>
            Edit: <a id="editEN" href="http://" target="en"> Englisch </a> <br>
            <textarea id="interwikiEN" rows="5" cols="100"> </textarea>
 <script src=""></script>
 <script type="text/javascript">

 const LANGUAGES = ["de", "en", "es", "fr"];
 var dictionary = {"de" : [], "en": [] , "es" :[] , "fr" :[]}, 
 EVENTS = {},
 eventNamesUri = "",
 i = LANGUAGES.length - 1; 

GW2 = window.GW2 || {} ;

GW2.EventNames = function(){
    i = LANGUAGES.length - 1;
    if (typeof LANGUAGES[i] != 'undefined'){
      callEvents( LANGUAGES[i])

$(document).ajaxComplete(function() {
  console.log("ajax complete");

function callEvents(lang){
            $.each(data, function () {
                for (key in this){
            localStorage.setItem('lang-'+lang, JSON.stringify(dictionary[lang] ) );
        }).done(function() {
          console.log(" call complete ", i);
          if (i == -1){
          else { callEvents(LANGUAGES[i]) }

//local storage -> if something is in localstorage, display it!
if (localStorage.getItem('lang-de') != null){
    dictionary["de"] = JSON.parse(localStorage.getItem('lang-de'));
    dictionary["en"] = JSON.parse(localStorage.getItem('lang-en'));
    dictionary["es"] = JSON.parse(localStorage.getItem('lang-es'));
    dictionary["fr"] = JSON.parse(localStorage.getItem('lang-fr'));
else {
    GW2Events = new GW2.EventNames();

function OutputList(){
    var j = dictionary["de"].length;
    var ul = document.createElement("ul");
    while (j--){
        var name = formatName(dictionary["de"][j]);
        var li = "<li data-index='"+j+"'>" + name  +"</li>"

function fillOutput(){

    $(this).css("text-decoration", "underline")

    //console.log(this); this = <li> .. </li>
    //generate DE 
    var index = $(this).data("index"), eventName = formatName(dictionary["de"][index]);
    $("#linkDE").attr("href", ""+eventName).html(eventName);
    $("#editDE").attr("href", ""+eventName+"&action=edit").html( "Edit "+eventName);

    var txt  = "[[en:"+formatName(dictionary["en"][index])+"]]\n";
        txt += "[[es:"+formatName(dictionary["es"][index])+"]]\n";
        txt += "[[fr:"+formatName(dictionary["fr"][index])+"]]";

    //generate EN
    eventName = formatName(dictionary["en"][index]);
    $("#linkEN").attr("href", ""+eventName).html(eventName);
    $("#editEN").attr("href", ""+eventName+"&action=edit").html( "Edit "+eventName);

    var txt  = "[[de:"+formatName(dictionary["de"][index])+"]]\n";
        txt += "[[es:"+formatName(dictionary["es"][index])+"]]\n";
        txt += "[[fr:"+formatName(dictionary["fr"][index])+"]]";


function formatName(name){
    if (name.indexOf("Défi de héros") != -1 ) {
        name = name.replace("Défi de héros : ","");
        name = name.charAt(0).toUpperCase() + name.slice(1);
        //tmp.substring(0,5) + tmp.charAt(5).toUpperCase() + tmp.substring(6,tmp.length) <- capitialize french

    if (name.indexOf("Hero Challenge: ") != -1 ) {
        name = name.replace("Hero Challenge: ","");
        name = name.charAt(0).toUpperCase() + name.slice(1);

    if (name.substr(name.length - 1) == ".") {
        return name.substring(0, name.length - 1);
    else {return name}

/*add events*/
//select in textarea
$("#output").on("click", "textarea", function() {;

$("#test1").on("click", "li", fillOutput);

function outputList(){	
 	i = eventsEN.Pairs.length;
 	while (i--) {
 		var pTag = "<p>";
 		pTag += '<a target="_blank" href="' + eventsEN.Pairs[i].name.substring(0, eventsEN.Pairs[i].name.length - 1) + '">'+ eventsEN.Pairs[i].name.substring(0, eventsEN.Pairs[i].name.length - 1) +'</a> <br />';
 		pTag += '<a target="_blank" href="http://wiki-'+ $('#slctLang').val()+'' + events.Pairs[i].name.substring(0, events.Pairs[i].name.length - 1) + '">'+ events.Pairs[i].name.substring(0, events.Pairs[i].name.length - 1) +'</a> <br /> </p>';

function addEvents(){
  GW2Events = new GW2.EventNames();