Matt23

Untitled

Aug 30th, 2016
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name        Lex.pl Graphics Plugin
  3. // @namespace   matt23.lex.graphics.plugin
  4. // @description Wyświetla grafiki w serwisie Lex
  5. // @version     1
  6. // @include     http://*.lex.pl/*
  7. // @include     https://*.lex.pl/*
  8. // @grant       none
  9. // ==/UserScript==
  10.  
  11. function getRandomInt() {
  12.   max = 10000000;
  13.   min = 100000;
  14.   return Math.floor(Math.random() * (max - min)) + min;
  15. }
  16.  
  17. function modifyCssRules(className, content) {
  18.   re = /(\.\w+\s{)/g;
  19.   return content.replace(re, "." + className + ' $1');
  20. }
  21.  
  22. function extractSVG(data) {
  23.   return data.substring(data.indexOf('<svg'));
  24. }
  25.  
  26. function renderSVGs(item) {
  27.   $.get(item.href, function(data) {
  28.     content = extractSVG(data);
  29.     className = 'graphicsRender' + getRandomInt();
  30.    
  31.     item.parentNode.className += ' ' + className;
  32.     svg = modifyCssRules(className, content);
  33.    
  34.     item.parentNode.innerHTML = svg;
  35.   });
  36. };
  37.  
  38. function doMagic() {
  39.   $('a[href$="SVG"]').each(function(index) {
  40.     renderSVGs(this);
  41.   });  
  42. }
  43.  
  44. document.addEventListener("keypress", function(event) {
  45.     doMagic();
  46. });
Advertisement
Add Comment
Please, Sign In to add comment