Advertisement
errur

Untitled

Jan 14th, 2013
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name           Images for TF2R Chat - Error Edition
  3. // @description    Attempts to embed link as image by Shift-clicking on it. Shift-clicking again would hide it.
  4. // @version        1.6
  5. // @include        http://tf2r.com/chat.html
  6. // @include        http://tf2r.com/k*.html
  7. // ==/UserScript==
  8.  
  9. (function() {
  10.     function wrapper () {
  11.         (function(){
  12.             var tryToEmbedLink = function(a) {
  13.                 a = $(a);
  14.                 var href = a.attr('href');
  15.                 if (href === undefined) return false;
  16.                
  17.                 if ( // domains and file extension
  18.                         (/^[^?#]*?(?:\.png|\.jpg|\.bmp|\.jpeg|\.gif|\.ico|\.apng)(?:[?#].*?)*?$/i).test(href)
  19.                         || (/^http(?:|s):\/\/[^\.]+?\.steampowered\.com\/.*?$/i).test(href)
  20.                         || (/^http(?:|s):\/\/[^\.]+?\.steamcommunity\.com\/.*?$/i).test(href)
  21.                         || (/^http(?:|s):\/\/(?:www\.|)puu.sh\/.*?$/i).test(href)
  22.                         || (/^http(?:|s):\/\/(?:www\.|)ompldr\.org\/.*?$/i).test(href)
  23.                 ) {
  24.                     $("<img>", {
  25.                         load: function () {
  26.                             $(this).attr('style', 'max-width: 560px; max-height: 400px;');
  27.                             var embedContainer = $(
  28.                                 '<div class="iws-embedded-image-container">\
  29.                                     <div style="clear:both;float:none;"></div>\
  30.                                     <div style="clear:both;float:none;"></div>\
  31.                                 </div>'
  32.                             );
  33.                             var imageWrap = a.clone();
  34.                             imageWrap.html(this).insertAfter(embedContainer.find('div:first'));
  35.                             embedContainer.data('originalTag', a);
  36.                             a.replaceWith(embedContainer);
  37.                         },
  38.                         error: function() {
  39.                             $(this).remove();
  40.                         },
  41.                         src: a.attr('href')
  42.                     });
  43.                 }
  44.             };
  45.             $('.userfeed, #chat').delegate('.userfeedpost .ufmes a', 'click', function(e) {
  46.                 if (e.shiftKey) {
  47.                     var $embed = $(this).closest('.iws-embedded-image-container');
  48.                     if ($embed.length > 0) {
  49.                         $embed.replaceWith($embed.data('originalTag'));
  50.                     } else {
  51.                         tryToEmbedLink(this);
  52.                     }
  53.                     e.preventDefault();
  54.                     return false;
  55.                 }
  56.             });
  57.         })();
  58.     };
  59.  
  60.     var script = document.createElement('script');
  61.     script.appendChild(document.createTextNode('('+ wrapper +')();'));
  62.     (document.head || document.body || document.documentElement).appendChild(script);
  63.  
  64. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement