-
-
Save dlenski/e598197774666d440503d5168eefed31 to your computer and use it in GitHub Desktop.
| javascript:void(function() { | |
| loc = window.location; | |
| page_title = window.document.title; /* create page */ | |
| w = window.open("", "_blank", "height=150,width=900"); | |
| d = w.document; | |
| d.open(); | |
| d.write(`<html><head><title>Create formatted link</title></head> | |
| <body> | |
| <form onsubmit="return false"> | |
| <table> | |
| <tr><th>URL: </th> <td><input id="url" type="text" size="100"></td></tr> | |
| <tr><th>Link title:</th><td><input id="title" type="text" size="100"></td></tr> | |
| <tr><td/> <td><input id="copy" type="submit" value="Copy & Close"/></td></tr> | |
| </table> | |
| </form> | |
| </body></html>`); | |
| /* initialize */ | |
| l = d.getElementById("url"); | |
| t = d.getElementById("title"); | |
| c = d.getElementById("copy"); | |
| l.value = window.location.toString(); | |
| t.value = page_title; | |
| /* https://jsfiddle.net/jdhenckel/km7prgv4/3/ */ | |
| function copyToClip(doc, html, text = null) { | |
| function listener(e) { | |
| e.clipboardData.setData("text/html", html); | |
| e.clipboardData.setData("text/plain", text || html); | |
| e.preventDefault(); | |
| } | |
| doc.addEventListener("copy", listener); | |
| doc.execCommand("copy"); | |
| doc.removeEventListener("copy", listener); | |
| }; | |
| c.onclick = function() { | |
| e = d.createElement("a"); | |
| e.href = l.value; | |
| e.innerHTML = t.value; | |
| copyToClip(d, e.outerHTML, l.value); | |
| w.close(); | |
| }; | |
| /* activate torpedos */ | |
| d.close(); | |
| c.focus(); | |
| }) () |
@Vaisakhkm2625, no. I am making the popup window so that the URL and title can be customized.
Hi @dlenski - Loving the bookmarklet, but would love to remove the popup window as I have no need to customize the link. I tried editing the code, but can't figure it out. Are you able to help?
https://gist.github.com/RyanAtSnapLogic/969457e51092cc040dfb4f5f79a4aa3a
would love to remove the popup window as I have no need to customize the link. I tried editing the code, but can't figure it out.
@RyanAtSnapLogic, what have you tried so far? What is or isn't working, specifically?
https://gist.github.com/RyanAtSnapLogic/969457e51092cc040dfb4f5f79a4aa3a
There are no differences between the current contents of that Gist and this one. 🤷♂️
Thanks for this very useful bookmarklet! However recently Brave has been crashing every time I use it. I found changing those nulls on line 4 to empty strings ("") stop the crashing and make it work for me again. Granted Brave shouldn't crash on something like this, but I got the idea to try empty strings from the MDN docs on window.open.
I found changing those nulls on line 4 to empty strings ("") stop the crashing and make it work for me again.
Interesting, thanks @skehlet. It crashes the tab??
Per those docs, should the second parameter (target) be set to "_blank" rather than ""?
I've updated it accordingly. Does that work for you?
Interesting, thanks @skehlet. It crashes the tab??
It does! The whole application actually. Only in the last version or two however.
Per those docs, should the second parameter (
target) be set to"_blank"rather than""?I've updated it accordingly. Does that work for you?
Yes, "_blank" is working great! Tested your updated version above exactly and it's working great on Brave
Version 1.69.162 Chromium: 128.0.6613.120 (Official Build) (arm64).
Edit: and verified without this change, it still crashes, even on today's update! ☠️
Thanks again!
Interesting, thanks @skehlet. It crashes the tab??
It does! The whole application actually. Only in the last version or two however.
Welp, good to know that there's an easy remotely-exploitable snippet of JavaScript that will crash https://github.com/brave/brave-browser 😝
(^attn @brave, if it hasn't been reported already)
wow trick is nice, you are making a popup window because doc.execCommand("copy") cannot run from bookmarklet right