4chan Save

Save the 4chan thread

  1. // ==UserScript==
  2. // @name 4chan Save
  3. // @namespace http://github.com/hangjeff
  4. // @version 2025-03-27_14h03m
  5. // @description Save the 4chan thread
  6. // @author hangjeff
  7. // @match https://boards.4chan.org/*
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. (function() {
  12. 'use strict';
  13.  
  14. // Your code here...
  15. document.querySelectorAll('.thread').forEach(thread => {
  16. let fileThumb = thread.querySelector('.fileThumb');
  17. if(fileThumb){
  18. let Komica_File_Url = 'https:' + fileThumb.getAttribute('href');
  19. let fileText = thread.querySelector('.fileText');
  20.  
  21. if(fileThumb.getAttribute('href').includes('.webm') || fileThumb.getAttribute('href').includes('.mp4')){
  22. fileText.appendChild(GhostArchive_Create(Komica_File_Url, 'Video'));
  23. fileText.appendChild(WebArchive_Create(Komica_File_Url, 'Video'));
  24. }
  25. else{
  26. // $(this).find('.fileText').first().append(WebArchive_Create(Komica_File_Url, 'Image'));
  27. fileText.appendChild(ArchiveIs_Create(Komica_File_Url, 'Image'));
  28. }
  29. }
  30.  
  31. })
  32.  
  33. reply_Class_Read();
  34. document.addEventListener('click', event => {
  35. if (event.target.matches('.-expand-thread')) {
  36. setTimeout(() => {
  37. reply_Class_Read();
  38. console.log('Done!');
  39. }, 1000);
  40. }
  41. });
  42.  
  43. function reply_Class_Read(){
  44. document.querySelectorAll('.reply').forEach(reply => {
  45. let fileThumb = reply.querySelector('.fileThumb');
  46. if (fileThumb && !reply.querySelector('form')) {
  47. let Komica_File_Url = 'https:' + fileThumb.getAttribute('href');
  48. let fileText = reply.querySelector('.fileText');
  49. if (fileThumb.getAttribute('href').includes('.webm') || fileThumb.getAttribute('href').includes('.mp4')) {
  50. fileThumb.appendChild(GhostArchive_Create(Komica_File_Url, 'Video'));
  51. fileThumb.appendChild(WebArchive_Create(Komica_File_Url, 'Video'));
  52. }
  53. else{
  54. // $(this).find('.fileText').append(WebArchive_Create(Komica_File_Url, 'Image'));
  55. fileText.appendChild(ArchiveIs_Create(Komica_File_Url, 'Image'));
  56. }
  57. }
  58. });
  59. }
  60. function WebArchive_Create(myUrl, myTarget){
  61. let form = document.createElement('form');
  62. form.setAttribute('name', 'wwmform_save');
  63. form.setAttribute('action', 'https://web.archive.org/save');
  64. form.setAttribute('method', 'POST');
  65. form.setAttribute('target', '_blank');
  66. form.style.display = 'inline-block';
  67.  
  68. let inputUrl = document.createElement('input');
  69. inputUrl.setAttribute('id', 'url');
  70. inputUrl.setAttribute('type', 'hidden');
  71. inputUrl.setAttribute('name', 'url');
  72. inputUrl.setAttribute('value', myUrl);
  73.  
  74. let inputSubmit = document.createElement('input');
  75. inputSubmit.setAttribute('type', 'submit');
  76. inputSubmit.setAttribute('value', 'Save ' + myTarget + ' to Web archive');
  77.  
  78. form.appendChild(inputUrl);
  79. form.appendChild(inputSubmit);
  80.  
  81. return form;
  82. }
  83.  
  84. function ArchiveIs_Create(myUrl, myTarget){
  85. let form = document.createElement('form');
  86. form.setAttribute('id', 'submiturl');
  87. form.setAttribute('action', 'https://archive.is/submit/');
  88. form.setAttribute('method', 'GET');
  89. form.setAttribute('target', '_blank');
  90. form.style.display = 'inline-block';
  91.  
  92. let inputUrl = document.createElement('input');
  93. inputUrl.setAttribute('id', 'url');
  94. inputUrl.setAttribute('type', 'hidden');
  95. inputUrl.setAttribute('name', 'url');
  96. inputUrl.setAttribute('value', myUrl);
  97.  
  98. let inputSubmit = document.createElement('input');
  99. inputSubmit.setAttribute('type', 'submit');
  100. inputSubmit.setAttribute('value', 'Save ' + myTarget + ' to archive.is');
  101. inputSubmit.setAttribute('tabindex', '1');
  102.  
  103. form.appendChild(inputUrl);
  104. form.appendChild(inputSubmit);
  105. return form;
  106. }
  107.  
  108. function GhostArchive_Create(myUrl, myTarget){
  109. let form = document.createElement('form');
  110. form.setAttribute('id', 'submiturl');
  111. form.setAttribute('action', 'https://ghostarchive.org/archive2');
  112. form.setAttribute('method', 'POST');
  113. form.setAttribute('target', '_blank');
  114. form.style.display = 'inline-block';
  115.  
  116. let inputUrl = document.createElement('input');
  117. inputUrl.setAttribute('id', 'url');
  118. inputUrl.setAttribute('type', 'hidden');
  119. inputUrl.setAttribute('name', 'archive');
  120. inputUrl.setAttribute('value', myUrl);
  121.  
  122. let inputSubmit = document.createElement('input');
  123. inputSubmit.setAttribute('type', 'submit');
  124. inputSubmit.setAttribute('value', 'Save ' + myTarget + ' to ghostarchive.org');
  125. inputSubmit.setAttribute('tabindex', '1');
  126.  
  127. form.appendChild(inputUrl);
  128. form.appendChild(inputSubmit);
  129. return form;
  130. }
  131.  
  132. })();