Skip to content

Instantly share code, notes, and snippets.

@ludoo0d0a
Created June 5, 2019 13:07
Show Gist options
  • Save ludoo0d0a/d86b1dab9c7e0145f46ecb6937dd5d1c to your computer and use it in GitHub Desktop.
Save ludoo0d0a/d86b1dab9c7e0145f46ecb6937dd5d1c to your computer and use it in GitHub Desktop.
Bpmn Viewer for github
// ==UserScript==
// @name Bpmn Viewer
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Show a source Bpmn as a diagram
// @author LudoO
// @match https://github.com/*.bpmn
// @require https://unpkg.com/jquery@3.3.1/dist/jquery.js
// @require https://unpkg.com/bpmn-js@3.4.1/dist/bpmn-viewer.development.js
// @grant GM_xmlhttpRequest
// @grant GM_addStyle
// ==/UserScript==
(function() {
'use strict';
GM_addStyle('.canvas {border: solid 1px black; height:400px; } ');
var url = 'https://raw.githubusercontent.com'+$('#raw-url').attr('href');
$('.repository-content').prepend("<div class='canvas'><div id='js-canvas'></div></div>");
var viewer = new BpmnJS({
container: $('#js-canvas'),
height: 600
});
function load(xml){
viewer.importXML(xml, function(err) {
if (err) {
console.error(err);
} else {
viewer.get('canvas').zoom('fit-viewport');
}
});
}
function openFromUrl(url) {
GM_xmlhttpRequest({
url: url,
//anonymous: true,
headers: {
'Referer': 'https://www.github.com/',
'Access-Control-Allow-Origin': '*'
},
method: 'GET',
onload: function(res){
load(res.responseText);
}
});
}
$(function() {
var url = 'https://www.github.com'+$('#raw-url').attr('href');
console.log('load url : ['+url+' ]')
openFromUrl(url);
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment