Advertisement
Guest User

Embed Resource - endchan.net

a guest
Mar 25th, 2021
276
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name        Embed Resource - endchan.net
  3. // @namespace   Violentmonkey Scripts
  4. // @match       https://endchan.net/*
  5. // @grant       none
  6. // @version     1.0
  7. // @author      -
  8. // @description 3/25/2021, 4:11:44 PM
  9. // ==/UserScript==
  10. var css = `
  11. #threadList pre {
  12.   white-space: pre;
  13. }
  14. #threadList a.toggle {
  15.   cursor: pointer;
  16. }
  17. `;
  18.  
  19. // Add CSS to the document safely.
  20. function addCSS(css) {
  21.   if (typeof GM_addStyle != "undefined") {
  22.     GM_addStyle(css);
  23.   } else if (typeof PRO_addStyle != "undefined") {
  24.     PRO_addStyle(css);
  25.   } else if (typeof addStyle != "undefined") {
  26.     addStyle(css);
  27.   } else {
  28.     var node = document.createElement("style");
  29.     node.type = "text/css";
  30.     node.appendChild(document.createTextNode(css));
  31.     var heads = document.getElementsByTagName("head");
  32.     if (heads.length > 0) {
  33.       heads[0].appendChild(node);
  34.     } else {
  35.       // no head yet, stick it whereever
  36.       document.documentElement.appendChild(node);
  37.     }
  38.   }
  39. }
  40.  
  41. jQuery(() => {
  42.   // minimal css
  43.   addCSS(css)
  44.  
  45.   // embed pastebin
  46.   jQuery('a[href^="https://pastebin.com"]').each((i, a) => {
  47.     const match = jQuery(a).attr('href').match(/\.com\/(.*)/)
  48.     const id = match[1]
  49.     const href = `https://pastebin.com/embed_iframe.php?i=${id}`;
  50.     console.log(href);
  51.     jQuery(a).after(` <a class="toggle" data-id="pastebin-${id}">(Embed)</a><div class="pastebin" id="pastebin-${id}" style="display:none;"><iframe src="${href}" width="800" height="400"/></div>`)
  52.   })
  53.  
  54.   // generic embed toggler
  55.   jQuery('#threadList').on('click', 'a.toggle', (ev) => {
  56.     const $span = jQuery(ev.target)
  57.     const id = `#${$span.data('id')}`
  58.     jQuery(id).toggle()
  59.   })
  60. })
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement