Copy Markdown-Format Address

Copy current tab title and url, and convert to markdown syntax

Verze ze dne 12. 02. 2018. Zobrazit nejnovější verzi.

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

You will need to install an extension such as Tampermonkey to install this script.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

You will need to install an extension such as Tampermonkey to install this script.

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

// ==UserScript==
// @name         Copy Markdown-Format Address
// @namespace    undefined
// @version      0.1
// @description  Copy current tab title and url, and convert to markdown syntax
// @author       https://github.com/Dream4ever
// @match        *://*/*
// @grant        none
// ==/UserScript==

// Thanks to https://stackoverflow.com/questions/400212/
// solved the problem of unable select text
// of none-displayed textarea

(function () {
  'use strict';

  window.onload = function () {
    var rdnId = Math.random().toString(36).substring(5);
    var nodeButton = document.createElement('button');
    nodeButton.setAttribute('id', rdnId);
    nodeButton.innerHTML = 'Copy';
    nodeButton.style.fontSize = '14px';
    nodeButton.style.color = '#000';
    nodeButton.style.width = '80px';
    nodeButton.style.padding = '5px 10px';
    nodeButton.style.borderRadius = '5px';
    nodeButton.style.background = 'rgb(240, 240, 240)';
    nodeButton.style.boxShadow = '3px 3px 3px rgba(0, 0, 0, .1)';
    nodeButton.style.position = 'fixed';
    nodeButton.style.bottom = '20px';
    nodeButton.style.right = '70px';
    nodeButton.style.zIndex = 2;
    document.body.appendChild(nodeButton);

    nodeButton.addEventListener('click', function (event) {

      // get title and url
      var title = document.title;
      var url = document.URL;
      var address = '[' + title + '](' + url + ')';

      if (copyTextToClipboard(address)) {
          nodeButton.innerHTML = 'Done';
          setTimeout(function() { nodeButton.innerHTML = 'Copy'; }, 2000);
      } else {
          nodeButton.innerHTML = 'Failed';
          setTimeout(function() { nodeButton.innerHTML = 'Copy'; }, 2000);
      }
    });
  };

})();

function copyTextToClipboard(text) {
  var textArea = document.createElement("textarea");

  textArea.style.position = 'fixed';
  textArea.style.top = 0;
  textArea.style.left = 0;

  textArea.style.width = '2em';
  textArea.style.height = '2em';

  textArea.style.padding = 0;

  textArea.style.border = 'none';
  textArea.style.outline = 'none';
  textArea.style.boxShadow = 'none';

  textArea.style.background = 'transparent';

  textArea.value = text;

  document.body.appendChild(textArea);

  textArea.select();

  var isOK = false;

  try {
    var successful = document.execCommand('copy');
    isOK = !!successful;
  } catch (err) {}

  document.body.removeChild(textArea);

  return isOK;
}