Created
July 8, 2010 12:27
-
-
Save littlefolk/467946 to your computer and use it in GitHub Desktop.
vimperator plugin: browser_object_api.js + tabBlocks
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
liberator.plugins.Block = function () { | |
let mTabs = Array.filter(config.tabbrowser.mTabs, function (aNode) aNode.localName == "tab"); | |
let mCurrentIndex = tabs.index(); | |
let identify = function (i) {try{return i.linkedBrowser.contentDocument.location.host}catch(e){}}; | |
let tabBlocks = [], activeBlockIndex, cache; | |
mTabs.forEach(function (aTab) { | |
let id = identify(aTab); | |
if (cache != id && !TreeStyleTabService.getParentTab(aTab)) { | |
tabBlocks.push([]); | |
cache = id; | |
}; | |
let (index = tabBlocks.length - 1) { | |
tabBlocks[index].push(aTab); | |
if (!activeBlockIndex && aTab._tPos == mCurrentIndex) | |
activeBlockIndex = index; | |
}; | |
}); | |
let method = { | |
get activeBlockIndex () | |
activeBlockIndex, | |
activeBlock: function () | |
this.__proto__[this.activeBlockIndex], | |
activeBlockTop: function () | |
this.activeBlock()[0], | |
activeBlockEnd: function () | |
this.activeBlock().reverse()[0], | |
previousBlock: function (i) | |
this.__proto__[this.activeBlockIndex - (i || 1)], | |
previousBlockTop: function (i) | |
this.previousBlock(i)[0], | |
previousBlockEnd: function (i) | |
this.previousBlock(i).reverse()[0], | |
nextBlock: function (i) | |
this.__proto__[this.activeBlockIndex + (i || 1)], | |
nextBlockTop: function (i) | |
this.nextBlock(i)[0], | |
nextBlockEnd: function (i) | |
this.nextBlock(i).reverse()[0], | |
}; | |
return libly.$U.extend(util.Array(tabBlocks), method); | |
}; | |
mappings.addUserMap( | |
[modes.NORMAL], ["gb^"], "Switch to the this Block first tab.", | |
function () | |
let (target = plugins.Block().activeBlockTop()) | |
target && tabs.select(target._tPos), | |
{count: true}) | |
mappings.addUserMap( | |
[modes.NORMAL], ["gb$"], "Switch to the this Block last tab.", | |
function () | |
let (target = plugins.Block().activeBlockEnd()) | |
target && tabs.select(target._tPos), | |
{count: true}) | |
mappings.addUserMap( | |
[modes.NORMAL], ["gbp"], "Switch to the Previous Block first tab.", | |
function (count) | |
let (target = plugins.Block().previousBlockEnd(count)) | |
target && tabs.select(target._tPos), | |
{count: true}) | |
mappings.addUserMap( | |
[modes.NORMAL], ["gbn"], "Switch to the Next Block first tab.", | |
function (count) | |
let (target = plugins.Block().nextBlockTop(count)) | |
target && tabs.select(target._tPos), | |
{count: true}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment