"use strict";
var Marks = {
  handlerId: 0,
  activateCreateMode: function() {
    this.handlerId = handlerStack.push({
      keydown: this.onKeydown,
      keypress: this._create,
      _this: this
    });
    VHUD.show("Create mark ...");
  },
  activateGotoMode: function() {
    this.handlerId = handlerStack.push({
      keydown: this.onKeydown,
      keypress: this._goto,
      _this: this
    });
    VHUD.show("Go to mark ...");
  },
  clearLocal: function() {
    var key_start, storage, i, key;
    this._previous = null;
    key_start = this.getLocationKey("");
    storage = localStorage;
    for (i = storage.length; 0 <= --i; ) {
      key = storage.key(i);
      if (key.startsWith(key_start)) {
        storage.removeItem(key);
      }
    }
    VHUD.showForDuration("Local marks have been cleared.", 1000);
  },
  onKeydown: function() {
    if (event.keyCode === KeyCodes.esc && KeyboardUtils.isPlain(event)) {
      handlerStack.remove(this.handlerId);
      VHUD.hide();
      return false;
    }
    return -1;
  },
  getBaseUrl: function() {
    return window.location.href.split('#', 1)[0];
  },
  getLocationKey: function(keyChar) {
    return "vimiumMark|" + this.getBaseUrl() + "|" + keyChar;
  },
  _previous: null,
  setPreviousPosition: function() {
    this._previous = {
      scrollX: window.scrollX,
      scrollY: window.scrollY
    };
  },
  _create: function(event) {
    var keyChar = String.fromCharCode(event.charCode);
    handlerStack.remove(this.handlerId);
    if (event.shiftKey) {
      this.CreateGlobalMark({markName: keyChar});
    } else if (keyChar === "`" || keyChar === "'") {
      this.setPreviousPosition();
      VHUD.showForDuration("Created local mark [last].", 1000);
    } else {
      localStorage[this.getLocationKey(keyChar)] = JSON.stringify({
        scrollX: window.scrollX,
        scrollY: window.scrollY
      });
      VHUD.showForDuration("Created local mark : ' " + keyChar + " '.", 1000);
    }
    return false;
  },
  _goto: function(event) {
    var keyChar = String.fromCharCode(event.charCode), markString, position;
    handlerStack.remove(this.handlerId);
    if (event.shiftKey) {
      MainPort.sendMessage({
        handler: "gotoMark",
        markName: keyChar
      }, function(req) {
        if (req === false) {
          VHUD.showForDuration("Global mark not set : ' " + keyChar + " '.", 1500);
        }
      });
      VHUD.hide();
    } else if (keyChar === "`" || keyChar === "'") {
      position = this._previous;
      this.setPreviousPosition();
      if (position) {
        window.scrollTo(position.scrollX, position.scrollY);
        VHUD.showForDuration("Jumped to local mark [last]", 1000);
      } else {
        VHUD.showForDuration("Created local mark [last]", 1000);
      }
    } else if (markString = localStorage[this.getLocationKey(keyChar)]) {
      position = JSON.parse(markString);
      this.setPreviousPosition();
      window.scrollTo(position.scrollX, position.scrollY);
      VHUD.showForDuration("Jumped to local mark : ' " + keyChar + " '.", 1000);
    } else {
      VHUD.showForDuration("Local mark not set : ' " + keyChar + " '.", 2000);
    }
    return false;
  },
  CreateGlobalMark: function(request) {
    var keyChar = request.markName;
    if (window.top !== window && !request.force) {
      MainPort.port.postMessage({handler: "createMark", markName: keyChar});
      VHUD.hide();
      return;
    }
    MainPort.port.postMessage({
      handler: "createMark",
      markName: keyChar,
      url: Marks.getBaseUrl(),
      scroll: [window.scrollX, window.scrollY]
    });
    VHUD.showForDuration("Created global mark : ' " + keyChar + " '.", 1000);
  },
  Goto: function(request) {
    var scroll = request.scroll;
    if (!document.body || document.body.nodeName.toLowerCase() !== "frameset") {
      window.focus();
    }
    if (request.markName) {
      Marks.setPreviousPosition();
      window.scrollTo(scroll[0], scroll[1]);
      VHUD.showForDuration("Jumped to global mark : ' " + request.markName + " '.", 2000);
    } else {
      window.scrollTo(scroll[0], scroll[1]);
    }
  }
};

@@ -567,16 +567,26 @@
 ey(%22%22);%0A
+    try %7B%0A
     stor
@@ -758,24 +758,45 @@
     %7D%0A    %7D%0A
+    %7D catch (key) %7B%7D%0A
     VHUD.sho
@@ -1761,24 +1761,38 @@
    %7D else %7B%0A
+      try %7B%0A  
       localS
@@ -1847,16 +1847,18 @@
 ngify(%7B%0A
+  
         
@@ -1886,24 +1886,26 @@
 lX,%0A        
+  
 scrollY: win
@@ -1918,28 +1918,173 @@
 rollY%0A      
+  
 %7D);%0A
+      %7D catch (keyChar) %7B%0A        VHUD.showForDuration(%22Failed to creat local mark (localStorage error)%22, 2000);%0A        return false;%0A      %7D%0A
       VHUD.s
@@ -2980,20 +2980,38 @@
  %7D else 
-if (
+%7B%0A      try %7B%0A        
 markStri
@@ -3057,20 +3057,71 @@
 eyChar)%5D
-) %7B%0A
+;%0A      %7D catch (keyChar) %7B%7D%0A      if (markString) %7B%0A  
       po
@@ -3151,32 +3151,34 @@
 kString);%0A      
+ 
+ 
 this.setPrevious
@@ -3181,32 +3181,34 @@
 iousPosition();%0A
+  
       window.scr
@@ -3248,32 +3248,34 @@
 scrollY);%0A      
+  
 VHUD.showForDura
@@ -3329,32 +3329,34 @@
 '.%22, 1000);%0A    
+ 
+ 
 %7D else %7B%0A      V
@@ -3344,24 +3344,26 @@
    %7D else %7B%0A
+  
       VHUD.s
@@ -3425,24 +3425,32 @@
 '.%22, 2000);%0A
+      %7D%0A
     %7D%0A    re

fix localStorage error