From ef1e3e178c0e9726612b1f3c1d1bd1a233982cab Mon Sep 17 00:00:00 2001 From: danbars Date: Mon, 28 May 2018 18:29:38 +0300 Subject: [PATCH] Easier read of log when there are multiple iframes When there are multiple iframes it is sometimes hard to read the log, especially if they don't have title. Added id to each frame so you can later reference to it from the log. Use hash method so the id is consistent across refresh of the page --- js/postMessage-debugger.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/js/postMessage-debugger.js b/js/postMessage-debugger.js index de23547..9b24e03 100644 --- a/js/postMessage-debugger.js +++ b/js/postMessage-debugger.js @@ -1,8 +1,12 @@ var postMessageDebugger = { + hashCode: function(s){ + return s.split("").reduce(function(a,b){a=((a<<5)-a)+b.charCodeAt(0);return a&a},0); + }, init: function() { - console.log("postMessageDebugger activated"); + var id = this.hashCode(window.location.href); + console.log("[" + id + "] postMessageDebugger activated on " + window.location.href); addEventListener("message", function(event) { - console.log(document.title + " received '" + event.data + "'") + console.log("[" + id + "]" + event.data ) }); } };