Created
April 25, 2011 13:11
-
-
Save adityavm/940484 to your computer and use it in GitHub Desktop.
bookmarklet to show the referrer for the current page
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
javascript:var str='';function avm_getL(h){var a=document.createElement('a');a.href=h;return a.hostname}function gup(){var results=document.referrer.toString().match(/q=([A-Z\%0-9]+)/i);if(!results)return'';else return results[1]}function avm_cb(d){var div=document.createElement('div');div.id='avm_ref_div';if(document.referrer==''){div.innerHTML='You came here independently, i.e. by typing in the URL or from an external application'}else{div.innerHTML='You came here from ';var a=document.createElement('a');a.href=(str==='Google')?'http://google.com/search?q='+gup():document.referrer;if(!d.query.results){a.innerHTML=(str)?str:'Unknown'}else{a.innerHTML=d.query.results.title}a.setAttribute('style','color:#ddd; text-decoration:underline;');div.appendChild(a)}div.innerHTML+='.';div.setAttribute('style','position:fixed; top:0; left:0; opacity:0.8; background-color:#222; color:#eee; font: 9pt \'Helvetica Neue\',Arial,sans-serif; padding:2px 4px;');document.body.appendChild(div)}if(avm_getL(document.referrer)==='www.google.com'){str='Google';avm_cb({'query':{'results':{'title':'Google'}}})}else{var yql='select * from html where url=\''+document.referrer+'\' and xpath=\'//title\'';var s=document.createElement('script');s.type='text/javascript';s.src='http://query.yahooapis.com/v1/public/yql?q='+encodeURIComponent(yql)+'&format=json&callback=avm_cb';document.head.appendChild(s)};void 0; |
I don't: http://d.pr/tHS
What's the error you're getting?
so, the console just hated it because I had already run it. The js command in uzbl, though, seems to hate """, so I changed all the escaped double quotes inside double quotes into unescape double quotes inside single quotes. Ie:
var str="";function avm_getL(h){var a=document.createElement('a');a.href=h;return a.hostname}function gup(){var results=document.referrer.toString().match(/q=([A-Z\%0-9]+)/i);if(!results)return"";else return results[1]}function avm_cb(d){var div=document.createElement('div');div.id="avm_ref_div";if(document.referrer==""){div.innerHTML="You came here independently, i.e. by typing in the URL or from an external application"}else{div.innerHTML="You came here from ";var a=document.createElement('a');a.href=(str==="Google")?"http://google.com/search?q="+gup():document.referrer;if(!d.query.results){a.innerHTML=(str)?str:"Unknown"}else{a.innerHTML=d.query.results.title}a.setAttribute('style','color:#ddd; text-decoration:underline;');div.appendChild(a)}div.innerHTML+=".";div.setAttribute('style','position:fixed; top:0; left:0; opacity:0.8; background-color:#222; color:#eee; font: 9pt "Helvetica Neue",Arial,sans-serif; padding:2px 4px;');document.body.appendChild(div)}if(avm_getL(document.referrer)==='www.google.com'){str="Google";avm_cb({"query":{"results":{"title":"Google"}}})}else{var yql='select * from html where url="'+document.referrer+'" and xpath="//title"';var s=document.createElement('script');s.type="text/javascript";s.src="http://query.yahooapis.com/v1/public/yql?q="+encodeURIComponent(yql)+"&format=json&callback=avm_cb";document.head.appendChild(s)}
My code works in Firefox (4) and Chrome (11), but I replaced my code with your changes anyway. Doesn't really matter as far as as the code is concerned, but if it works in one more thing, why not.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I get a syntax error running this is the webkit console.