QR from highlight

Create a QR code from anything highlighted

Verze ze dne 18. 10. 2023. 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         QR from highlight
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  Create a QR code from anything highlighted
// @match        http://*/*
// @match        https://*/*
// @grant        none
// @require      https://cdnjs.cloudflare.com/ajax/libs/qrcode-generator/1.4.4/qrcode.js
// ==/UserScript==

(function () {
  'use strict';

  // Function to get the currently selected text
  function getSelectionText() {
    var selectedText = '';
    if (window.getSelection) {
      // All modern browsers and IE9+
      selectedText = window.getSelection().toString();
    }
    return selectedText;
  }

  // Function to generate and display QR code
  function generateQRCode(text) {
    let qrElement = document.getElementById('generated-qr-code');
    if (!qrElement) {
      qrElement = document.createElement('div');
      qrElement.id = 'generated-qr-code';
      document.body.appendChild(qrElement);
    }

    qrElement.innerHTML = ''; // Clear any previous QR codes

    let typeNumber = 0; // Auto detect QR code type based on input data
    let errorCorrectionLevel = 'L'; // Low error correction level
    let qr = qrcode(typeNumber, errorCorrectionLevel);
    qr.addData(text);
    qr.make();

    // Add QR code to the container
    qrElement.innerHTML = qr.createImgTag(5);

    // Style the container
    qrElement.style.width = '200px';
    qrElement.style.height = '200px';
    qrElement.style.position = 'fixed';
    qrElement.style.bottom = '10px';
    qrElement.style.right = '10px';
    qrElement.style.zIndex = '1000';
  }

  // Listen for text selection
  document.addEventListener('mouseup', function () {
    let selectedText = getSelectionText();
    if (selectedText) {
      generateQRCode(selectedText);
    }
  });
})();