Last active
August 31, 2017 06:39
-
-
Save jackysee/6067506 to your computer and use it in GitHub Desktop.
Twitter pinboard shortcut
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
// ==UserScript== | |
// @id Twitter pinbaord unread | |
// @name Twitter pinboard unread | |
// @namespace http://jacky.seezone.net/twitterpinboardunread | |
// @description press p to save link in current tweets to pinobard unread | |
// @include https://twitter.com/* | |
// @include http://twitter.com/* | |
// ==/UserScript== | |
function getTitle(link){ | |
var contents = link.parentNode.childNodes; | |
return Array.prototype.slice.call(contents, 0).map(function(node){ | |
return node.nodeType === 3? node.textContent : ''; | |
}).join(""); | |
} | |
function isInput(ev){ | |
console.log('isInput', ev); | |
if(ev.altKey || ev.ctrlKey || ev.shiftKey || | |
/input|textarea/.test(ev.target.tagName.toLowerCase()) || | |
ev.target.contentEditable === 'true'){ | |
return true; | |
} | |
return false; | |
} | |
function getKey(ev){ | |
return String.fromCharCode(ev.keyCode ||ev.which); | |
} | |
function linkKey(ev){ | |
if(isInput(ev)){ return; } | |
var k = getKey(ev); | |
if(k == "p"){ | |
var links = document.querySelectorAll(".selected-stream-item a.twitter-timeline-link"); | |
if(links && links.length>0){ | |
var url = links[0].href; //asume first link | |
var title = getTitle(links[0]); | |
var win = window.open('https://pinboard.in/add?later=yes&noui=yes&jump=close&url='+encodeURIComponent(url)+'&title='+encodeURIComponent(title),'Pinboard','toolbar=no,width=100,height=100'); | |
win.blur(); | |
} | |
} | |
} | |
document.addEventListener('keypress', linkKey, true); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment