Last active
December 20, 2015 15:49
-
-
Save kaorimatz/6156668 to your computer and use it in GitHub Desktop.
User defined vimperator command for opening a link on the twitter timeline in the new tab
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
(function () { | |
function contains(clazz) { | |
return 'contains(concat(" ", normalize-space(@class), " "), " ' + clazz + ' ")'; | |
} | |
mappings.addUserMap( | |
[modes.NORMAL], | |
['v'], | |
'Open links contained in a selected tweat', | |
function openTwitterTimelineLink() { | |
let expr = '//li[' + contains('selected-stream-item') + ']' + | |
'//p[' + contains('tweet-text') + ']' + | |
'/a[' + contains('twitter-timeline-link') + ']'; | |
let links = util.evaluateXPath(expr, content.document); | |
if (links.snapshotLength > 0) { | |
let urls = []; | |
for (let i = 0; i < links.snapshotLength; i++) { | |
urls.push(links.snapshotItem(i)); | |
} | |
liberator.open(urls, liberator.NEW_TAB); | |
} | |
}, | |
{ | |
noremap: true, | |
matchingUrls: /^https:\/\/twitter\.com/, | |
} | |
); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment