7sIV799F

Untitled

Apr 8th, 2015
417
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name       2ch pastebin
  3. // @version    0.3
  4. // @match      https://2ch.hk/*
  5. // @grant      none
  6. // ==/UserScript==
  7.  
  8. $(document).ready(getIframe);
  9.  
  10. $('.posts').bind('DOMSubtreeModified', getIframe);
  11.  
  12. function getIframe() {
  13.   $('a[href*="pastebin.com"]')
  14.     .add('a[href*="ideone.com"]')
  15.     .add('a[href*="jsfiddle.net"]')
  16.     .add('a[href*="codepen.io"]')
  17.     .not('.code-embedded')
  18.     .addClass('code-embedded')
  19.     .after(' <button class="embed-code">code</button>')
  20.     .next('button.embed-code')
  21.       .click(function() {
  22.         var $this = $(this),
  23.             re    = /(pastebin\.com|ideone\.com|jsfiddle\.net|codepen\.io)\/(\w+\/pen\/)?(\w+)/,
  24.             match = $this.prev().attr('href').match(re);
  25.  
  26.         if (!match) return;
  27.  
  28.         var host = match[1],
  29.             id   = match[3],
  30.             src  = {
  31.               'pastebin.com': '//pastebin.com/embed_iframe.php?i=' + id,
  32.               'ideone.com'  : '//ideone.com/embed/' + id,
  33.               'jsfiddle.net': '//jsfiddle.net/' + id + '/embedded/',
  34.               'codepen.io'  : '//codepen.io/brianknapp/embed/' + id
  35.             };
  36.  
  37.         $('<div>', {
  38.           class: 'code-embedded',
  39.           html: $('<iframe>', {
  40.             src: src[host],
  41.             style: 'border:none; width:800px; height:500px'
  42.           })
  43.         }).insertAfter(this);
  44.  
  45.         $this.remove();
  46.       });
  47. }
Advertisement
Add Comment
Please, Sign In to add comment