Anonfiles, Upload.ee, MediaFire PDF Viewer

Adds a button to view PDF and TXT files without needing to download them.

  1. // ==UserScript==
  2. // @name Anonfiles, Upload.ee, MediaFire PDF Viewer
  3. // @namespace https://leaked.wiki
  4. // @version 1.1
  5. // @description Adds a button to view PDF and TXT files without needing to download them.
  6. // @author Sango
  7. // @match *://anonfiles.com/*
  8. // @match *://bayfiles.com/*
  9. // @match *://*.upload.ee/files/*
  10. // @match *://*.mediafire.com/file/*
  11. // @icon https://www.google.com/s2/favicons?sz=64&domain=anonfiles.com
  12. // @grant GM_xmlhttpRequest
  13. // @grant GM_addStyle
  14. // @connect upload.ee
  15. // @connect *
  16. // ==/UserScript==
  17.  
  18. (function () {
  19. 'use strict';
  20.  
  21. const ALWAYS_SHOW = false,
  22. PDF_HEIGHT = '100vh',
  23. TXT_ICON = 'https://i.imgur.com/Lt93sLj.png',
  24. PDF_ICON = 'https://i.imgur.com/IwbUR6B.png';
  25.  
  26.  
  27.  
  28. function createViewButton(directURL, fileType, host) {
  29. const iconUrl = fileType === 'TXT' ? TXT_ICON : PDF_ICON;
  30. const icon = `<img src="${iconUrl}" style="height: 30px; width: 30px;">`;
  31. const pdfBtn = document.createElement('a');
  32. pdfBtn.href = '#Sango';
  33. pdfBtn.id = 'show-pdf';
  34. pdfBtn.type = 'button';
  35. pdfBtn.className = 'btn btn-primary btn-block';
  36. pdfBtn.style.background = 'rgb(36, 84, 136)';
  37. pdfBtn.style.color = 'white';
  38. pdfBtn.style.padding = '5px';
  39. pdfBtn.style.borderRadius = '12px';
  40. pdfBtn.style.border = '1px solid #000000';
  41. pdfBtn.style.display = 'inline-flex';
  42. pdfBtn.style.justifyContent = 'space-evenly';
  43. pdfBtn.style.alignItems = 'center';
  44. pdfBtn.style.fontSize = '13px';
  45. pdfBtn.style.margin = '5px';
  46. pdfBtn.style.gap = '5px';
  47. pdfBtn.style.position = 'relative';
  48. pdfBtn.style.zIndex = '420';
  49. pdfBtn.innerHTML = `${icon} View as ${fileType}`;
  50.  
  51. pdfBtn.addEventListener('click', (e) => {
  52. e.preventDefault();
  53. handleFileView(directURL, fileType, host, pdfBtn);
  54. });
  55.  
  56. return pdfBtn;
  57. }
  58.  
  59. function handleFileView(directURL, fileType, host, btn) {
  60. const iconUrl = fileType === 'TXT' ? TXT_ICON : PDF_ICON;
  61. const icon = `<img src="${iconUrl}" style="height: 30px; width: 30px;">`;
  62. const existingFrame = document.getElementById('pdf-viewer');
  63. if (existingFrame) {
  64. existingFrame.remove();
  65. btn.innerHTML = `${icon} View as ${fileType}`;
  66. return;
  67. }
  68. const frame = document.createElement('iframe');
  69. frame.id = 'pdf-viewer';
  70. frame.style = `width: 100%; height: 100%; min-height: ${PDF_HEIGHT}; margin-bottom: 10px; border: 1px solid #245488;`;
  71. frame.src = '';
  72. btn.innerHTML = `${icon} Loading File...`;
  73.  
  74. // display file on sites that lock download link by ip
  75. if (host.includes('upload.ee')) {
  76. GM_xmlhttpRequest({
  77. method: 'GET',
  78. url: directURL,
  79. responseType: 'blob',
  80. onload: (response) => {
  81. const fileBlob = new Blob([response.response], { type: fileType === 'PDF' ? 'application/pdf' : 'text/plain' });
  82. const fileURL = URL.createObjectURL(fileBlob);
  83. frame.src = fileURL;
  84. frame.onload = () => { // scroll to iframe
  85. frame.scrollIntoView({ behavior: 'smooth', block: 'start' });
  86. btn.innerHTML = `${icon} Hide ${fileType}`;
  87. };
  88. },
  89. onerror: () => {
  90. alert('Failed to fetch the file. Please try again.');
  91. frame.remove();
  92. btn.innerHTML = `${icon} View as ${fileType}`;
  93. },
  94. });
  95. } else {
  96. frame.src = `https://docs.google.com/viewer?url=${encodeURIComponent(directURL)}&embedded=true`;
  97. frame.onload = () => { // scroll to iframe
  98. frame.scrollIntoView({ behavior: 'smooth', block: 'start' });
  99. btn.innerHTML = `${icon} Hide ${fileType}`;
  100. };
  101. }
  102. document.body.appendChild(frame);
  103. }
  104.  
  105. const currentHost = window.location.hostname;
  106. let downloadUrl, container;
  107. if (currentHost.includes('anonfiles.com') || currentHost.includes('bayfiles.com')) {
  108. downloadUrl = document.getElementById('download-url');
  109. container = downloadUrl;
  110. } else if (currentHost.includes('upload.ee')) {
  111. downloadUrl = document.getElementById('d_l');
  112. container = downloadUrl;
  113. } else if (currentHost.includes('mediafire.com')) {
  114. downloadUrl = document.getElementById('downloadButton');
  115. container = document.querySelector('form[name="download"]');
  116. }
  117.  
  118. if (downloadUrl) {
  119. const fileType = downloadUrl.href.split('.').pop().toUpperCase();
  120. if (['PDF', 'TXT'].includes(fileType)) {
  121. const button = createViewButton(downloadUrl.href, fileType, currentHost);
  122. container.insertAdjacentElement('afterend', button);
  123.  
  124. if (ALWAYS_SHOW) {
  125. // Automatically show the file
  126. handleFileView(downloadUrl.href, fileType, currentHost, button);
  127. }
  128. }
  129. }
  130. })();