Advertisement
SPennLUE

ETI Image Transload

Jan 8th, 2013
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name           ETI Image Transload
  3. // @namespace      shoecream@luelinks.net
  4. // @description    Transloads images from web sites onto ETI
  5. // @include        *
  6. // @exclude        http://endoftheinter.net*
  7. // @exclude        https://endoftheinter.net*
  8. // @exclude        http://*.endoftheinter.net*
  9. // @exclude        https://*.endoftheinter.net*
  10. // @require        http://userscripts.org/scripts/source/69456.user.js
  11. // @history        1.1 Release
  12. // @history        1.0 First version
  13. // ==/UserScript==
  14.  
  15. String.prototype.supplant = function (o) {
  16.     return this.replace(/{([^{}]*)}/g,
  17.         function (a, b) {
  18.             var r = o[b];
  19.             return typeof r === 'string' || typeof r === 'number' ? r : a;
  20.         }
  21.     );
  22. };
  23.  
  24. function findpos (element) {
  25.   var d = {x:0,y:0};
  26.   d.h = element.offsetHeight;
  27.   d.w = element.offsetWidth;
  28.   do {
  29.     d.x += element.offsetLeft;
  30.     d.y += element.offsetTop;
  31.   } while (element = element.offsetParent);
  32.  
  33.   return d;
  34. }
  35.  
  36. var boxes = [];
  37.  
  38. function createFloatBox (dims, dom) {
  39.   var div = document.createElement('div');
  40.   dims.x -= 3; dims.y -= 3;
  41.   var style = 'position:absolute;left:{x}px;top:{y}px;height:{h}px;width:{w}px;border:3px dashed red;cursor:pointer;z-index:1000'.supplant(dims);
  42.   div.setAttribute('style', style);
  43.   div.setAttribute('value', dom.src);
  44.   div.addEventListener('mouseover', mouseover, false);
  45.   div.addEventListener('mouseout', mouseout, false);
  46.   div.addEventListener('click', click, false);
  47.   boxes.push(div);
  48.   document.body.appendChild(div);
  49.  
  50.   function mouseover (ee) { ee.target.style.borderColor = 'green'; }
  51.   function mouseout (ee) { ee.target.style.borderColor = 'red'; }
  52.  
  53.   function click (ee) {
  54.     document.body.style.cursor = 'wait';    
  55.     transload (ee.target);
  56.     boxes.forEach(function (box) {
  57.       box.parentNode.removeChild(box);
  58.     });
  59.   }
  60. }
  61.  
  62. function transload (dom) {
  63.   var href = dom.getAttribute('value');
  64.   BinaryRes.get({url: href, callback: transload_got});
  65. }
  66.  
  67. function transload_got (resp) {
  68.   filename = (resp.finalUrl.split('/') || ['something.jpg']).pop();
  69.   BinaryRes.post({
  70.     url: 'http://u.endoftheinter.net/u.php',
  71.     callback: transload_posted,
  72.     data: {
  73.       file: {
  74.         value: BinaryRes._clean(resp.responseText),
  75.         filename: filename,
  76.         type: BinaryRes.guessType(resp.responseText)
  77.       }
  78.     }
  79.   });
  80. }
  81.  
  82. function transload_posted (resp) {
  83.   document.body.style.cursor = 'default';
  84.   var html = document.createElement('html');
  85.   html.innerHTML = resp.responseText;
  86.   // newly uploaded images are always the first to be returned
  87.   var value = html.getElementsByClassName('img')[0].getElementsByTagName('input')[0].value;
  88.   prompt('Here is your image', value);
  89. }
  90.  
  91. function highlight () {
  92.   [].forEach.call(document.getElementsByTagName('img'), function (img) {
  93.     createFloatBox(findpos(img), img);
  94.   });
  95. }
  96.  
  97. GM_registerMenuCommand('Start ETI Image Transload', highlight);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement