Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save lorashfuko/b14c51aca351fb83c95307bdb52f5bc9 to your computer and use it in GitHub Desktop.
Save lorashfuko/b14c51aca351fb83c95307bdb52f5bc9 to your computer and use it in GitHub Desktop.
Букмарклет копирует содержимое мета-тега Title в буфер обмена
javascript:(function () {
var body = document.querySelector("body");
var range = document.createRange();
var text = document.createElement("P");
var title = document.querySelector("title");
if (title) {
text.innerHTML = title.textContent;
body.appendChild(text);
range.selectNode(text);
window.getSelection().addRange(range);
} else {
var html = document.querySelector("html");
title = document.createElement("TITLE");
title.innerHTML = "Пусто";
html.appendChild(title);
text.innerHTML = title;
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 = "В буфер обмена скопирован title:<br><br>" + title.textContent;
body.appendChild(div);
setTimeout(function () {
div.parentNode.removeChild(div);
text.parentNode.removeChild(text);
}, 5000);
var msg = successful ? 'successful' : 'unsuccessful';
console.log('Copy title 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