stuhack icon indicating copy to clipboard operation
stuhack copied to clipboard

Not working

Open conallfowler opened this issue 1 year ago • 6 comments

Hi, The extension doesn't appear to be working any more? Studocu is asking to login/pay for premium, and not allowing downloads? (And sometimes, the page breaks entirely)

Tried on multiple devices, latest version, etc.

conallfowler avatar Jan 13 '24 18:01 conallfowler

same issue, it loads few pages of any document but missing a lot of parts.

darren89d avatar Jan 14 '24 17:01 darren89d

@darren89d, @conallfowler Replace the code in doc-viewer.js with this. The issue is, that the content is loaded as you scroll through. This way, it only fetches the first 10 pages. The added functionality scrolls through all the way to the bottom and then opens the print view; this way, all the content can be fetched. Additionally, the print view showed the premium overlay. It would disappear when you hit print, but this way, it is also hidden in the preview.


function downloadDoc()
{
	var head = document.getElementsByTagName("head")[0].innerHTML;
	var tit = document.getElementsByTagName("h1")[0].innerHTML;
	var pages = document.getElementById('page-container').childNodes;

	width = pages[0].offsetWidth;
	height = pages[0].offsetHeight;

	if (width > height) print_opt = "{@page {size: A5 landscape;} body {zoom: 90%;}";
	else print_opt = "{@page {size: A5 portrait;}";

	for(i=0; i<pages.length; i++)
	{
		var elm_id = pages[i].getAttribute('id')

		if (elm_id != null && elm_id.includes('pf')) pages[i].childNodes[0].style = "display: block;";
	}

	var pdf = pages[0].parentNode.parentNode.parentNode.innerHTML;

	newWindow = window.open("", "Document", "height=865,width=625,status=yes,toolbar=no,menubar=no");  
	newWindow.document.getElementsByTagName("head")[0].innerHTML = head + "<style> .nofilter{filter: none !important;} </style>" + "<style> @media print " + print_opt + "</style>";
	newWindow.document.title = tit;
	newWindow.document.getElementsByTagName("body")[0].innerHTML = pdf;
	newWindow.document.getElementsByTagName("body")[0].childNodes[0].style = "";

	//remove premium overlay in the preview
	addStyleToNewWindow(newWindow, '._3c5189f13e56 { display: none !important; }');
}

function addButtons() {
	button1 = document.createElement("button");
	button1.classList.add("download-button-1");
	button1.innerHTML = '<svg aria-hidden="true" focusable="false" data-prefix="fas" class="svg-inline--fa" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 640 512"><path fill="currentColor" d="M537.6 226.6c4.1-10.7 6.4-22.4 6.4-34.6 0-53-43-96-96-96-19.7 0-38.1 6-53.3 16.2C367 64.2 315.3 32 256 32c-88.4 0-160 71.6-160 160 0 2.7.1 5.4.2 8.1C40.2 219.8 0 273.2 0 336c0 79.5 64.5 144 144 144h368c70.7 0 128-57.3 128-128 0-61.9-44-113.6-102.4-125.4zm-132.9 88.7L299.3 420.7c-6.2 6.2-16.4 6.2-22.6 0L171.3 315.3c-10.1-10.1-2.9-27.3 11.3-27.3H248V176c0-8.8 7.2-16 16-16h48c8.8 0 16 7.2 16 16v112h65.4c14.2 0 21.4 17.2 11.3 27.3z"></path></svg><span class="download-text">Download</span>';

	let prev_buttons = document.getElementsByClassName("fa-cloud-arrow-down");
	let i = 0;
	buttons = [];
	while (prev_buttons.length > 0) 
	{
		if (prev_buttons[0].parentNode.parentNode.firstChild.classList.contains("download-button-1")) 
		{
			prev_buttons[0].parentNode.remove();
		} 
		else 
		{
			buttons.push(button1.cloneNode(true, true));
			buttons[i].onclick = function () { downloadDoc() };
			prev_buttons[0].parentNode.parentNode.prepend(buttons[i]);
			prev_buttons[0].parentNode.remove();
			i++;
		}
	}
}

