Skip to content

Instantly share code, notes, and snippets.

@Albatrosicks
Last active June 6, 2023 17:39
Show Gist options
  • Save Albatrosicks/532d31558c7d6f628a7c30cd9d0aaa6e to your computer and use it in GitHub Desktop.
Save Albatrosicks/532d31558c7d6f628a7c30cd9d0aaa6e to your computer and use it in GitHub Desktop.
Copy download link of the entire folder as a ZIP archive to clipboard.
// ==UserScript==
// @name Mail.ru Cloud Zip Downloader
// @namespace http://tampermonkey.net/
// @version 0.2
// @description Copy download link of the entire folder as a ZIP archive to clipboard. By Ctrl+Shift+S
// @updateURL https://gist.github.com/Albatrosicks/532d31558c7d6f628a7c30cd9d0aaa6e/raw/MailruCloudZipDownloader-user.js
// @match https://cloud.mail.ru/public/*
// @grant GM_xmlhttpRequest
// ==/UserScript==
(function() {
'use strict';
function showSuccessModal(downloadLink) {
const modal = document.createElement("div");
modal.style.position = "fixed";
modal.style.top = "50%";
modal.style.left = "50%";
modal.style.transform = "translate(-50%, -50%)";
modal.style.backgroundColor = "#333";
modal.style.color = "#fff";
modal.style.padding = "20px";
modal.style.borderRadius = "5px";
modal.style.zIndex= 999;
const successMessage =
`Success! Copied Link: <br/>${downloadLink}`;
const closeBtn=document.createElement("button");
closeBtn.innerHTML="Close";
closeBtn.onclick=function(){
this.parentNode.remove();
};
modal.innerHTML=`<div>${successMessage}<br/><br/></div>`;
modal.appendChild(closeBtn);
document.body.appendChild(modal);
setTimeout(() => {
if (modal) {
document.body.removeChild(modal);
};
}, 4500);
}
const urlMatch = window.location.href.match(/https:\/\/cloud\.mail\.ru\/public\/([A-Za-z0-9]+\/[A-Za-z0-9]+)/);
const breadcrumbElement = document.evaluate('//*[@id="react-breadcrumbs"]/div/div/div[1]/div[1]/div/div/div/div', document, null,
XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
const name = breadcrumbElement ? breadcrumbElement.textContent.trim() : "archive";
if (!urlMatch) {
console.warn("Mail.ru Cloud URL doesn't match expected pattern.");
} else {
const folderId = urlMatch[1];
GM_xmlhttpRequest({
method: "POST",
url: "https://cloud.mail.ru/api/v3/zip/weblink",
data: JSON.stringify({
"x-email": "anonym",
"weblink_list": [folderId],
"name": name
}),
headers: {
"Content-Type": "application/json;charset=UTF-8"
},
onload: function(response) {
const downloadLink = JSON.parse(response.responseText).key;
document.documentElement.addEventListener('keydown', function(event) {
if (event.ctrlKey && event.shiftKey && event.key === 'S') {
event.preventDefault();
navigator.clipboard.writeText(downloadLink).then(function() {
console.log("Download link copied to clipboard.");
showSuccessModal(downloadLink);
}, function() {
console.warn("Failed to copy download link to clipboard.");
});
}
});
}
});
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment