Last active
September 23, 2024 16:10
-
-
Save dlenski/e598197774666d440503d5168eefed31 to your computer and use it in GitHub Desktop.
Bookmarklet to copy current page title as a rich-text formatted link
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: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(); | |
}) () |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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)