// 복사 할 때 출처 추가하기
function run_copy()
{
var text = window.getSelection().toString();
var retUrl = document.URL;
text = text +'\n\n출처: [하나성경] '+retUrl;
copyToClipboard(text);
}
function copyToClipboard(text) {
var textarea = document.createElement("textarea");
var result = "";
textarea.textContent = text;
textarea.style.position = "fixed";
document.body.appendChild(textarea);
textarea.select();
try {
result = document.execCommand("cut");
} catch (ex) {
console.warn("Copy to clipboard failed.", ex);
return false;
} finally {
document.body.removeChild(textarea);
}
if (false == result) {
var textarea = document.createElement("textarea");
textarea.textContent = text;
textarea.style.position = "fixed";
document.body.appendChild(textarea);
textarea.select();
unsafeWindow.netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
const clipboardHelper = Components.classes["@mozilla.org/widget/clipboardhelper;1"].getService(Components.interfaces.nsIClipboardHelper);
clipboardHelper.copyString(text);
}
}
HTML :
<body oncopy="run_copy();">