ScriptUserNotes

Aus Horizon
Wechseln zu: Navigation, Suche

Dieses GreaseMonkey Script erweitert das Spiel um die Möglichkeit einfach Notizen hinterlegen zu können. Es wird ein neuer Knopf "N" in der Planetenminiübersicht hinzugefügt über den sich die Notizen ein- und ausblenden lassen.

Speicherung[Bearbeiten]

Die Notizen werden bei jeder Änderung automatisch im lokalen Speicher (localStorage) des Browsers abgelegt, vor einem Browserupdate sollte also eine Kopie angelegt werden. Die Notizen werden Browserspezifisch abgelegt, sind also an anderen Rechnern oder im Inkognitomodus nicht identisch.

Aussehen[Bearbeiten]

siehe http://postimg.org/image/o3m2nrqh7/

Code[Bearbeiten]

// ==UserScript==

// @name          Horizon - UserNotes

// @namespace     http://www.sueshi.tk

// @description   provides simple notesmanagment for Horizon Browser game

// @include       *horitest.goetterheimat.de/game/main/main.php*
// @include       *horiversum.de/game/main/main.php*
// @include       *horiversum.org/game/main/main.php*

// @author        Dr.Ecksack
// @version       2014.03.11

// ==/UserScript==


function generateHorizonUserNotes(){

    //Notes-Button in Planetbar
    var planetsdiv = document.getElementsByClassName('TickPlanetList');
    var notesTickEntry = document.createElement('div');
    notesTickEntry.setAttribute('class', 'TickPlanetEntry');

    var notesTickImageDiv = document.createElement('div');
    notesTickImageDiv.className = "TickPlanetDiv";
    notesTickImageDiv.style.cursor = 'pointer';
    notesTickImageDiv.onclick = toggleHorizonUserNotesVisibility;

    notesTickImageDiv.appendChild(document.createTextNode('N'));
    notesTickImageDiv.style.color = "white";
    notesTickImageDiv.style.fontSize = "15px";
    notesTickImageDiv.style.fontWeight = "bold";
    notesTickImageDiv.style.textAlign = "center";

    notesTickEntry.appendChild(notesTickImageDiv);

    planetsdiv[0].appendChild(notesTickEntry);

    //--------

    var notesDiv = document.createElement('div');
    notesDiv.style.position = 'absolute';
    notesDiv.style.top = '160px';
    notesDiv.style.left = '800px';
    notesDiv.style.right = "10px";
    notesDiv.style.minWidth = "300px";
    //notesDiv.style.width = document.getElementsByClassName('TickContainer')[0].style.width;
    notesDiv.setAttribute('id', 'horizon_user_notes_div');


    var notesTextarea = document.createElement('textarea');
    notesTextarea.setAttribute('rows', '20');
    notesTextarea.setAttribute('id', 'horizon_user_notes_textarea');
    notesTextarea.style.width = "100%";
    notesTextarea.style.font = 'bold 11px Verdana';
    notesTextarea.style.color = '#E9E8E4';
    notesTextarea.style.border = '1px solid #ADB1B9';
    notesTextarea.style.backgroundColor = '#242E37';
    notesTextarea.appendChild(document.createTextNode(window.localStorage.getItem('Horizon_user_note')));

    //we want to save the note with every key stoke to prevent data loss during page-reloads
    notesTextarea.onkeyup = saveHorizonUserNotes;
    
    
    var notesBackupButton = document.createElement("img");
    notesBackupButton.src = "http://sueshi.tk/images/prioritydown.png";
    notesBackupButton.style.position = "absolute";
    notesBackupButton.style.top = "10px";
    notesBackupButton.style.right = "20px";
    
    var notesBackupLink = document.createElement("a");
    notesBackupLink.onclick = function(){
        //we want to get the content of current state
        this.href = "data:text/csv;charset=utf-8," + encodeURIComponent(window.localStorage.getItem('Horizon_user_note'));
        return true;
    };
    notesBackupLink.download = "horizon_usernotes.txt"; //this is HTML5 only
    notesBackupLink.appendChild(notesBackupButton);
    

    notesDiv.appendChild(notesTextarea);
    notesDiv.appendChild(notesBackupLink);


    //if the user hid the div, we will do this here too
    notesDiv.style.display = window.localStorage.getItem('horizon_user_notes_visibility');
    
    document.body.appendChild(notesDiv);
}

function saveHorizonUserNotes(){
    //console.log('saving data: ' + document.getElementById('horizon_user_notes_textarea').value);
    window.localStorage.setItem('Horizon_user_note', document.getElementById('horizon_user_notes_textarea').value);
}

function toggleHorizonUserNotesVisibility(){
    var notesDiv = document.getElementById('horizon_user_notes_div');
    var NotesVisibility = window.localStorage.getItem('horizon_user_notes_visibility');
    if (NotesVisibility == 'block'){
        window.localStorage.setItem('horizon_user_notes_visibility', 'none');
    }else{
        window.localStorage.setItem('horizon_user_notes_visibility', 'block');
    }
    notesDiv.style.display = window.localStorage.getItem('horizon_user_notes_visibility');
}

//dont show in fleet details view
if (document.URL.indexOf("main.php?cmd=fleet&subcmd=view") != -1){
    //console.log("we are in fleet details view");
    return 0;
}


generateHorizonUserNotes();