Open main menu

Changes

MediaWiki:QRCode.js

2,159 bytes added, 5 years ago
Created page with "/* This is userscirpt to genreate qr Code on wiki. @Author User:Jayprakash12345 @OwnBy meta:Indic-TechCom Please note The word "QR Code" is registered t..."
/*
This is userscirpt to genreate qr Code on wiki.

@Author [[User:Jayprakash12345]]
@OwnBy [[meta:Indic-TechCom]]

Please note The word "QR Code" is registered trademark of DENSO WAVE INCORPORATED
*/
$(document).ready( function() {

// Load module
mw.loader.load( 'https://meta.wikimedia.org/w/index.php?title=User:Jayprakash12345/jquery-qrcode.min.js&action=raw&ctype=text/javascript' );

// Add a portlet link.
var link = mw.util.addPortletLink(
'p-tb',
'#',
'Genreate QR code'
);

// Trigger for portlet link
$(link).click( function( e ) {
e.preventDefault();

pageName = mw.config.get( 'wgPageName' )
url = 'https:' + mw.config.get( 'wgServer' ) + '/wiki/' + mw.config.get( 'wgPageName' );

// Create dic with qrCode id
qrCodeDiv = $( '<div/>' ).attr('id','qrCode');

// Create paragraph
para = $('<p/>').css('font-weight', 'bold').text('This is the QR Code for '+ url + ' URL.' )
$( qrCodeDiv ).append( para, '<br/>' );


$( '#bodyContent' ).children().hide();
$( '#bodyContent' ).append( qrCodeDiv );

var qrcode = $( '#qrCode' ).qrcode( {
render: 'canvas',
text: url,
size: '460'
} );

mw.loader.using( 'oojs-ui-core' ).done( function () {

var downloadBtn = new OO.ui.ButtonWidget( { label: 'Download PNG' } ),
cancelBtn = new OO.ui.ButtonWidget( { label: 'Back to Page', flags: ['destructive' ] } );

cancelBtn.on( 'click', function () {
location.reload();
} );

downloadBtn.on( 'click', function () {
var a = document.createElement('a');
a.href = $(document).find('canvas').get(0).toDataURL('image/png');
a.download = mw.config.get( 'wgPageName' ) + '-qrCode.png';
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
} );

var notice = '<br/><br/><small>Notice: The word QR Code is registered trademark of DENSO WAVE INCORPORATED</small>';

$( '#qrCode' ).append( '<br/><br/>', downloadBtn.$element, cancelBtn.$element, notice );
} );

});

});