Advertisement
Guest User

Untitled

a guest
May 13th, 2012
1,022
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name           ExSauce
  3. // @namespace      hurfdurf
  4. // @version        2.0
  5. // @include        http://boards.4chan.org/*
  6. // ==/UserScript==
  7.  
  8. // Original from http://pastebin.com/TTDJNH7c
  9. // Modified by /a/nonymous
  10. // Thanks to 4chan SS for helping me figure this shit out.
  11. // No thanks to 4chan SS for making it hard by using jQuery!
  12. // Works with the new 4chan HTML.
  13.  
  14. function addLinks(x) {
  15.     setTimeout(function()
  16.                 {
  17.                     var targets = x.querySelectorAll('a[class=fileThumb]');
  18.                     for (var i=0;i<targets.length;i++)
  19.                     {
  20.                         var node = targets[i].previousSibling;
  21.                         var a = document.createElement('a');
  22.                         a.innerHTML = 'exhentai';
  23.                         a.href = targets[i].href;
  24.                         a.addEventListener('click',fetchImage,false);
  25.                         node.appendChild(document.createTextNode(" "));
  26.                         node.appendChild(a);
  27.                     };
  28.                 }, 10);
  29. }
  30.  
  31. function fetchImage(e) {
  32.     if (e.which !== 1) return;
  33.     e.preventDefault();
  34.     var a = e.target;
  35.     a.textContent = 'loading';
  36.     GM_xmlhttpRequest(
  37.                 {
  38.                     method: "GET",
  39.                     url: a.href,
  40.                     overrideMimeType: "text/plain; charset=x-user-defined",
  41.                     headers: { "Content-Type": "image/jpeg" },
  42.                     onload: function(x) { checkTitles(a, x.responseText); }
  43.                 });
  44. }
  45.  
  46. function checkTitles(anchor,data) {
  47.     var hash = sha1Hash(data_string(data));
  48.     anchor.innerHTML = 'checking';
  49.     var div = document.createElement('div');
  50.     div.className = 'exPopup';
  51.     div.id = 'ex' + hash;
  52.     div.style.display = 'none';
  53.     anchor.href = 'http://exhentai.org/?f_shash=' + hash + '&fs_similar=1&fs_exp=1';
  54.     anchor.removeEventListener('click',fetchImage,false);
  55.     document.body.appendChild(div);
  56.     GM_xmlhttpRequest({
  57.         method:'GET',
  58.         url:anchor.href,
  59.         onload:function(x) {
  60.        
  61.             var temp = document.createElement('div');
  62.             temp.innerHTML = x.responseText;
  63.             var results = temp.querySelectorAll('div.it3 > a:not([rel="nofollow"]), div.itd2 > a:not([rel="nofollow"])');
  64.             var MAX = results.length;
  65.            
  66.             target = document.getElementById('ex' + hash);
  67.            
  68.             for (var i=0;i<MAX;i++) {
  69.                 target.appendChild(document.createTextNode(results[i].innerHTML));
  70.                 if (i<results.length-1) target.appendChild(document.createElement('br'));
  71.             }
  72.             anchor.innerHTML = 'found: ' + MAX;
  73.             anchor.setAttribute('target','_blank');
  74.             if (results.length) {
  75.                 anchor.addEventListener('mouseover',function(e) { document.getElementById('ex' + hash).style.display = null; },false);
  76.                 anchor.addEventListener('mousemove',function(e) { var target = document.getElementById('ex' + hash); target.style.left = (e.clientX+50) + 'px'; target.style.top = (e.clientY+10) + 'px'; },false);
  77.                 anchor.addEventListener('mouseout',function() { document.getElementById('ex' + hash).style.display = 'none'; },false);
  78.             }
  79.         }
  80.     });
  81. }
  82.  
  83. // ----------
  84.  
  85. function data_string(data) {
  86.         var data_string='';
  87.         for (var i=0,il=data.length;i<il;i++) data_string+=String.fromCharCode(data[i].charCodeAt(0)&0xff);
  88.         return data_string;
  89. }
  90.  
  91.  
  92. function sha1Hash(msg) {
  93.                 var K = [0x5a827999, 0x6ed9eba1, 0x8f1bbcdc, 0xca62c1d6];
  94.                 msg += String.fromCharCode(0x80);
  95.                 var l = msg.length/4 + 2;
  96.                 var N = Math.ceil(l/16);
  97.                 var M = new Array(N);
  98.                 for (var i = 0; i < N; i++)
  99.                 {
  100.                     M[i] = new Array(16);
  101.                     for (var j = 0; j < 16; j++)
  102.                         M[i][j] = (msg.charCodeAt(i*64+j*4)<<24) | (msg.charCodeAt(i*64+j*4+1)<<16) |
  103.                                   (msg.charCodeAt(i*64+j*4+2)<<8) | (msg.charCodeAt(i*64+j*4+3));
  104.                 }
  105.                
  106.                 M[N-1][14] = ((msg.length-1)*8) / Math.pow(2, 32); M[N-1][14] = Math.floor(M[N-1][14])
  107.                 M[N-1][15] = ((msg.length-1)*8) & 0xffffffff;
  108.  
  109.                 var H0 = 0x67452301;
  110.                 var H1 = 0xefcdab89;
  111.                 var H2 = 0x98badcfe;
  112.                 var H3 = 0x10325476;
  113.                 var H4 = 0xc3d2e1f0;
  114.  
  115.                 var W = new Array(80);
  116.                 var a, b, c, d, e;
  117.                 for (var i = 0; i < N; i++)
  118.                 {
  119.                     for (var t = 0; t < 16; t++)
  120.                         W[t] = M[i][t];
  121.                        
  122.                     for (var t = 16; t < 80; t++)
  123.                         W[t] = ROTL(W[t-3] ^ W[t-8] ^ W[t-14] ^ W[t-16], 1);
  124.                        
  125.                     a = H0;
  126.                     b = H1;
  127.                     c = H2;
  128.                     d = H3;
  129.                     e = H4;
  130.                    
  131.                     for (var t = 0; t < 80; t++)
  132.                     {
  133.                         var s = Math.floor(t/20);
  134.                         var T = (ROTL(a,5) + f(s,b,c,d) + e + K[s] + W[t]) & 0xffffffff;
  135.                         e = d;
  136.                         d = c;
  137.                         c = ROTL(b, 30);
  138.                         b = a;
  139.                         a = T;
  140.                     }
  141.                    
  142.                     H0 = (H0+a) & 0xffffffff;
  143.                     H1 = (H1+b) & 0xffffffff;
  144.                     H2 = (H2+c) & 0xffffffff;
  145.                     H3 = (H3+d) & 0xffffffff;
  146.                     H4 = (H4+e) & 0xffffffff;
  147.                 }
  148.                
  149.                 return H0.toHexStr() + H1.toHexStr() + H2.toHexStr() + H3.toHexStr() + H4.toHexStr();
  150. }
  151.  
  152. function f(s, x, y, z) {
  153.     switch (s) {
  154.         case 0: return (x & y) ^ (~x & z);
  155.         case 1: return x ^ y ^ z;
  156.         case 2: return (x & y) ^ (x & z) ^ (y & z);
  157.         case 3: return x ^ y ^ z;
  158.     }
  159. }
  160.  
  161. function ROTL(x, n) {
  162.     return (x<<n) | (x>>>(32-n));
  163. }
  164.  
  165. Number.prototype.toHexStr = function() {
  166.     var s="", v;
  167.     for (var i=7; i>=0; i--) { v = (this>>>(i*4)) & 0xf; s += v.toString(16); }
  168.     return s;
  169. }
  170.  
  171. // ----------
  172.  
  173.  
  174. var style = document.createElement('style');
  175. style.innerHTML = '.exPopup { position: fixed; background: white; padding: 5px; border: 1px black solid; color: black; }';
  176. document.head.appendChild(style);
  177.  
  178. addLinks(document);
  179. document.addEventListener('DOMNodeInserted',function(e) { if (e.target.nodeName == 'DIV') addLinks(e.target); },false);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement