Skip to content

Instantly share code, notes, and snippets.

@jemsgit
Created December 31, 2022 08:52
Show Gist options
  • Save jemsgit/0d5c933b434a0a888fa1c5108f7876b7 to your computer and use it in GitHub Desktop.
Save jemsgit/0d5c933b434a0a888fa1c5108f7876b7 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name eductiveGrubPath
// @description Grub educative course
// @author Jem Jem
// @license MIT
// @version 1.0
// @include https://www.educative.io/path/*
// ==/UserScript==
(async function (window, undefined) { // [2] нормализуем window
function getModuleLinks() {
const moduleBlocks = document.querySelectorAll(".major-second div.flex.flex-col.w-full .h-full .border-transparent");
for(let i = 0; i < moduleBlocks.length; i++) {
if(!moduleBlocks[i].querySelector(".overflow-y-scroll")){
let collapse = moduleBlocks[i].querySelector("div.cursor-pointer");
if(collapse) {
collapse.click();
}
}
}
const links = document.querySelectorAll(".major-second .items-center .overflow-y-scroll.lg\\:hidden a:first-child");
let result = [];
for(let i = 0; i < links.length; i++) {
let link = links[i].getAttribute('href');
result.push(`https://www.educative.io${link}`);
}
return result;
}
function sleep(seconds) {
return new Promise((res, rej) => {
setTimeout(res, seconds * 1000);
})
}
function saveDelimetrFile(data) {
const fileName = 'Next Module.txt';
let blob = new Blob([data],{ type: "text/plain;charset=utf-8" });
let a = document.createElement("a");
let url = window.URL.createObjectURL(blob);
a.style = "display: none";
a.href = url;
a.download = fileName;
document.body.appendChild(a);
a.click();
}
async function grub() {
let links = localStorage.getItem('modules-links');
let hasFinished = localStorage.getItem('modules-saved');
if(hasFinished === 'true') {
return;
}
if(!links) {
links = getModuleLinks();
} else {
links = JSON.parse(links);
}
const nextLink = links[0];
localStorage.setItem('modules-links', JSON.stringify(links.slice(1)));
saveDelimetrFile('123')
window.location = nextLink;
}
await sleep(20);
await grub();
})(window);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment