Injects Scribd Material Downloader buttons into Scribd pages to view, download TXT, or download PDF safely.
Size
5.3 KB
Version
1.2
Created
Nov 18, 2025
Updated
25 days ago
1// ==UserScript==
2// @name Scribd Material Downloader (Safe PDF)
3// @namespace Violentmonkey Scripts
4// @version 1.2
5// @description Injects Scribd Material Downloader buttons into Scribd pages to view, download TXT, or download PDF safely.
6// @author Angesom12
7// @license MIT
8// @match *://www.scribd.com/*
9// @grant none
10// @run-at document-idle
11// @downloadURL https://update.greasyfork.org/scripts/550292/Scribd%20Material%20Downloader%20%28Safe%20PDF%29.user.js
12// @updateURL https://update.greasyfork.org/scripts/550292/Scribd%20Material%20Downloader%20%28Safe%20PDF%29.meta.js
13// ==/UserScript==
14
15(function() {
16 'use strict';
17
18 // Load jsPDF dynamically from GitHub
19 const jsPDFScript = document.createElement('script');
20 jsPDFScript.src = 'https://raw.githubusercontent.com/Angesom12/scribd-downloader-assets/main/js/jspdf.umd.min.js';
21 jsPDFScript.onload = () => initDownloader();
22 document.head.appendChild(jsPDFScript);
23
24 function initDownloader() {
25 const { jsPDF } = window.jspdf;
26
27 // --- Create Button Container ---
28 const container = document.createElement('div');
29 container.className = 'button-container';
30 container.style.position = 'fixed';
31 container.style.top = '50%';
32 container.style.right = '40px';
33 container.style.transform = 'translateY(-50%)';
34 container.style.display = 'flex';
35 container.style.flexDirection = 'column';
36 container.style.gap = '18px';
37 container.style.zIndex = '100000';
38
39 // --- Button Styles ---
40 const style = document.createElement('style');
41 style.textContent = `
42 .dl-btn {
43 padding: 14px 24px;
44 font-size: 16px;
45 font-weight: bold;
46 border: none;
47 border-radius: 10px;
48 cursor: pointer;
49 color: #fff;
50 box-shadow: 0 3px 6px rgba(0,0,0,0.25);
51 transition: transform 0.2s, opacity 0.2s;
52 }
53 .dl-btn:hover {
54 transform: scale(1.1);
55 opacity: 0.9;
56 }
57 .btn-view { background-color: #27ae60; }
58 .btn-txt { background-color: #f39c12; }
59 .btn-pdf { background-color: #8e44ad; }
60 `;
61 document.head.appendChild(style);
62
63 // --- Create Buttons ---
64 const btnView = document.createElement('button');
65 btnView.className = 'dl-btn btn-view';
66 btnView.textContent = 'View Full';
67
68 const btnTXT = document.createElement('button');
69 btnTXT.className = 'dl-btn btn-txt';
70 btnTXT.textContent = 'Download (TXT)';
71
72 const btnPDF = document.createElement('button');
73 btnPDF.className = 'dl-btn btn-pdf';
74 btnPDF.textContent = 'Download (PDF)';
75
76 container.appendChild(btnView);
77 container.appendChild(btnTXT);
78 container.appendChild(btnPDF);
79 document.body.appendChild(container);
80
81 // --- Button Functions ---
82 function redirectToEmbed() {
83 const currentUrl = window.location.href;
84 const regex = /https:\/\/www\.scribd\.com\/[^/]+\/([^/]+)\/[^/]+/;
85 const match = currentUrl.match(regex);
86
87 if (match) {
88 const newUrl = `https://www.scribd.com/embeds/${match[1]}/content`;
89 window.location.href = newUrl;
90 } else {
91 alert("Unable to open embed view. Please refresh the page.");
92 }
93 }
94
95 function downloadTXT() {
96 const contentElements = document.querySelectorAll('.text_layer .a');
97 let content = '';
98 contentElements.forEach(el => content += el.textContent + '\n');
99
100 if (!content.trim()) {
101 alert("No content found. Try opening the Scribd embed view first.");
102 return;
103 }
104
105 const blob = new Blob([content], { type: 'text/plain' });
106 const url = URL.createObjectURL(blob);
107 const a = document.createElement('a');
108 a.href = url;
109 a.download = 'scribd_material.txt';
110 document.body.appendChild(a);
111 a.click();
112 document.body.removeChild(a);
113 URL.revokeObjectURL(url);
114 }
115
116 function downloadPDF() {
117 const contentElements = document.querySelectorAll('.text_layer .a');
118 let content = '';
119 contentElements.forEach(el => content += el.textContent + '\n');
120
121 if (!content.trim()) {
122 alert("No content found. Try opening the Scribd embed view first.");
123 return;
124 }
125
126 const doc = new jsPDF();
127 const lines = content.split('\n');
128 let y = 10;
129
130 lines.forEach(line => {
131 if (y > 280) { // page limit
132 doc.addPage();
133 y = 10;
134 }
135 doc.text(line, 10, y);
136 y += 7; // line height
137 });
138
139 doc.save('scribd_material.pdf');
140 }
141
142 // --- Bind Buttons ---
143 btnView.addEventListener('click', redirectToEmbed);
144 btnTXT.addEventListener('click', downloadTXT);
145 btnPDF.addEventListener('click', downloadPDF);
146 }
147
148})();
149