CopyFixerfix

Copy Title and URL by Ctrl-C

이 스크립트를 설치하려면 Tampermonkey, Greasemonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey와 같은 확장 프로그램을 설치해야 합니다.

이 스크립트를 설치하려면 Tampermonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey 또는 Userscripts와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 유저 스크립트 관리자 확장 프로그램이 필요합니다.

(이미 유저 스크립트 관리자가 설치되어 있습니다. 설치를 진행합니다!)

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

(이미 유저 스타일 관리자가 설치되어 있습니다. 설치를 진행합니다!)

// ==UserScript==
// @name         CopyFixerfix
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  Copy Title and URL by Ctrl-C
// @author       MSG
// @match        *://*/*
// @grant        none
// ==/UserScript==

(function() {
    window.addEventListener('keydown', copyfixer, true);

    function copyfixer(event) {
        if (event.keyCode != 67) return;
        var isWin = (navigator.platform.indexOf("Win") != -1);
        var isMac = (navigator.platform.indexOf("Mac") != -1);
        if ((! isMac && ! event.ctrlKey) || (isMac && ! event.metaKey)) return;
        if (isSelected()) return;
        var crlf = isWin ? "\r\n" : "\n";
        var txt = document.title + crlf + document.location.href + crlf + crlf;
        sendMessage(txt);
    }

    function isSelected() {
        var sel = window.getSelection();
        if (sel.rangeCount <= 0) return false;
        if (sel.rangeCount > 1) return true;

        var range = sel.getRangeAt(0);
        if (! range.collapsed) return true;
        if (range.startContainer != range.endContainer) return true;
        if (range.startOffset != range.endOffset) return true;
        if (document.activeElement.tagName.toLowerCase() != "body") return true;

        return false;
    }

    function sendMessage(data) {
        //if ( request.command != "copyfixerCopy" ) return;
        const textarea = document.createElement('textarea');
        textarea.style.position = 'fixed';
        textarea.style.opacity = 0;
        textarea.value = data;

        document.body.appendChild(textarea);

        textarea.select();
        document.execCommand('Copy');
    }

})();