Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name Embed Resource - endchan.net
- // @namespace Violentmonkey Scripts
- // @match https://endchan.net/*
- // @grant none
- // @version 1.0
- // @author -
- // @description 3/25/2021, 4:11:44 PM
- // ==/UserScript==
- var css = `
- #threadList pre {
- white-space: pre;
- }
- #threadList a.toggle {
- cursor: pointer;
- }
- `;
- // Add CSS to the document safely.
- function addCSS(css) {
- if (typeof GM_addStyle != "undefined") {
- GM_addStyle(css);
- } else if (typeof PRO_addStyle != "undefined") {
- PRO_addStyle(css);
- } else if (typeof addStyle != "undefined") {
- addStyle(css);
- } else {
- var node = document.createElement("style");
- node.type = "text/css";
- node.appendChild(document.createTextNode(css));
- var heads = document.getElementsByTagName("head");
- if (heads.length > 0) {
- heads[0].appendChild(node);
- } else {
- // no head yet, stick it whereever
- document.documentElement.appendChild(node);
- }
- }
- }
- jQuery(() => {
- // minimal css
- addCSS(css)
- // embed pastebin
- jQuery('a[href^="https://pastebin.com"]').each((i, a) => {
- const match = jQuery(a).attr('href').match(/\.com\/(.*)/)
- const id = match[1]
- const href = `https://pastebin.com/embed_iframe.php?i=${id}`;
- console.log(href);
- 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>`)
- })
- // generic embed toggler
- jQuery('#threadList').on('click', 'a.toggle', (ev) => {
- const $span = jQuery(ev.target)
- const id = `#${$span.data('id')}`
- jQuery(id).toggle()
- })
- })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement