Created
January 12, 2011 11:08
-
-
Save edvakf/776022 to your computer and use it in GitHub Desktop.
This file contains hidden or 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() { | |
| var SHOW_URL_IN_BRACES = false; | |
| var re = /^https?:\/\/twitter\.com\/(?:#!\/)?(\w+)\/status(?:es)?\/(\d+)/; | |
| function addPageTitleButtonOnTweet(elem) { | |
| var links = elem.getElementsByTagName('a'); | |
| for (var i = 0, l = links.length; i < l; i++) { | |
| if (/\slink\s/.test(' ' + links[i].className + ' ')) { | |
| // avoid tweet url (there is already tweet_url_reply.js) | |
| if (!re.test(links[i].href)) addPageTitleButton(links[i]); | |
| } | |
| } | |
| } | |
| function addPageTitleButton(elem) { | |
| var b = document.createElement('a'); | |
| var id = b.id = 'PageTitle_' + (Math.random() * 100000 | 0); | |
| b.href = '#'; | |
| var img = new Image(); | |
| img.src = '/images/inrep.png'; | |
| b.appendChild(img); | |
| b.onclick = function() { | |
| window['show' + id] = function(res) { | |
| if (res.query.results) { | |
| var a = b.previousSibling; | |
| var title = res.query.results.title.replace(/\s+/g,' '); | |
| if (title.length > 200) title = title.slice(0, 200) + '…'; | |
| var url = a.href; | |
| if (url.length > 200) url = url.slice(0, 200) + '…'; | |
| a.innerHTML = ''; | |
| a.appendChild(document.createTextNode(title + (SHOW_URL_IN_BRACES ? ' (' + url + ')' : ''))); | |
| } | |
| window['show' + id] = null; | |
| b.parentNode.removeChild(b); | |
| }; | |
| loadXDomainScript( | |
| 'http://query.yahooapis.com/v1/public/yql?q=' + | |
| encodeURIComponent('select * from html where url="' + | |
| elem.href + | |
| '" and xpath="//title"') + | |
| '&format=json&diagnostics=false&callback=' + | |
| 'show' + id); | |
| return false; | |
| }; | |
| elem.parentNode.insertBefore(b, elem.nextSibling); | |
| } | |
| registerPlugin({ | |
| newMessageElement : addPageTitleButtonOnTweet, | |
| }); | |
| }()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment