Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name 2ch code embedded
- // @version 0.3.1
- // @match https://2ch.hk/*
- // @grant none
- // ==/UserScript==
- $(document).ready(getIframe);
- $('.posts').bind('DOMSubtreeModified', getIframe);
- function getIframe() {
- var re = /(pastebin\.com|ideone\.com|jsfiddle\.net|codepen\.io)\/(\w+\/)?(\w+\/pen\/)?(\w+)\/?$/;
- $('a[href^="http"')
- .filter(function() {
- return !$(this).hasClass('code-embedded') && re.test(this.href);
- })
- .addClass('code-embedded')
- .after(' <button class="embed-code">code</button>')
- .next('button.embed-code')
- .click(function() {
- var $this = $(this),
- match = $this.prev().attr('href').match(re);
- if (!match) return;
- var host = match[1],
- id = match[4],
- src = {
- 'pastebin.com': '//pastebin.com/embed_iframe.php?i=' + id,
- 'ideone.com' : '//ideone.com/embed/' + id,
- 'jsfiddle.net': '//jsfiddle.net/' + id + '/embedded/',
- 'codepen.io' : '//codepen.io/brianknapp/embed/' + id + '/?height=500'
- };
- $('<div>', {
- class: 'code-embedded',
- html: $('<iframe>', {
- src: src[host],
- style: 'border:none; width:800px; height:500px'
- })
- }).insertAfter(this);
- $this.remove();
- });
- }
Advertisement
Add Comment
Please, Sign In to add comment