From 8a0c471440c1eec74517f4dfc954948ded85ebfe Mon Sep 17 00:00:00 2001 From: therealbitkid Date: Sat, 18 Jun 2011 18:55:42 +0000 Subject: [PATCH 1/3] small code fixes --- vim-keybindings.js | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/vim-keybindings.js b/vim-keybindings.js index 2b8c070..d879157 100644 --- a/vim-keybindings.js +++ b/vim-keybindings.js @@ -31,7 +31,7 @@ var handler = function(e) { window.document.activeElement.blur(); break; case 8: - if (window.document.activeElement.id == "vimOverlayTextinput" && window.document.activeElement.value == '') { + if (window.document.activeElement.id == "vimOverlayTextinput" && window.document.activeElement.value === '') { window.document.activeElement.blur(); document.getElementById('vimOverlay').style.display = "none"; e.preventDefault(); @@ -95,7 +95,7 @@ var handler = function(e) { return false; } return true; - } + }; switch (e.keyIdentifier) { case "U+003A": @@ -104,7 +104,7 @@ var handler = function(e) { e.preventDefault(); break; case "U+0008": - if (document.getElementById('vimOverlay').style.display == "block" && document.getElementById('vimOverlayTextinput').value == '') { + if (document.getElementById('vimOverlay').style.display == "block" && document.getElementById('vimOverlayTextinput').value === '') { document.getElementById('vimOverlayTextinput').blur(); document.getElementById('vimOverlay').style.display = "none"; } @@ -115,7 +115,7 @@ var handler = function(e) { } t.keyCommand(combokey, e); -} +}; t.keyCommand = function(c, e) { @@ -156,7 +156,7 @@ t.keyCommand = function(c, e) { } break; case 'dd': - if (t.functionkeys({'none': '1'}) && t.lastActiveElement != undefined) { + if (t.functionkeys({'none': '1'}) && t.lastActiveElement !== undefined) { t.lastActiveElement.value = ''; } break; @@ -181,7 +181,7 @@ t.keyCommand = function(c, e) { } break; case 'i': - if (t.lastActiveElement != undefined) { + if (t.lastActiveElement !== undefined) { t.lastActiveElement.focus(); e.preventDefault(); } @@ -211,10 +211,10 @@ t.keyCommand = function(c, e) { t.resetCombo(); } -} +}; t.inputCommand = function(command) { - if (command == '') return; + if (command === '') return; if (command.charAt(0) == "%") { t.percentCommand(command); @@ -228,7 +228,7 @@ t.inputCommand = function(command) { case 'tabedit': case 'e': case 'edit': - if (param[1] == "" || param[1] == undefined) { + if (param[1] === "" || param[1] === undefined) { if (param[0] == 'e' || param[0] == 'edit') { alert('Usage: command "edit" or "e" for short, opens the url specified as first parameter in the current tab'); } else { @@ -236,7 +236,7 @@ t.inputCommand = function(command) { } } else { - var url = param[1] + var url = param[1]; if (url.substr(0,5) != "http:" && url.substr(0,6) != "https:") { url = "http://" + url; } @@ -278,14 +278,14 @@ t.inputCommand = function(command) { break; } -} +}; t.percentCommand = function(command) { param = command.split("/"); switch (param[0]) { case "%s": - if (t.lastActiveElement == undefined) break; + if (t.lastActiveElement === undefined) break; if (param.length == 3 || param.length == 4) { var mod = ""; if (param.length == 4) mod = param[3]; @@ -294,16 +294,16 @@ t.percentCommand = function(command) { } break; } -} +}; t.resetCombo = function() { combokey = ''; multiplier = 0; -} +}; t.disable = function() { window.document.removeEventListener("keydown", handler, false); -} +}; function getAnswer(theMessageEvent) { switch (theMessageEvent.name) { From 8ae1eb439da18e54aae21cef2e4d3e0e6030170a Mon Sep 17 00:00:00 2001 From: Amadeus Demarzi Date: Thu, 1 Dec 2011 10:34:06 -0800 Subject: [PATCH 2/3] Whitespace and lint fixes --- globalpage.html | 279 +++++++++++++------------ overlay.js | 6 +- vim-keybindings.js | 504 ++++++++++++++++++++++----------------------- 3 files changed, 393 insertions(+), 396 deletions(-) diff --git a/globalpage.html b/globalpage.html index 15a0136..d9e5198 100644 --- a/globalpage.html +++ b/globalpage.html @@ -1,154 +1,153 @@ - global page - - - - +} +safari.application.addEventListener("message",respondToMessage,false); + + + + diff --git a/overlay.js b/overlay.js index 1b529a0..38893cd 100644 --- a/overlay.js +++ b/overlay.js @@ -15,7 +15,7 @@ if (window.top === window) { overlay.style.display = "none"; overlay.setAttribute('id', 'vimOverlay'); overlay.style.opacity = ".9"; - overlay.style.zIndex = "2147483648"; + overlay.style.zIndex = "2147483648"; var overlayTextinput = document.createElement("input"); overlayTextinput.style.border = "0"; @@ -25,11 +25,9 @@ if (window.top === window) { overlayTextinput.style.color = "black"; overlayTextinput.style.margin = "0"; overlayTextinput.style.opacity = ".9"; - overlayTextinput.style.clear = "none"; + overlayTextinput.style.clear = "none"; overlayTextinput.setAttribute('id', 'vimOverlayTextinput'); document.body.insertBefore(overlay, document.body.firstChild); overlay.appendChild(overlayTextinput); - - } diff --git a/vim-keybindings.js b/vim-keybindings.js index 2b8c070..5cdefcf 100644 --- a/vim-keybindings.js +++ b/vim-keybindings.js @@ -5,31 +5,31 @@ var timer; var loaded = false; var handler = function(e) { - var c = String.fromCharCode(e.keyCode).toLowerCase(); - if(e.shiftKey) c = c.toUpperCase(); - if (e.keyCode > 32 && e.keyCode < 91) { - if (parseInt(c, 10) == c) { - multiplier = (multiplier * 10) + c; - } else { - combokey += c; - } - clearTimeout(timer); - timer = window.setTimeout(function() { combokey = ''; multiplier = 0; }, 5000); - } - - if(window.document.activeElement !== window.document.body) { - switch (e.keyCode) { + var c = String.fromCharCode(e.keyCode).toLowerCase(); + if(e.shiftKey) c = c.toUpperCase(); + if (e.keyCode > 32 && e.keyCode < 91) { + if (parseInt(c, 10) == c) { + multiplier = (multiplier * 10) + c; + } else { + combokey += c; + } + clearTimeout(timer); + timer = window.setTimeout(function() { combokey = ''; multiplier = 0; }, 5000); + } + + if(window.document.activeElement !== window.document.body) { + switch (e.keyCode) { case 27: - if (document.getElementById('vimOverlay').style.display == "block") { - document.getElementById('vimOverlay').style.display = 'none'; - document.getElementById('vimOverlayTextinput').value = ''; - } else { - t.lastActiveElement = window.document.activeElement; - } - combokey = ''; - multiplier = 0; - window.document.activeElement.blur(); - break; + if (document.getElementById('vimOverlay').style.display == "block") { + document.getElementById('vimOverlay').style.display = 'none'; + document.getElementById('vimOverlayTextinput').value = ''; + } else { + t.lastActiveElement = window.document.activeElement; + } + combokey = ''; + multiplier = 0; + window.document.activeElement.blur(); + break; case 8: if (window.document.activeElement.id == "vimOverlayTextinput" && window.document.activeElement.value == '') { window.document.activeElement.blur(); @@ -45,181 +45,181 @@ var handler = function(e) { document.getElementById('vimOverlay').style.display = "none"; } break; - } - return; - } else { + } + return; + } else { - switch (e.keyCode) { + switch (e.keyCode) { case 27: - t.resetCombo(); - break; - } - } - - t.scroll = function(x, y) { - window.scrollBy(x, y); - }; - t.scrollTo = function(x, y) { - window.scrollTo(x, y); - }; - - t.halfWindowHeight = function() { - return window.innerHeight / 2; - }; - - t.fullWindowHeight = function() { - return window.innerHeight; - }; - - t.screenHeight = function() { - return document.body.offsetHeight; - }; - - t.functionkeys = function(keys) { - if (keys.none == '1' && (e.altKey || e.metaKey || e.ctrlKey || e.altGraphKey || e.shiftKey)) { - return false; - } - if ((keys.alt != '1' && e.altKey) || (keys.alt == '1' && !e.altKey)) { - return false; - } - if ((keys.meta != '1' && e.metaKey) || (keys.meta == '1' && !e.metaKey)) { - return false; - } - if ((keys.ctrl != '1' && e.ctrlKey) || (keys.ctrl == '1' && !e.ctrlKey)) { - return false; - } - if ((keys.altgr != '1' && e.altGraphKey) || (keys.altgr == '1' && !e.altGraphKey)) { - return false; - } - if ((keys.shift != '1' && e.shiftKey) || (keys.shift == '1' && !e.shiftKey)) { - return false; - } - return true; - } - - switch (e.keyIdentifier) { - case "U+003A": - document.getElementById('vimOverlay').style.display = "block"; - document.getElementById('vimOverlayTextinput').focus(); - e.preventDefault(); + t.resetCombo(); + break; + } + } + + t.scroll = function(x, y) { + window.scrollBy(x, y); + }; + t.scrollTo = function(x, y) { + window.scrollTo(x, y); + }; + + t.halfWindowHeight = function() { + return window.innerHeight / 2; + }; + + t.fullWindowHeight = function() { + return window.innerHeight; + }; + + t.screenHeight = function() { + return document.body.offsetHeight; + }; + + t.functionkeys = function(keys) { + if (keys.none == '1' && (e.altKey || e.metaKey || e.ctrlKey || e.altGraphKey || e.shiftKey)) { + return false; + } + if ((keys.alt != '1' && e.altKey) || (keys.alt == '1' && !e.altKey)) { + return false; + } + if ((keys.meta != '1' && e.metaKey) || (keys.meta == '1' && !e.metaKey)) { + return false; + } + if ((keys.ctrl != '1' && e.ctrlKey) || (keys.ctrl == '1' && !e.ctrlKey)) { + return false; + } + if ((keys.altgr != '1' && e.altGraphKey) || (keys.altgr == '1' && !e.altGraphKey)) { + return false; + } + if ((keys.shift != '1' && e.shiftKey) || (keys.shift == '1' && !e.shiftKey)) { + return false; + } + return true; + }; + + switch (e.keyIdentifier) { + case "U+003A": + document.getElementById('vimOverlay').style.display = "block"; + document.getElementById('vimOverlayTextinput').focus(); + e.preventDefault(); + break; + case "U+0008": + if (document.getElementById('vimOverlay').style.display == "block" && document.getElementById('vimOverlayTextinput').value == '') { + document.getElementById('vimOverlayTextinput').blur(); + document.getElementById('vimOverlay').style.display = "none"; + } break; - case "U+0008": - if (document.getElementById('vimOverlay').style.display == "block" && document.getElementById('vimOverlayTextinput').value == '') { - document.getElementById('vimOverlayTextinput').blur(); - document.getElementById('vimOverlay').style.display = "none"; - } + case "U+0027": + combokey += "'"; break; - case "U+0027": - combokey += "'"; - break; - } + } - t.keyCommand(combokey, e); -} + t.keyCommand(combokey, e); +}; t.keyCommand = function(c, e) { - - var reset_combo = true; - var SCROLL_STEP = 35; - - switch(c) { - case 'gg': - if (t.functionkeys({'none': '1'})) { - t.scrollTo(0,0); - } - break; - case 'h': - if (t.functionkeys({'none': '1'})) { - t.scroll(-SCROLL_STEP, 0); - } - break; - case 'j': - if (t.functionkeys({'none': '1'})) { - t.scroll(0, SCROLL_STEP); - } - break; - case 'k': - if (t.functionkeys({'none': '1'})) { - t.scroll(0, -SCROLL_STEP); - } - break; - case 'l': - if (t.functionkeys({'none': '1'})) { - t.scroll(SCROLL_STEP, 0); - } - break; - case 'd': - if (t.functionkeys({'ctrl': '1'})) { - t.scroll(0, t.halfWindowHeight()); - } else { - reset_combo = false; - } - break; - case 'dd': - if (t.functionkeys({'none': '1'}) && t.lastActiveElement != undefined) { - t.lastActiveElement.value = ''; - } - break; - case 'f': - if(t.functionkeys({'ctrl': '1'})) { - t.scroll(0, t.fullWindowHeight()); - } - break; - case 'u': - if(t.functionkeys({'ctrl': '1'})) { - t.scroll(0, -t.halfWindowHeight()); - } - break; - case 'b': - if(t.functionkeys({'ctrl': '1'})) { - t.scroll(0, -t.fullWindowHeight()); - } - break; - case 'G': - if (t.functionkeys({'shift': '1'})) { - t.scrollTo(0, t.screenHeight()); - } - break; - case 'i': - if (t.lastActiveElement != undefined) { - t.lastActiveElement.focus(); - e.preventDefault(); - } - break; - case 'gT': - if (t.functionkeys({'shift': '1'})) { - safari.self.tab.dispatchMessage("prevTab",""); - } - break; - case 'gt': - if (t.functionkeys({'none': '1'})) { - safari.self.tab.dispatchMessage("nextTab",multiplier); - } - break; - /*case '\'\'': - if (t.functionkeys({'none': '1'})) { - safari.self.tab.dispatchMessage("backTab", ""); - } - break;*/ - - default: - reset_combo = false; - break; - } - - if (reset_combo || c.length > 4) { - t.resetCombo(); - } - -} + + var reset_combo = true; + var SCROLL_STEP = 35; + + switch(c) { + case 'gg': + if (t.functionkeys({'none': '1'})) { + t.scrollTo(0,0); + } + break; + case 'h': + if (t.functionkeys({'none': '1'})) { + t.scroll(-SCROLL_STEP, 0); + } + break; + case 'j': + if (t.functionkeys({'none': '1'})) { + t.scroll(0, SCROLL_STEP); + } + break; + case 'k': + if (t.functionkeys({'none': '1'})) { + t.scroll(0, -SCROLL_STEP); + } + break; + case 'l': + if (t.functionkeys({'none': '1'})) { + t.scroll(SCROLL_STEP, 0); + } + break; + case 'd': + if (t.functionkeys({'ctrl': '1'})) { + t.scroll(0, t.halfWindowHeight()); + } else { + reset_combo = false; + } + break; + case 'dd': + if (t.functionkeys({'none': '1'}) && t.lastActiveElement != undefined) { + t.lastActiveElement.value = ''; + } + break; + case 'f': + if(t.functionkeys({'ctrl': '1'})) { + t.scroll(0, t.fullWindowHeight()); + } + break; + case 'u': + if(t.functionkeys({'ctrl': '1'})) { + t.scroll(0, -t.halfWindowHeight()); + } + break; + case 'b': + if(t.functionkeys({'ctrl': '1'})) { + t.scroll(0, -t.fullWindowHeight()); + } + break; + case 'G': + if (t.functionkeys({'shift': '1'})) { + t.scrollTo(0, t.screenHeight()); + } + break; + case 'i': + if (t.lastActiveElement != undefined) { + t.lastActiveElement.focus(); + e.preventDefault(); + } + break; + case 'gT': + if (t.functionkeys({'shift': '1'})) { + safari.self.tab.dispatchMessage("prevTab",""); + } + break; + case 'gt': + if (t.functionkeys({'none': '1'})) { + safari.self.tab.dispatchMessage("nextTab",multiplier); + } + break; + /*case '\'\'': + if (t.functionkeys({'none': '1'})) { + safari.self.tab.dispatchMessage("backTab", ""); + } + break;*/ + + default: + reset_combo = false; + break; + } + + if (reset_combo || c.length > 4) { + t.resetCombo(); + } + +}; t.inputCommand = function(command) { if (command == '') return; - if (command.charAt(0) == "%") { - t.percentCommand(command); - return; - } + if (command.charAt(0) == "%") { + t.percentCommand(command); + return; + } param = command.split(" "); @@ -227,7 +227,7 @@ t.inputCommand = function(command) { case 'tabe': case 'tabedit': case 'e': - case 'edit': + case 'edit': if (param[1] == "" || param[1] == undefined) { if (param[0] == 'e' || param[0] == 'edit') { alert('Usage: command "edit" or "e" for short, opens the url specified as first parameter in the current tab'); @@ -236,7 +236,7 @@ t.inputCommand = function(command) { } } else { - var url = param[1] + var url = param[1]; if (url.substr(0,5) != "http:" && url.substr(0,6) != "https:") { url = "http://" + url; } @@ -247,82 +247,82 @@ t.inputCommand = function(command) { } } break; - - case 'q': + + case 'q': safari.self.tab.dispatchMessage("closeTab"); break; - case 'qa': - safari.self.tab.dispatchMessage("closeWindow"); - break; - - case 'tabn': - safari.self.tab.dispatchMessage("nextTab",0); - break; - - case 'tabp': - safari.self.tab.dispatchMessage("prevTab",""); - break; - - case 'tabfirst': - case 'tabfir': - safari.self.tab.dispatchMessage("nextTab",1); - break; - - case 'tablast': - safari.self.tab.dispatchMessage("nextTab","last"); - break; - - case 'tabnew': - safari.self.tab.dispatchMessage("newTab",""); - break; - + case 'qa': + safari.self.tab.dispatchMessage("closeWindow"); + break; + + case 'tabn': + safari.self.tab.dispatchMessage("nextTab",0); + break; + + case 'tabp': + safari.self.tab.dispatchMessage("prevTab",""); + break; + + case 'tabfirst': + case 'tabfir': + safari.self.tab.dispatchMessage("nextTab",1); + break; + + case 'tablast': + safari.self.tab.dispatchMessage("nextTab","last"); + break; + + case 'tabnew': + safari.self.tab.dispatchMessage("newTab",""); + break; + } -} +}; t.percentCommand = function(command) { param = command.split("/"); - - switch (param[0]) { - case "%s": - if (t.lastActiveElement == undefined) break; - if (param.length == 3 || param.length == 4) { - var mod = ""; - if (param.length == 4) mod = param[3]; - var regex = new RegExp(param[1], mod); - t.lastActiveElement.value = t.lastActiveElement.value.replace(regex, param[2]); - } - break; - } -} + + switch (param[0]) { + case "%s": + if (t.lastActiveElement == undefined) break; + if (param.length == 3 || param.length == 4) { + var mod = ""; + if (param.length == 4) mod = param[3]; + var regex = new RegExp(param[1], mod); + t.lastActiveElement.value = t.lastActiveElement.value.replace(regex, param[2]); + } + break; + } +}; t.resetCombo = function() { - combokey = ''; - multiplier = 0; -} + combokey = ''; + multiplier = 0; +}; t.disable = function() { - window.document.removeEventListener("keydown", handler, false); -} + window.document.removeEventListener("keydown", handler, false); +}; function getAnswer(theMessageEvent) { switch (theMessageEvent.name) { - case "resetcombo": - t.resetCombo(); - break; - - case "disable": - if (loaded) { - t.disable(); - } - break; - - case "load": - if (!loaded) { - loaded = true; - window.document.addEventListener("keydown", handler); - } - break; + case "resetcombo": + t.resetCombo(); + break; + + case "disable": + if (loaded) { + t.disable(); + } + break; + + case "load": + if (!loaded) { + loaded = true; + window.document.addEventListener("keydown", handler); + } + break; } } safari.self.addEventListener("message", getAnswer, false); From c3ebeb5f060e022e3b3b5d37f6ad950cdf30de62 Mon Sep 17 00:00:00 2001 From: Khaled Hussein Date: Thu, 28 Jun 2012 10:53:33 -0700 Subject: [PATCH 3/3] Adds a couple more keybindings. The README.md is updated with the documentation of the added bindings. I've also done a lot of :retab to get the style fixed. --- Info.plist | 92 +++++++++++---------- README.md | 24 +++--- Settings.plist | 16 ++-- globalpage.html | 202 ++++++++++++++++++++++----------------------- vim-keybindings.js | 21 +++-- 5 files changed, 183 insertions(+), 172 deletions(-) diff --git a/Info.plist b/Info.plist index 0a51306..6764c01 100644 --- a/Info.plist +++ b/Info.plist @@ -2,50 +2,52 @@ - Author - Mutwin Kraus, Jannik Nielsen - CFBundleDisplayName - vim - CFBundleIdentifier - com.mutwinkraus.vim - CFBundleInfoDictionaryVersion - 6.0 - CFBundleShortVersionString - 0.6 - CFBundleVersion - 2 - Chrome - - Database Quota - 1048576 - Global Page - globalpage.html - - Content - - Scripts - - End - - overlay.js - - Start - - vim-keybindings.js - - - - ExtensionInfoDictionaryVersion - 1.0 - Permissions - - Website Access - - Include Secure Pages - - Level - All - - + Author + Mutwin Kraus, Jannik Nielsen, Khaled Hussein + Builder Version + 7534.57.2 + CFBundleDisplayName + Vim Bindings + CFBundleIdentifier + com.mutwinkraus.vim + CFBundleInfoDictionaryVersion + 6.0 + CFBundleShortVersionString + 0.6 + CFBundleVersion + 2 + Chrome + + Database Quota + 1048576 + Global Page + globalpage.html + + Content + + Scripts + + End + + overlay.js + + Start + + vim-keybindings.js + + + + ExtensionInfoDictionaryVersion + 1.0 + Permissions + + Website Access + + Include Secure Pages + + Level + All + + diff --git a/README.md b/README.md index 399972c..8c21eba 100644 --- a/README.md +++ b/README.md @@ -1,15 +1,16 @@ -Vim Keybindings for Safari --------------------------- +# Vim Keybindings for Safari -Currently supported keys: +## Currently supported keys: * gg, G * h, j, k, l * ^D, ^U, ^F, ^B * esc, i, dd * gt, gT, gt +* t -- starts a new tab +* d -- closes a tab -Currently supported commands: +## Currently supported commands: * :q, :q!, :tabnew * :tabn, :tabp, :tabfir, :tabfirst, :tablast @@ -21,14 +22,15 @@ Currently supported commands: In the preferences for the extension, it is possible to give a list of sites, where the extension should not be loaded. Separate sites by , (comma). Spaces are allowed. -Known issues ------------- +## Known issues + * Some pages takes over the keyboard just as this extension does. That means that on some pages the overlay wont show up and wont recieve key strokes. * Some pages makes the gt and gT combos jump past it. -Contributors -============ +# AUTHORS + +- Mutwin Kraus +- Jason Green +- Jannik Nielsen +- Khaled Hussein -Mutwin Kraus -Jason Green -Jannik Nielsen diff --git a/Settings.plist b/Settings.plist index 2ab72d0..83d57c5 100644 --- a/Settings.plist +++ b/Settings.plist @@ -2,13 +2,13 @@ - - Key - disabledsites - Title - Disabled sites - Type - TextField - + + Key + disabledsites + Title + Disabled sites + Type + TextField + diff --git a/globalpage.html b/globalpage.html index d9e5198..2b148e2 100644 --- a/globalpage.html +++ b/globalpage.html @@ -12,137 +12,137 @@ setInterval("update()", 100); function update() { - if (!updating && tabActive[safari.application.browserWindows.indexOf(safari.application.activeBrowserWindow)] != undefined && tabActive[safari.application.browserWindows.indexOf(safari.application.activeBrowserWindow)][0] != undefined && parseInt(tabActive[safari.application.browserWindows.indexOf(safari.application.activeBrowserWindow)][0]) != parseInt(safari.application.activeBrowserWindow.tabs.indexOf( safari.application.activeBrowserWindow.activeTab ))) { - updateing = true; - changeTabActive(); - safari.application.activeBrowserWindow.activeTab.page.dispatchMessage("reset",true); - updating = false; - } + if (!updating && tabActive[safari.application.browserWindows.indexOf(safari.application.activeBrowserWindow)] != undefined && tabActive[safari.application.browserWindows.indexOf(safari.application.activeBrowserWindow)][0] != undefined && parseInt(tabActive[safari.application.browserWindows.indexOf(safari.application.activeBrowserWindow)][0]) != parseInt(safari.application.activeBrowserWindow.tabs.indexOf( safari.application.activeBrowserWindow.activeTab ))) { + updateing = true; + changeTabActive(); + safari.application.activeBrowserWindow.activeTab.page.dispatchMessage("reset",true); + updating = false; + } } */ String.prototype.trim = function () { - return this.replace(/^\s*/, "").replace(/\s*$/, ""); + return this.replace(/^\s*/, "").replace(/\s*$/, ""); } function disabledSitesHandler() { - if (disabledSites != undefined) { - disabledSitesArray = disabledSites.split(","); - - for (var i=0; i < disabledSitesArray.length; i++) { - var ds = disabledSitesArray[i].trim(); - currentSite = safari.application.activeBrowserWindow.activeTab.url; - dsm = ds.match(/([^\/.]+\.[^\/.]+(?=$|\/))/); - csm = currentSite.match(/([^\/.]+\.[^\/.]+(?=$|\/))/); - if (dsm != null && csm != null && dsm[0] == csm[0]) { - safari.application.activeBrowserWindow.activeTab.page.dispatchMessage("disable",true); - return; - } - } - safari.application.activeBrowserWindow.activeTab.page.dispatchMessage("load",true); - } else { - safari.application.activeBrowserWindow.activeTab.page.dispatchMessage("load",true); - } + if (disabledSites != undefined) { + disabledSitesArray = disabledSites.split(","); + + for (var i=0; i < disabledSitesArray.length; i++) { + var ds = disabledSitesArray[i].trim(); + currentSite = safari.application.activeBrowserWindow.activeTab.url; + dsm = ds.match(/([^\/.]+\.[^\/.]+(?=$|\/))/); + csm = currentSite.match(/([^\/.]+\.[^\/.]+(?=$|\/))/); + if (dsm != null && csm != null && dsm[0] == csm[0]) { + safari.application.activeBrowserWindow.activeTab.page.dispatchMessage("disable",true); + return; + } + } + safari.application.activeBrowserWindow.activeTab.page.dispatchMessage("load",true); + } else { + safari.application.activeBrowserWindow.activeTab.page.dispatchMessage("load",true); + } } function disabledSitesChanged(event) { - if (event.key == "disabledsites") { - disabledSites=event.newValue; - disabledSitesHandler(); - } + if (event.key == "disabledsites") { + disabledSites=event.newValue; + disabledSitesHandler(); + } } safari.extension.settings.addEventListener("change", disabledSitesChanged, false); function closeTab() { - safari.application.activeBrowserWindow.activeTab.close(); + safari.application.activeBrowserWindow.activeTab.close(); } function closeWindow() { - safari.application.activeBrowserWindow.close(); + safari.application.activeBrowserWindow.close(); } function openTab(event) { - var url = event.message; - var index = safari.application.activeBrowserWindow.tabs.indexOf( safari.application.activeBrowserWindow.activeTab ); - if (url != "") { - safari.application.activeBrowserWindow.openTab('foreground', ++index).url = url; - } else { - safari.application.activeBrowserWindow.openTab('foreground', ++index); - } - safari.application.activeBrowserWindow.activeTab.page.dispatchMessage("resetcombo", true); + var url = event.message; + var index = safari.application.activeBrowserWindow.tabs.indexOf( safari.application.activeBrowserWindow.activeTab ); + if (url != "") { + safari.application.activeBrowserWindow.openTab('foreground', ++index).url = url; + } else { + safari.application.activeBrowserWindow.openTab('foreground', ++index); + } + safari.application.activeBrowserWindow.activeTab.page.dispatchMessage("resetcombo", true); } /* function changeTabActive() { console.log(safari.application.browserWindows.indexOf( safari.application.activeBrowserWindow )); - if (tabActive[safari.application.browserWindows.indexOf( safari.application.activeBrowserWindow )] != undefined && tabActive[safari.application.browserWindows.indexOf( safari.application.activeBrowserWindow )][1] != undefined) { - tabActive[safari.application.browserWindows.indexOf( safari.application.activeBrowserWindow )][0] = tabActive[safari.application.browserWindows.indexOf( safari.application.activeBrowserWindow )][1]; - } - tabActive[safari.application.browserWindows.indexOf( safari.application.activeBrowserWindow )][1] = safari.application.activeBrowserWindow.tabs.indexOf( safari.application.activeBrowserWindow.activeTab ); + if (tabActive[safari.application.browserWindows.indexOf( safari.application.activeBrowserWindow )] != undefined && tabActive[safari.application.browserWindows.indexOf( safari.application.activeBrowserWindow )][1] != undefined) { + tabActive[safari.application.browserWindows.indexOf( safari.application.activeBrowserWindow )][0] = tabActive[safari.application.browserWindows.indexOf( safari.application.activeBrowserWindow )][1]; + } + tabActive[safari.application.browserWindows.indexOf( safari.application.activeBrowserWindow )][1] = safari.application.activeBrowserWindow.tabs.indexOf( safari.application.activeBrowserWindow.activeTab ); } */ function respondToMessage(theMessageEvent) { - switch (theMessageEvent.name) { - case "closeTab": - closeTab(); - break; - - case "closeWindow": - closeWindow(); - break; - - case "openTab": - case "newTab": - openTab(theMessageEvent); - // changeTabActive(); - safari.application.activeBrowserWindow.activeTab.page.dispatchMessage("resetcombo", true); - break; - - case "prevTab": - var index = safari.application.activeBrowserWindow.tabs.indexOf( safari.application.activeBrowserWindow.activeTab ); - if (index == 0) { - index = safari.application.activeBrowserWindow.tabs.length-1; - } else { - index--; - } - safari.application.activeBrowserWindow.tabs[index].activate(); - // changeTabActive(); - safari.application.activeBrowserWindow.activeTab.page.dispatchMessage("resetcombo", true); - break; - - case "nextTab": - var index = safari.application.activeBrowserWindow.tabs.indexOf( safari.application.activeBrowserWindow.activeTab ); - if (parseInt(theMessageEvent.message, 10) != 0) { - if (theMessageEvent.message == "last") { - index = parseInt(safari.application.activeBrowserWindow.tabs.length, 10)-1; - } else if (parseInt(theMessageEvent.message) < safari.application.activeBrowserWindow.tabs.length, 10) { - index = parseInt(theMessageEvent.message, 10)-1; - } - } else { - if (index == parseInt(safari.application.activeBrowserWindow.tabs.length, 10)-1) { - index = 0; - } else { - index++; - } - } - safari.application.activeBrowserWindow.tabs[index].activate(); - // changeTabActive(); - safari.application.activeBrowserWindow.activeTab.page.dispatchMessage("resetcombo", true); - break; - - case "backTab": - if (tabActive[0] != undefined && safari.application.activeBrowserWindow.tabs[tabActive[0]]) { - safari.application.activeBrowserWindow.tabs[tabActive[0]].activate(); - changeTabActive(); - } - break; - - case "disabledSites": - disabledSitesHandler(); - break; - } + switch (theMessageEvent.name) { + case "closeTab": + closeTab(); + break; + + case "closeWindow": + closeWindow(); + break; + + case "openTab": + case "newTab": + openTab(theMessageEvent); + // changeTabActive(); + safari.application.activeBrowserWindow.activeTab.page.dispatchMessage("resetcombo", true); + break; + + case "prevTab": + var index = safari.application.activeBrowserWindow.tabs.indexOf( safari.application.activeBrowserWindow.activeTab ); + if (index == 0) { + index = safari.application.activeBrowserWindow.tabs.length-1; + } else { + index--; + } + safari.application.activeBrowserWindow.tabs[index].activate(); + // changeTabActive(); + safari.application.activeBrowserWindow.activeTab.page.dispatchMessage("resetcombo", true); + break; + + case "nextTab": + var index = safari.application.activeBrowserWindow.tabs.indexOf( safari.application.activeBrowserWindow.activeTab ); + if (parseInt(theMessageEvent.message, 10) != 0) { + if (theMessageEvent.message == "last") { + index = parseInt(safari.application.activeBrowserWindow.tabs.length, 10)-1; + } else if (parseInt(theMessageEvent.message) < safari.application.activeBrowserWindow.tabs.length, 10) { + index = parseInt(theMessageEvent.message, 10)-1; + } + } else { + if (index == parseInt(safari.application.activeBrowserWindow.tabs.length, 10)-1) { + index = 0; + } else { + index++; + } + } + safari.application.activeBrowserWindow.tabs[index].activate(); + // changeTabActive(); + safari.application.activeBrowserWindow.activeTab.page.dispatchMessage("resetcombo", true); + break; + + case "backTab": + if (tabActive[0] != undefined && safari.application.activeBrowserWindow.tabs[tabActive[0]]) { + safari.application.activeBrowserWindow.tabs[tabActive[0]].activate(); + changeTabActive(); + } + break; + + case "disabledSites": + disabledSitesHandler(); + break; + } } safari.application.addEventListener("message",respondToMessage,false); diff --git a/vim-keybindings.js b/vim-keybindings.js index c366688..178ca8f 100644 --- a/vim-keybindings.js +++ b/vim-keybindings.js @@ -148,13 +148,13 @@ t.keyCommand = function(c, e) { t.scroll(SCROLL_STEP, 0); } break; - case 'd': - if (t.functionkeys({'ctrl': '1'})) { - t.scroll(0, t.halfWindowHeight()); - } else { - reset_combo = false; - } - break; + //case 'd': + // if (t.functionkeys({'ctrl': '1'})) { + // t.scroll(0, t.halfWindowHeight()); + // } else { + // reset_combo = false; + // } + //break; case 'dd': if (t.functionkeys({'none': '1'}) && t.lastActiveElement != undefined) { t.lastActiveElement.value = ''; @@ -186,6 +186,12 @@ t.keyCommand = function(c, e) { e.preventDefault(); } break; + case 'd': + safari.self.tab.dispatchMessage("closeTab"); + break; + case 't': + safari.self.tab.dispatchMessage("openTab", "https://"); + break; case 'gT': if (t.functionkeys({'shift': '1'})) { safari.self.tab.dispatchMessage("prevTab",""); @@ -227,6 +233,7 @@ t.inputCommand = function(command) { case 'tabe': case 'tabedit': case 'e': + case 't': case 'edit': if (param[1] == "" || param[1] == undefined) { if (param[0] == 'e' || param[0] == 'edit') {