Skip to content

Instantly share code, notes, and snippets.

@dvygolov
Created February 2, 2024 14:32
Show Gist options
  • Save dvygolov/a041ae9285e95cc042bd3423953b3eb4 to your computer and use it in GitHub Desktop.
Save dvygolov/a041ae9285e95cc042bd3423953b3eb4 to your computer and use it in GitHub Desktop.
Script adds Download button to videos in Facebook Ads Library
//FOR CONSOLOE
setInterval(function (){
var videos = document.getElementsByTagName("video");
for (var i = 0; i < videos.length; i++) {
var video = videos[i];
if (video.parentNode.querySelector(".download-button")) {
continue;
}
var downloadButton = document.createElement("button");
downloadButton.innerHTML = "Скачать";
downloadButton.className = "download-button";
downloadButton.style.position = "absolute";
downloadButton.style.zIndex = "1";
downloadButton.addEventListener("click", function () {
var videoSrc = this.parentNode.querySelector("video").src;
fetch(videoSrc)
.then(function (response) {
return response.blob();
})
.then(function (blob) {
var link = document.createElement("a");
link.href = URL.createObjectURL(blob);
link.download = "video.mp4";
link.click();
})
.catch(function (error) {
console.log("Ошибка при скачивании видео:", error);
});
});
video.parentNode.insertBefore(downloadButton, video);
}
}, 400)
//FOR A BOOKMARK
javascript:(function() {
setInterval(function() {
var videos = document.getElementsByTagName("video");
for (var i = 0; i < videos.length; i++) {
var video = videos[i];
if (video.parentNode.querySelector(".download-button")) {
continue;
}
var downloadButton = document.createElement("button");
downloadButton.innerHTML = "Скачать";
downloadButton.className = "download-button";
downloadButton.style.position = "absolute";
downloadButton.style.zIndex = "1";
downloadButton.addEventListener("click", function() {
var videoSrc = this.parentNode.querySelector("video").src;
fetch(videoSrc)
.then(function(response) {
return response.blob();
})
.then(function(blob) {
var link = document.createElement("a");
link.href = URL.createObjectURL(blob);
link.download = "video.mp4";
link.click();
})
.catch(function(error) {
console.log("Ошибка при скачивании видео:", error);
});
});
video.parentNode.insertBefore(downloadButton, video);
}
}, 400);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment