Reep QRcode

generate QRcode for reep.io link

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==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://greasyfork.org/scripts/31884-qrcode-js/code/qrcodejs.js?version=208858
// @require      https://greasyfork.org/scripts/31885-jquery-qrcode-js/code/jqueryqrcodejs.js?version=208856
// ==/UserScript==
//
// 核心代码来自 编译小僵尸 https://greasyfork.org/users/85375
// https://greasyfork.org/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);
    });
})();