見ているページのURLをQRCode表示する

    
      
  • /*
     * @title 見ているページのURLをQRCode表示する
     * @description iOS11からデフォルトのカメラでQRCodeを読み込めるようになったので
     * @include http://*
     * @license MIT License 
     */
    
    
    javascript:(function(){
      var idname = 'qrplaceholder';
      var createPlaceholder = function(){
        var c = document.createElement('div');
        c.style.width = '100%25';
        c.style.height = '100%25';
        c.style.position = 'fixed';
        c.style.display = 'flex';
        c.style.top = '0';
        c.style.backgroundColor = 'rgba(0, 0, 0, 0.1)';
        c.zIndex = 10000;
        c.onclick = function(){
          document.body.removeChild(c);
        };
        var d = document.createElement('div');
        d.id = idname;
        d.style.width = '266px';
        d.style.height = '266px';
        d.style.marginTop = '10px';
        d.style.zIndex = 9999;
        d.style.margin = 'auto';
        c.appendChild(d);
        document.body.appendChild(c);
      };
    
      var showSvg = function(){
        try {
          var qrcode = new QRCode({
            content: window.location.href,
            width: 256,
            height: 256,
            padding: 4
          });
          document.getElementById(idname).innerHTML = qrcode.svg();
        }
        catch (e) {
          alert(e.message);
        }
      };
    
      var loadJS = function(onload){
        var s = document.createElement('script');
        document.head.appendChild(s);
        s.onload = onload;
        s.src = '//papnkukn.github.io/qrcode-svg/javascripts/qrcode.js';
      };
    
      loadJS(function(){
        createPlaceholder();
        showSvg();
      });
    })()
  • Permalink
    このページへの個別リンクです。
    RAW
    書かれたコードへの直接のリンクです。
    Packed
    文字列が圧縮された書かれたコードへのリンクです。
    Userscript
    Greasemonkey 等で利用する場合の .user.js へのリンクです。
    Loader
    @require やソースコードが長い場合に多段ロードする Loader コミのコードへのリンクです。
    Metadata
    コード中にコメントで @xxx と書かれたメタデータの JSON です。

History

  1. 2017/09/24 00:19:34 - 2017-09-24