var observer = new MutationObserver(function(mutations) {
	mutations.forEach(function(mutation) {
		addButtons();
	});
});

window.addEventListener('load', function()
{
	const prev_buttons = document.getElementsByClassName("fa-cloud-arrow-down");
	if(prev_buttons.length > 0) 
	{
		try{
			addButtons();
		}catch(err){
			console.log(err);
		}finally{
			let element = document.getElementById("viewer-wrapper");
			observer.observe(element, { attributes: true, childList: true, subtree: true});
		}
	}

	fetchAllContent();
});

function addStyleToNewWindow(newWin, cssRule) 
{
    var style = newWin.document.createElement('style');
    style.type = 'text/css';
    style.appendChild(newWin.document.createTextNode(cssRule));
    newWin.document.head.appendChild(style);
}

function fetchAllContent() 
{
    var wrapper = document.getElementById('document-wrapper');
    var height = wrapper.scrollHeight;
    var currentPosition = 0;
    var step = 10000; // step size to controll how much it should scroll down at a time 
	var overlay = createOverlay();

    function createOverlay() 
	{
        var overlayDiv = document.createElement('div');
        overlayDiv.style.position = 'fixed';
        overlayDiv.style.top = '0';
        overlayDiv.style.left = '0';
        overlayDiv.style.width = '100%';
        overlayDiv.style.height = '100%';
        overlayDiv.style.backgroundColor = 'white';
        overlayDiv.style.display = 'flex';
        overlayDiv.style.justifyContent = 'center';
        overlayDiv.style.alignItems = 'center';
        overlayDiv.style.borderRadius = '15px';
        overlayDiv.style.zIndex = '1000';
        overlayDiv.innerText = 'Please wait! The content is being loaded.';
		overlayDiv.style.fontSize = '30px';
        document.body.appendChild(overlayDiv);
        return overlayDiv;
    }

    function hideOverlay() 
	{
        overlay.style.display = 'none';
    }

    function scrollStep() 
	{
        if (currentPosition < height) 
		{
            wrapper.scrollTo(0, currentPosition);
            currentPosition += step;
            setTimeout(scrollStep, 50); // time needed to scroll through the step size
        } 
		else 
		{
            hideOverlay();

			// wait at the bottom to ensure everything has been loaded
            setTimeout(() => wrapper.scrollTo(0, 0), 50);
        }
    }

    scrollStep();
}

// Remove the premium overlay from the original document preview
function removeOverlayWhenLoaded() 
{
    const observer = new MutationObserver(mutations => {
        for (const mutation of mutations) {
            if (mutation.addedNodes.length) {
                for (const node of mutation.addedNodes) {
                    if (node.id === 'modal-overlay') {
                        node.style.display = 'none';
                        observer.disconnect();
                        return; // Exit the function once the overlay is found and removed
                    }
                }
            }
        }
    });

    observer.observe(document.body, { childList: true, subtree: true });
}

removeOverlayWhenLoaded();


chrisfeldkircher avatar Jan 15 '24 11:01 chrisfeldkircher

https://github.com/danieltyukov/studocuhack checkout the most latest version of a better extension to solve this problem.

danieltyukov avatar Feb 09 '24 21:02 danieltyukov

Hi, the banner problem is solved, but not for the blurred pages on Studocu. Usually the blurred pages are from the third and multiples. I downloaded the lastest version of StuHack.

StuUser avatar Feb 28 '24 14:02 StuUser

@danieltyukov Thanks alot, I can confirm this works for me!

JoelJ-500 avatar Mar 06 '24 15:03 JoelJ-500

Hi, I found a bug, the pages that were previously blurry are no longer blurry, but instead of the page that should be there there is the previous page, for example if page 3 is blurry, by clicking on download page 3 is not blurry because in its place is page 2, which is thus repeated twice, thus for all the pages that should be unblurred. Another question, when you update to the latest version I just need to download the latest version which is called stuhack-master and that's it right? Thanks for your time!

StuUser avatar Mar 19 '24 09:03 StuUser