Reep QRcode

generate QRcode for reep.io link

คุณจะต้องติดตั้งส่วนขยาย เช่น Tampermonkey, Greasemonkey หรือ Violentmonkey เพื่อติดตั้งสคริปต์นี้

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

คุณจะต้องติดตั้งส่วนขยาย เช่น Tampermonkey หรือ Violentmonkey เพื่อติดตั้งสคริปต์นี้

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

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

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

(I already have a user script manager, let me install it!)

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.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         Reep QRcode
// @name:zh-CN   Reep 二维码
// @namespace    reep
// @include 	 *://reep.io/*
// @version      1.0
// @description  generate QRcode for reep.io link
// @description:zh-CN  链接转二维码
// @author       BlindingDark
// @grant        none
// @license MIT License
// @require      https://cdn.bootcss.com/jquery/3.2.1/jquery.js
// @require      https://greatest.deepsurf.us/scripts/31884-qrcode-js/code/qrcodejs.js?version=208858
// @require      https://greatest.deepsurf.us/scripts/31885-jquery-qrcode-js/code/jqueryqrcodejs.js?version=208856
// ==/UserScript==
//
// 核心代码来自 编译小僵尸 https://greatest.deepsurf.us/users/85375
// https://greatest.deepsurf.us/zh-CN/scripts/27450-%E6%98%BE%E7%A4%BA%E4%BA%8C%E7%BB%B4%E7%A0%81/code

(function() {
    var html = '<div id="showQRcodeJsCanvas" style="position:fixed;top:50%;left:50%;margin-left:-135px;margin-top:-135px;background-color:white;height:auto;padding:7px;">';
    var colsefn = '';

    function getSelect() {
        if(window.getSelection) {
            return window.getSelection().toString();
        } else {
            return document.selection.createRange().text;
        }
    }

    function checkURLFormat(string) {
        var reg = new RegExp(/^[hH][tT][tT][pP]([sS]?):\/\/(\S+\.)+\S{2,}$/);
        if(!reg.test(string)) {
            return false;
        }
        return true;
    }

    $(document).mouseup(function(event) {
        let selectString = getSelect();
        if(selectString === "") {
            return;
        }

        if(!checkURLFormat(selectString)) {
            return;
        }

        if (!document.querySelector('#showQRcodeJs')) {
            // 添加div
            var div = document.createElement('div');
            div.setAttribute('id', 'showQRcodeJs');
            div.setAttribute('style', 'position:fixed;top:0;left:0;bottom:0;right:0;z-index:99999;background-color: rgba(0, 0, 0, 0.3);');
            div.innerHTML = html;
            document.body.appendChild(div);
            // 执行QRCode
            jQuery('#showQRcodeJsCanvas').qrcode(selectString);
        } else {
            document.body.removeChild(document.querySelector('#showQRcodeJs'));
            colse.removeEventListener("click", colsefn, false);
        }
        //添加监听
        var colse = document.querySelector('#showQRcodeJs');
        colse.addEventListener('click', colsefn = function() {
            document.body.removeChild(document.querySelector('#showQRcodeJs'));
        }, false);
    });
})();