{"size": 837, "ext": "js", "max_stars_repo_path": "src/foreground.js", "max_stars_repo_name": "ryanspain/chromium-copy-text-as-link", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/foreground.js", "max_issues_repo_name": "ryanspain/chromium-copy-text-as-link", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/foreground.js", "max_forks_repo_name": "ryanspain/chromium-copy-text-as-link", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 32.1923076923, "max_line_length": 78, "alphanum_fraction": 0.651135006}
// handle message requests
chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {

    console.debug(`${message.command} message received`, message);

    switch (message.command) {
        case 'copy_text_as_plain_html_link':
            copySelectedTextAsPlainHtmlLink(message.selectedText, message.url)
            break;
        case 'copy_text_as_markdown_link':
            throw new Error(`${message.command} not implemented yet`);
        default:
            throw new Error("Unsupported message");
    }
});

function copySelectedTextAsPlainHtmlLink(selectedText, url) {

    var link = `<a href="${url}" target="_blank">${selectedText}</a>`;

    var type = "text/html";
    var blob = new Blob([link], { type });
    var data = [new ClipboardItem({ [type]: blob })];

    navigator.clipboard.write(data);
}