Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name Images for TF2R Chat - Error Edition
- // @description Attempts to embed link as image by Shift-clicking on it. Shift-clicking again would hide it.
- // @version 1.6
- // @include http://tf2r.com/chat.html
- // @include http://tf2r.com/k*.html
- // ==/UserScript==
- (function() {
- function wrapper () {
- (function(){
- var tryToEmbedLink = function(a) {
- a = $(a);
- var href = a.attr('href');
- if (href === undefined) return false;
- if ( // domains and file extension
- (/^[^?#]*?(?:\.png|\.jpg|\.bmp|\.jpeg|\.gif|\.ico|\.apng)(?:[?#].*?)*?$/i).test(href)
- || (/^http(?:|s):\/\/[^\.]+?\.steampowered\.com\/.*?$/i).test(href)
- || (/^http(?:|s):\/\/[^\.]+?\.steamcommunity\.com\/.*?$/i).test(href)
- || (/^http(?:|s):\/\/(?:www\.|)puu.sh\/.*?$/i).test(href)
- || (/^http(?:|s):\/\/(?:www\.|)ompldr\.org\/.*?$/i).test(href)
- ) {
- $("<img>", {
- load: function () {
- $(this).attr('style', 'max-width: 560px; max-height: 400px;');
- var embedContainer = $(
- '<div class="iws-embedded-image-container">\
- <div style="clear:both;float:none;"></div>\
- <div style="clear:both;float:none;"></div>\
- </div>'
- );
- var imageWrap = a.clone();
- imageWrap.html(this).insertAfter(embedContainer.find('div:first'));
- embedContainer.data('originalTag', a);
- a.replaceWith(embedContainer);
- },
- error: function() {
- $(this).remove();
- },
- src: a.attr('href')
- });
- }
- };
- $('.userfeed, #chat').delegate('.userfeedpost .ufmes a', 'click', function(e) {
- if (e.shiftKey) {
- var $embed = $(this).closest('.iws-embedded-image-container');
- if ($embed.length > 0) {
- $embed.replaceWith($embed.data('originalTag'));
- } else {
- tryToEmbedLink(this);
- }
- e.preventDefault();
- return false;
- }
- });
- })();
- };
- var script = document.createElement('script');
- script.appendChild(document.createTextNode('('+ wrapper +')();'));
- (document.head || document.body || document.documentElement).appendChild(script);
- })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement