Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save lorashfuko/0caa61d808e6e5c58e10a56cb9e31181 to your computer and use it in GitHub Desktop.
Save lorashfuko/0caa61d808e6e5c58e10a56cb9e31181 to your computer and use it in GitHub Desktop.
Букмарклет копирует description документа в буфер обмена
javascript:(function () {
var body = document.querySelector("body");
var range = document.createRange();
var text = document.createElement("P");
var description = document.querySelector('meta[name="description"]');
if (description) {
text.innerHTML = description.content;
body.appendChild(text);
range.selectNode(text);
window.getSelection().addRange(range);
} else {
var html = document.querySelector("html");
description = document.createElement("META");
description.setAttribute('name', 'description');
description.setAttribute('content', 'Пусто');
html.appendChild(description);
text.innerHTML = description.content;
body.appendChild(text);
range.selectNode(text);
window.getSelection().addRange(range);
}
try {
var successful = document.execCommand('copy');
var div = document.createElement("DIV");
div.style.cssText = "width: 500px; padding: 20px; position: fixed; top: 20px; left: 50%; background: rgba(51,67,70,.9); z-index: 9999999; border-radius:5px; margin-left: -250px; color: #fff;";
div.innerHTML = "В буфер обмена скопирован description:<br><br>" + description.content;
body.appendChild(div);
setTimeout(function () {
div.parentNode.removeChild(div);
text.parentNode.removeChild(text);
}, 4000);
var msg = successful ? 'successful' : 'unsuccessful';
console.log('Copy description command was ' + msg);
} catch (err) {
console.log('Oops, unable to copy');
}
window.getSelection().removeAllRanges();
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment