- Copy the minified
bookmarklet
code. - Add a page/link to your bookmarks toolbar.
- Paste the code.
- Save.
- Profit.
- Click the bookmark.
- Paste the link.
- Profit.
- Highlight page text.
- Click the bookmark.
- Paste the link + text.
- Profit.
bookmarklet
code.javascript:var a=encodeURI(document.location.href),b=window.getSelection().toString(),c='<a href="'+a+'">'+document.title+"</a>",d=document.createElement("div");d.innerHTML=b?"<div>"+c+":<br />"+b+"</div>":c;document.body.appendChild(d);window.getSelection().removeAllRanges();var e=document.createRange();e.selectNode("string"===typeof d?document.getElementById(d):d);window.getSelection().addRange(e);document.execCommand("copy");window.getSelection().removeAllRanges();document.body.removeChild(d);var f={},g=void 0===f.frequency?1E3:f.frequency,h=void 0===f.start?0:f.start,k=void 0===f.stop?.05:f.stop,l=void 0===f.context?new AudioContext:f.context,m=l.createOscillator(),n=l.createGain();n.gain.setValueAtTime(0,h);n.gain.linearRampToValueAtTime(1,h+.0025);n.gain.linearRampToValueAtTime(0,k-.005);m.frequency.value=g;m.connect(n);n.connect(l.destination);m.start(h);m.stop(k); |
// ==ClosureCompiler== | |
// @compilation_level ADVANCED_OPTIMIZATIONS | |
// @output_file_name default.js | |
// ==/ClosureCompiler== | |
(function() { | |
function copyMarkupToClipboard(markup) { | |
let el = document.createElement('div'); | |
el.innerHTML = markup; | |
document.body.appendChild(el); | |
copyElementToClipboard(el); | |
document.body.removeChild(el); | |
} | |
function copyElementToClipboard(element) { | |
window.getSelection().removeAllRanges(); | |
let range = document.createRange(); | |
range.selectNode(typeof element === 'string' ? document.getElementById(element) : element); | |
window.getSelection().addRange(range); | |
document.execCommand('copy'); | |
window.getSelection().removeAllRanges(); | |
} | |
function makeLink() { | |
let href = encodeURI(document.location.href); | |
let title = document.title; | |
let body = window.getSelection().toString(); | |
let link = `<a href="${href}">${title}</a>`; | |
if (body) { | |
return `<div>${link}:<br />${body}</div>`; | |
} else { | |
return link; | |
} | |
} | |
function beep({frequency = 1000, start = 0, stop = 0.05, context = new AudioContext()} = {}) { | |
let o = context.createOscillator(); | |
let g = context.createGain(); | |
g.gain.setValueAtTime(0, start); | |
g.gain.linearRampToValueAtTime(1, start + 0.0025); | |
g.gain.linearRampToValueAtTime(0, stop - 0.005); | |
o.frequency.value = frequency; | |
o.connect(g); | |
g.connect(context.destination); | |
o.start(start); | |
o.stop(stop); | |
}; | |
copyMarkupToClipboard(makeLink()); | |
beep(); | |
})(); |
New version softens the feedback beep and fixes waveform cutting at the start and/or end of the beep.
The latest version adds a brief beep for feedback. If I have time later, I will replace the beep with a fading popup.