Advertisement
Guest User

Untitled

a guest
Apr 16th, 2018
285
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.23 KB | None | 0 0
  1. // ==UserScript==
  2. // @name Wykop pastebin embed
  3. // @description Embeduje linki do pastebin.com
  4. // @version 0.1.1
  5. // @released 2018-04-16
  6. // @copyright aseeon, and wytrzeszcz
  7. // @namespace http://www.wykop.pl/*
  8. // @match *://www.wykop.pl/*
  9. // @downloadURL https://pastebin.com/raw/YAUpwPXZ
  10. // ==/UserScript==
  11.  
  12. // changelog add asynchronic load and small "fiutek" that works like orginal link
  13.  
  14. function embed_pastebin(pastebin_link, index){
  15. var id = pastebin_link.href.split('/').pop();
  16. var goto=document.createElement('a');
  17. var text=document.createTextNode("[^]");
  18. goto.title="link";
  19. goto.href=pastebin_link.href;
  20. goto.appendChild(text);
  21. pastebin_link.parentNode.insertBefore(goto,pastebin_link);
  22.  
  23. pastebin_link.onclick = function() {
  24. var existing_element = document.getElementById(id);
  25. if (existing_element) {
  26. existing_element.parentNode.removeChild(existing_element);
  27. } else {
  28. var pastebin_embed = document.createElement("iframe");
  29. pastebin_embed.src = 'https://pastebin.com/embed_iframe/' + id;
  30. pastebin_embed.style = 'border: none;width: 100%;height: 450px;margin-top: 10px;';
  31. pastebin_embed.id = id;
  32. pastebin_link.insertAdjacentElement('afterend', pastebin_embed);
  33.  
  34.  
  35. }
  36. return false;
  37. };
  38. }
  39.  
  40. (function() {
  41. const preper=function(){
  42. 'use strict';
  43. observerPaste.disconnect();
  44. var pastebin_links = document.querySelectorAll('div.text a[href*="pastebin.com"]');
  45. Array.prototype.forEach.call(pastebin_links, embed_pastebin);
  46. observerPaste = new MutationObserver(function(mut){
  47. var sum=0;
  48. mut.forEach(function(el,index){sum=sum+el.addedNodes.length;});
  49. if(sum>0)
  50. preper();});
  51. };
  52. var observerPaste = new MutationObserver(function(mut){
  53. var sum=0;
  54. mut.forEach(function(el,index){sum=sum+el.addedNodes.length;});
  55. if(sum>0)
  56. preper();});
  57. $(document).ready(function(){
  58. var config = { attributes: true, childList: true,subtree:true };
  59. observerPaste.observe(document.getElementById("itemsStream"),config);
  60. preper();
  61. });
  62. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement