Last active
August 29, 2015 14:02
-
-
Save shtrih/a3ddb3d6b66e4b0013a3 to your computer and use it in GitHub Desktop.
logs.4otaku.org pictures preview
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name logs-preview | |
// @namespace https://gist.github.com/shtrih/a3ddb3d6b66e4b0013a3 | |
// @version 0.3 | |
// @description enter something useful | |
// @match http://old.4otaku.org/logs* | |
// @copyright 2014+, shtrih | |
// ==/UserScript== | |
function scriptBody() { | |
var image_links = $('a[href$="jpg"],a[href$="gif"],a[href$="png"],a[href$="jpeg"]', '#logs'), | |
youtube_links = $('a', '#logs').filter(function () { | |
return $(this).attr('href').match(/^https?:\/\/(www\.)?youtu(\.be|be\.com)/); | |
}); | |
; | |
image_links.each(function () { | |
$(this).html( | |
$('<img/>', { | |
src: $(this).attr('href'), | |
width: '200px', | |
css: { | |
margin: '5px' | |
} | |
}) | |
).prepend('<br />'); | |
}); | |
youtube_links.each(function () { | |
var link = $(this), | |
yt_id = link.attr('href').match(/v=([^&]*)|be\/([^?\/]*)/) | |
; | |
yt_id = yt_id[1] || yt_id[2]; | |
var yt_preview = $('<a/>', { | |
href: link.attr('href'), | |
click: function() { | |
$(this).after( | |
$('<iframe/>', { | |
src: 'http://www.youtube.com/embed/'+ yt_id +'?wmode=opaque&theme=light&autoplay=1', | |
width: '560', | |
height: '315', | |
frameborder: '0' | |
}) | |
); | |
this.remove(); | |
return false; | |
}, | |
html: '<img src="http://i3.ytimg.com/vi/'+ yt_id +'/hqdefault.jpg" width="" style="margin: 5px;" />' | |
}) | |
; | |
link.after( | |
yt_preview | |
) | |
.after('<br />') | |
; | |
}); | |
} | |
var script = document.createElement('script'); | |
script.textContent = '(' + scriptBody.toString() + ')()'; | |
(document.head||document.documentElement).appendChild(script); | |
script.parentNode.removeChild(script); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment