3 ms·
Show HN: ⌘goo.gl - Shorten current URL and copy to clipboard in 1-click
- projectant 9y agoGithub gist version of jsbin page here: https://gist.github.com/dosyago-coder-0/b7bcf95f60b6979de2a07764109020e8 https://gist.github.com/dosyago-coder-0/b7bcf95f60b6979de2a0...
- Vvg 9y agoIs book marklet
- projectant 9y agoI think it could be improved by adding some styles to the inserted textarea, such as opacity, or position absolute, or even a pointer events to make sure it is invisible and doesn't interact. Display: none does not work as then select and copy will not work.
- projectant 9y agoThis is a bookmarklet to anyone who doesn't know. Code is here also for convenience: javascript:(function()%7B(function()%20%7Bconst%20req%20%3D%20new%20XMLHttpRequest()%3Bconst%20key%20%3D%20'AIzaSyAUYMRSUW3BAZLhSTbB1poQuQ4xaqt2C4c'%3Breq.open('POST'%2C%20'https%3A%2F%2Fwww.googleapis.com%2Furlshortener%2Fv1%2Furl%3Fkey%3D'%2Bkey)%3Breq.setRequestHeader(%22Content-Type%22%2C%20%22application%2Fjson%22)%3Breq.responseType%3D%22json%22%3Breq.send(JSON.stringify(%7BlongUrl%3Alocation.href%7D))%3Bconst%20text%20%3D%20document.createElement('textarea')%3Blet%20result%3BsetTimeout(%20()%20%3D%3E%20(document.execCommand('copy')%2Ctext.remove())%2C%20700%20)%3Breq.onreadystatechange%20%3D%20()%20%3D%3E%20%7Bif%20(%20req.status%20%3D%3D%20200%20%26%26%20req.readyState%20%3D%3D%204%20)%20%7Bdocument.body.appendChild(text)%3Btext.value%20%3D%20req.response.id%3Btext.select()%3B%7D%7D%7D())%7D)()