Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var frozenIceWrapper = function(){
- this.run = function() {
- console.log("ok");
- if (!this.supports_html5_storage()) {
- alert('Der Browser unterschtützt diese Technologie nicht!');
- } else {
- console.log("ok2");
- this.insertButtons();
- this.bindToChat();
- }
- };
- this.supports_html5_storage = function() { //http://stackoverflow.com/questions/17956343/can-you-save-load-a-file-via-javascript
- try
- {
- return 'localStorage' in window && window['localStorage'] !== null;
- }
- catch (e)
- {
- return false;
- }
- }
- this.bindToChat = function() {
- var saveToLog = this.saveToLog;
- $('.messagelist').bind('DOMNodeInserted', function(event) {
- var targetNode = event.target;
- var messagerow = targetNode.getElementsByClassName('messagerow');
- var textNodes = targetNode.getElementsByClassName('messagetext');
- var playerName = null;
- var message = "";
- for (node in textNodes) {
- //console.log(node + ": " + textNodes[node].innerHTML);
- if (node.substring(0,4) == "ms__") {
- console.log(node + ": " + textNodes[node].innerHTML);
- if (playerName == null) {
- playerName = textNodes[node].innerHTML;
- } else {
- message += textNodes[node].innerHTML + " ";
- }
- }
- }
- if (playerName != null) {
- var today = new Date();
- console.log("(" + today.getHours() + ":" + today.getMinutes() + ") " + playerName + " " + message);
- saveToLog("(" + today.getHours() + ":" + today.getMinutes() + ") " + playerName + " " + message + "<br>");
- }
- });
- };
- this.saveToLog = function(text) {
- var myDataString = localStorage.getItem("chatLogFrozen");
- if (myDataString == null) {myDataString = "";}
- myDataString += "\n" + text;
- localStorage.setItem("chatLogFrozen", myDataString);
- };
- this.clearLog = function() {
- if (confirm("Wollen sie den ChatLog löschen?")) {
- localStorage.removeItem("chatLogFrozen");
- }
- };
- this.downloadLog = function() {
- var temp = window.open('about:blank', 'example', '');
- var div = temp.document.createElement("div");
- div.innerHTML = "Logs<br>" + localStorage.getItem("chatLogFrozen");
- temp.document.body.appendChild( div );
- };
- this.insertButtons = function() {
- var divs = document.getElementsByClassName('dynmap-link leaflet-control');
- var div = divs[0];
- var divDownload = document.createElement("a");
- var divDelete = document.createElement("a");
- //divDownload.className = "dynmap-link-button";
- divDownload.title="Download Chat Log";
- divDownload.innerHTML = "Download";
- divDelete.title = "Delete Chat Log";
- divDelete.innerHTML = "Delete";
- div.appendChild(divDownload);
- div.appendChild(divDelete);
- divDownload.addEventListener("click", this.downloadLog);
- divDelete.addEventListener("click", this.clearLog);
- };
- }
- var chatLog = new frozenIceWrapper();
- chatLog.run();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement