1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- /**
- * QR码解码
- */
- var qrDecode = (function () {
- "use strict";
- var _show = function(text){
- var el = $('#__fehelper_qr_decode__');
- if(!el[0]){
- el = $('<div id="__fehelper_qr_decode__" style="z-index:999999;position: fixed;left:0;top:0;right: 0;bottom: 0;display: none;">' +
- '<div style="position: fixed;left:0;top:0;right: 0;bottom: 0;background: #000;opacity: 0.5;"></div>' +
- '<div style="position: relative;top: 100px;left: ' + ($('body').width() / 2 - 200) + 'px;border:1px solid #000;background:#fff;width:420px;padding:15px;border-radius:5px 5px;box-shadow:2px 2px 5px #000;">' +
- '<div style="margin: 0 0 10px 0;font-size: 14px;font-weight: bold;">二维码解码结果:</div>' +
- '<textarea style="display:block;border-radius:5px 5px;width:398px;border:1px solid #aaa;min-height:80px;resize:none;box-shadow:2px 2px 5px #aaa;padding:10px;font-size:14px;color:#888;"></textarea>' +
- '<div style="margin-top:10px;">' +
- '<span id="__fehelper_qr_msg_" style="float: right;color:#f00;display:none;">复制成功!</span>' +
- '<a id="__fehelper_qr_copy_" style="margin-right:20px;color: #00f;text-decoration: underline" href="#">复制</a>' +
- '<a id="__fehelper_qr_close_" style="margin-top:10px;color: #00f;text-decoration: underline" href="#">关闭</a>' +
- '</div></div>' +
- '</div>').appendTo('body');
- el.find('a#__fehelper_qr_copy_').click(function(e){
- e.preventDefault();
- el.find('textarea').select();
- document.execCommand('Copy');
- el.find('#__fehelper_qr_msg_').show().delay(2000).hide('slow');
- });
- el.find('a#__fehelper_qr_close_').click(function(e){
- e.preventDefault();
- el.hide('slow');
- });
- }
- if(text == 'error decoding QR Code') {
- text = '抱歉,二维码识别失败!';
- }
- el.show('slow').find('textarea').val(text);
- };
- var _init = function () {
- // 在tab创建或者更新时候,监听事件,看看是否有参数传递过来
- chrome.runtime.onMessage.addListener(function (request, sender, callback) {
- if (request.type == MSG_TYPE.QR_DECODE) {
- _show(request.result);
- }
- });
- };
- return {
- init: _init
- };
- })();
- qrDecode.init();
|