Guest User

blocked catbox soundpost fix

a guest
Dec 8th, 2023
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.60 KB | None | 0 0
  1. // ==UserScript==
  2. // @name blocked catbox soundpost fix
  3. // @namespace fuwamocobaubau
  4. // @description Replaces files.catbox.moe links with files.pixstash.moe on soundposts. Site files.pixstash.moe is a simple passthrough to bypass ISP blocks.
  5. // @author fuwamocobaubau
  6. // @license MIT
  7. // @version 0.3
  8. // @match *://boards.4chan.org/*
  9. // @match *://boards.4channel.org/*
  10. // @match *://desuarchive.org/*
  11. // @match *://arch.b4k.co/*
  12. // @match *://archived.moe/*
  13. // @match *://warosu.org/*
  14. // @match *://archive.nyafuu.org/*
  15. // @icon data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
  16. // @grant none
  17. // ==/UserScript==
  18.  
  19. (function() {
  20. 'use strict';
  21.  
  22. window.isChanX = document.documentElement && document.documentElement.classList.contains('fourchan-x');
  23. window.isSiteAddedToWhiteList = false;
  24.  
  25. // look for any catbox soundposts and replace the sound url with a pixstash link
  26. function rewriteCatbox(target) {
  27. let posts = target.classList.contains('post')
  28. ? [ target ]
  29. : target.querySelectorAll('.post');
  30.  
  31. let filename = null;
  32. let filenameLocations = {
  33. '.fileText .file-info .fnfull': 'textContent',
  34. '.fileText .file-info > a': 'textContent',
  35. '.fileText > a': 'title',
  36. '.fileText': 'textContent'
  37. }
  38.  
  39.  
  40. posts.forEach(post => {
  41. Object.keys(filenameLocations).some(function (selector) {
  42. const node = post.querySelector(selector);
  43.  
  44. node && (filename = node[filenameLocations[selector]]);
  45. if (filename && filename.includes('files.catbox.moe')) {
  46. node[filenameLocations[selector]] = filename.replace('files.catbox.moe', 'files.pixstash.moe')
  47. }
  48. });
  49.  
  50. });
  51. }
  52.  
  53. async function doInit() {
  54. // does the link rewriting on initial page load
  55. rewriteCatbox(document.body);
  56.  
  57. // sets up an observer so that new posts added via auto updating also have their link rewriten
  58. const observer = new MutationObserver(function (mutations) {
  59. mutations.forEach(function (mutation) {
  60. if (mutation.type === 'childList') {
  61. mutation.addedNodes.forEach(function (node) {
  62. if (node.nodeType === Node.ELEMENT_NODE) {
  63. rewriteCatbox(node);
  64.  
  65. if (node.className == 'fcsp-image-link' && window.isSiteAddedToWhiteList == false) {
  66. // Update the site filter/whitelist settings to allow loading soundposts from pixstash.moe urls
  67. document.dispatchEvent(new CustomEvent('PlayerEvent', {
  68. detail: {
  69. action: 'settings.load',
  70. arguments: [
  71. {"allow": ["pixstash.moe", "4cdn.org", "catbox.moe", "dmca.gripe", "lewd.se", "pomf.cat", "zz.ht", "zz.fo"] },
  72. { "applyDefault": false }
  73. ]
  74. }
  75. }))
  76.  
  77. window.isSiteAddedToWhiteList = true;
  78. }
  79. }
  80. });
  81. }
  82. });
  83. });
  84.  
  85. observer.observe(document.body, {
  86. childList: true,
  87. subtree: true
  88. });
  89. }
  90.  
  91. document.addEventListener('4chanXInitFinished', doInit);
  92.  
  93. // The timeout makes sure 4chan X will have added it's classes and be identified.
  94. setTimeout(function () {
  95. // If it's already known 4chan X is installed this can be skipped.
  96. if (!isChanX) {
  97. if (document.readyState !== 'loading') {
  98. doInit();
  99. } else {
  100. document.addEventListener('DOMContentLoaded', doInit);
  101. }
  102. }
  103. }, 0);
  104. })();
Add Comment
Please, Sign In to add comment