Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
/**
* Experimental "Send page to alternative render server" gadget
*
* Prerequisites:
* - a running instance of the electron render server (https://github.com/msokk/electron-render-service )
* - add some explanation and a link a link href='#chrome-print' to the page Mediawiki:Coll-rendering_finished_text ( or MediaWiki:Coll-request_failed_msg if you're testing without a working OCG renderer)
*
* Author: Gabriel Birke < gabriel.birke@wikimedia.de >
*/
function getQueryVariable(variable) {
var query = window.location.search.substring(1);
var vars = query.split('&');
for (var i = 0; i < vars.length; i++) {
var pair = vars[i].split('=');
if (decodeURIComponent(pair[0]) == variable) {
return decodeURIComponent(pair[1]);
}
}
}
$(document).ready( function() {
$("a[href=#chrome-print]").click( function( e ) {
e.preventDefault();
// TODO: Ask user for params (paper format, margins, orientation)
// TODO: make renderer URL configurable
// TODO set up proxy on tool labs that checks page for valid wikimedia url (so people cant use it to print arbitrary internet pages) The proxy will also hide the secret access token and generate headers for file name and contet type.
var rendererUrl = "http://192.168.33.11:3000/pdf?accessKey=secret&url=";
var pageTitle = getQueryVariable('arttitle');
if ( !pageTitle ) {
return;
}
console.log("pt",pageTitle);
var pageUrl = mw.config.get( 'wgServer' ) + mw.config.get( 'wgScript' ) + '?title=' + pageTitle + '&printable=yes';
window.open(rendererUrl + encodeURIComponent( pageUrl) );
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment