Advertisement
Guest User

Thumbnail für SVGTranslate

a guest
Dec 5th, 2010
286
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @include       http://toolserver.org/~nikola/svgtranslate.php?*
  3. // ==/UserScript==
  4.  
  5. function showThumbnail(resp) {
  6.     if(!resp || !resp.query || !resp.query.pages) {
  7.         return;
  8.     }
  9.     resp = resp.query.pages;
  10.     for(var e in resp) {
  11.         resp = resp[e];
  12.         break;
  13.     }
  14.     if(!resp || !resp.imageinfo || !resp.imageinfo[0]) {
  15.         return;
  16.     }
  17.     resp = resp.imageinfo[0];
  18.     if(!resp.thumburl || !resp.thumbwidth || !resp.thumbheight || !resp.descriptionurl) {
  19.         return;
  20.     }
  21.     var a = document.createElement("a");
  22.     a.setAttribute("href", resp.descriptionurl);
  23.     var img = a.appendChild(document.createElement("img"));
  24.     img.setAttribute("src", resp.thumburl);
  25.     img.setAttribute("width", resp.thumbwidth);
  26.     img.setAttribute("height", resp.thumbheight);
  27.     img.style.border = "1px solid #aaa";
  28.     img.style.cssFloat = "right";
  29.     document.body.insertBefore(a, document.forms[0]);
  30. }
  31.  
  32. (function() {
  33.     var path = /^(?:&|\?)svg=([^&]+)/.exec(window.location.search);
  34.     if(!path) {
  35.         return;
  36.     }
  37.     path = /^(?:https?:\/\/)(?:[^\/]+)\/([^\/]+)\/([^\/]+)\/.+?\/([^\/]+)$/.exec(
  38.             decodeURIComponent(path[1]));
  39.     if(!path) {
  40.         return;
  41.     }
  42.     var parameters = [
  43.             "action=query",
  44.             "prop=imageinfo",
  45.             "iiprop=url",
  46.             "iiurlwidth=600",
  47.             "iiurlheight=600",
  48.             "format=json",
  49.             "callback=showThumbnail",
  50.             "titles=" + "File:" + encodeURIComponent(path[3])];
  51.     var api = encodeURI("http://" + path[2] + "." + path[1] + ".org/w/api.php");
  52.     var script = document.createElement("script");
  53.     script.setAttribute("type", "text/javascript");
  54.     script.setAttribute("encoding", "UTF-8");
  55.     script.setAttribute("defer", "defer");
  56.     script.setAttribute("src", api + "?" + parameters.join("&"));
  57.     document.getElementsByTagName("head")[0].appendChild(script);
  58. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement