5 ms·
It is all one line. Yes, Twitter formats it in a way that makes it impossible to copy just the text. Because it thinks that .style is a toplevel domain and #ccc
by mg 4y ago
It is all one line. Yes, Twitter formats it in a way that makes it impossible to copy just the text. Because it thinks that .style is a toplevel domain and #ccc is a hashtag.
Here is a repo from which it is easy to copy:
https://github.com/no-gravity/hn-bookmarklet https://github.com/no-gravity/hn-bookmarklet
- javajosh 4y agoDid you write this? If so, why did you add the "{}" at the end? Also, can't you use newlines in bookmarklets?
- mg 4y agoYes, I wrote it. The {} prevents the code from evaluating to a value that the browser then would use as the new value for the DOM, overwriting the existing page. Try bookmarking javascript:123 and see what happens when you click it. Bookmarklets are URLs, so a newline in the code would be urlencoded as %0A. So you could do: javascript:alert(1)%0Aalert(2) But I would prefer: javascript:alert(1);alert(2)
- lioeters 4y agoAh that's nice, thank you. Sorry I mis-rewrote when I tried to correct what was copied from Twitter. It addeded some extraneous "https:// https://" too. javascript:if (!location.href.match('ycom')) {location.href='https://news.ycombinator.com'};if (typeof e!=='undefined') e.style.background='#c0c0c0';e=Array.from(document.querySelectorAll('.age%20a:not(.seen)')).sort().at(-1);e.style.background='#ff0';e.classList.add('seen');e.scrollIntoView({behavior:"smooth",block:"center",inline:"nearest"});{} I see, that {} at the end is intentional, as you described in another comment. And accessing the variable e before assigning it a value, now I see that probably serves a practical purpose too.