Reep 二维码

链接转二维码

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

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

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 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);
    });
})();