להורדת אלבום, יש לפתוח את דף האלבום, ולהדביק את הקוד המצורף בקונסולה.
הקוד המינימלי מיועד ליצירת סימניית הורדה ב'כרום'.
| (async function download_all_songs() { | |
| console.log("Musicode7"); | |
| console.log("https://gist.github.com/MusiCode1/c50432ad3f413a958e6f3aea7c214cfc"); | |
| const audio_list = document.querySelectorAll("audio > source"); | |
| check(); | |
| add_html(); | |
| const albom_title = document.querySelector(".album-title").innerText, | |
| albom_art = document.querySelector(".arts_name").innerText; | |
| const file_name = `${albom_title} - ${albom_art}`; | |
| await my_require('https://cdnjs.cloudflare.com/ajax/libs/jszip/3.6.0/jszip.min.js'); | |
| var zip = new window.JSZip(); | |
| for (const source of audio_list) { | |
| await download(source.src) | |
| } | |
| my_console_log("save zip file..."); | |
| await save_zip_file(); | |
| document.querySelector(".back-modal").remove(); | |
| function check() { | |
| if (window.location.hostname != "jewishmusic.fm") { | |
| throw new Error("זה איננו " + "jewishmusic.fm!"); | |
| } | |
| if(audio_list.length < 1) { | |
| throw new Error("אין בדף זה קבצי מוזיקה!"); | |
| } | |
| } | |
| async function save_zip_file() { | |
| const zipFile = await zip.generateAsync({ type: "blob" }); | |
| save_blob_file(zipFile, file_name); | |
| } | |
| async function download(url) { | |
| url = url.replace("http://", "https://"); | |
| const file_name = url.split("/").pop(); | |
| my_console_log(`download file ${file_name}...`); | |
| const promise = download_file(url) | |
| .then(blob => { | |
| my_console_log(`add to zip file ${file_name}...`); | |
| zip.file(file_name, blob, { binary: true }); | |
| }); | |
| await promise; | |
| } | |
| function download_file(url, reply = 0) { | |
| let res; | |
| const promise = new Promise(async (resolve, reason) => { | |
| const file_name = url.split("/").pop(); | |
| res = fetch(url, { | |
| headers: { | |
| "Range": "bytes=0-" | |
| } | |
| }); | |
| const response = await res; | |
| if (response.status < 200 || response.status >= 400) { | |
| if (reply < 5) { | |
| reply++; | |
| my_console_log("!!!"); | |
| await new Promise(resolve => setTimeout(resolve, 1000)); | |
| resolve(download_file(url, reply)) | |
| } else { | |
| reason(); | |
| throw response; | |
| } | |
| } | |
| const reader = response.body.getReader(); | |
| const contentLength = response.headers.get('Content-Length'); | |
| let receivedLength = 0; | |
| const stream = new Response( | |
| new ReadableStream({ | |
| async start(controller) { | |
| const interval = setInterval(() => { | |
| my_console_log(`Received ${file_name} ${bytesToSize(receivedLength)} of ${bytesToSize(contentLength)}`); | |
| }, 1000); | |
| while (true) { | |
| const { done, value } = await reader.read(); | |
| if (done) { | |
| clearInterval(interval); | |
| break; | |
| } | |
| receivedLength += value.length; | |
| controller.enqueue(value); | |
| } | |
| controller.close(); | |
| } | |
| }) | |
| ); | |
| const blob = await stream.blob(); | |
| resolve(blob); | |
| }); | |
| promise.res = res; | |
| return promise; | |
| function bytesToSize(bytes) { | |
| var sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB']; | |
| if (bytes == 0) return '0 Byte'; | |
| var i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024))); | |
| return Math.round(bytes / Math.pow(1024, i), 2) + ' ' + sizes[i]; | |
| } | |
| } | |
| async function my_require(url) { | |
| const script = document.createElement('script'); | |
| script.type = 'text/javascript'; | |
| script.src = url; | |
| document.head.appendChild(script); | |
| my_console_log(`import ${url} ...`); | |
| await new Promise((resolve) => script.onload = resolve); | |
| } | |
| async function save_blob_file(blob, file_name) { | |
| var url = URL.createObjectURL(blob); | |
| var a = document.createElement('a'); | |
| a.href = url; | |
| a.download = file_name || "download"; | |
| document.body.appendChild(a); | |
| a.click(); | |
| a.remove(); | |
| } | |
| function add_html() { | |
| const div = document.createElement("div"); | |
| const style = document.createElement("style"); | |
| div.classList.add("back-modal"); | |
| style.nodeType = "text/css"; | |
| div.innerHTML = `<div class="modal"></div>`; | |
| style.innerHTML = ` | |
| .back-modal { | |
| position: fixed; | |
| z-index: 50; | |
| width: 100%; | |
| height: 100%; | |
| overflow: auto; | |
| left: 0; | |
| top: 0; | |
| padding-top: 4em; | |
| } | |
| .modal { | |
| margin: auto; | |
| background-color: black; | |
| width: 50vw; | |
| height: 50vh; | |
| box-shadow: 0px 0px 14px 5px rgb(0 0 0 / 85%); | |
| padding: 2vh; | |
| overflow-y: scroll; | |
| overflow-x: overlay; | |
| color: #5c5cec; | |
| direction: ltr; | |
| font-size: medium; | |
| } | |
| `; | |
| document.body.appendChild(style); | |
| document.body.appendChild(div); | |
| } | |
| function my_console_log(txt) { | |
| const modal = document.querySelector(".modal"); | |
| modal.innerText += txt + "\n"; | |
| modal.scrollTo({ | |
| top: modal.scrollHeight, | |
| behavior: "smooth" | |
| }); | |
| } | |
| })().catch(error => alert(error)); | |
| javascript:(async function download_all_songs(){console.log("Musicode7");console.log("https://gist.github.com/MusiCode1/c50432ad3f413a958e6f3aea7c214cfc");const audio_list=document.querySelectorAll("audio>source");check();add_html();const albom_title=document.querySelector(".album-title").innerText,albom_art=document.querySelector(".arts_name").innerText;const file_name=`${albom_title} - ${albom_art}`;await my_require('https://cdnjs.cloudflare.com/ajax/libs/jszip/3.6.0/jszip.min.js');var zip=new window.JSZip();for(const source of audio_list){await download(source.src)}my_console_log("save zip file...");await save_zip_file();document.querySelector(".back-modal").remove();function check(){if(window.location.hostname !="jewishmusic.fm"){throw new Error("זה איננו "+"jewishmusic.fm!");}if(audio_list.length<1){throw new Error("אין בדף זה קבצי מוזיקה!");}}async function save_zip_file(){const zipFile=await zip.generateAsync({ type:"blob" });save_blob_file(zipFile,file_name);}async function download(url){url=url.replace("http://","https://");const file_name=url.split("/").pop();my_console_log(`download file ${file_name}...`);const promise=download_file(url).then(blob=>{my_console_log(`add to zip file ${file_name}...`);zip.file(file_name,blob,{ binary:true });});await promise;}function download_file(url,reply=0){let res;const promise=new Promise(async(resolve,reason)=>{const file_name=url.split("/").pop();res=fetch(url,{headers:{"Range":"bytes=0-"}});const response=await res;if(response.status<200||response.status>=400){if(reply<5){reply++;my_console_log("!!!");await new Promise(resolve=>setTimeout(resolve,1000));resolve(download_file(url,reply))} else {reason();throw response;}}const reader=response.body.getReader();const contentLength=response.headers.get('Content-Length');let receivedLength=0;const stream=new Response(new ReadableStream({async start(controller){const interval=setInterval(()=>{my_console_log(`Received ${file_name} ${bytesToSize(receivedLength)} of ${bytesToSize(contentLength)}`);},1000);while(true){const { done,value }=await reader.read();if(done){clearInterval(interval);break;}receivedLength+=value.length;controller.enqueue(value);}controller.close();}}));const blob=await stream.blob();resolve(blob);});promise.res=res;return promise;function bytesToSize(bytes){var sizes=['Bytes','KB','MB','GB','TB'];if(bytes==0)return '0 Byte';var i=parseInt(Math.floor(Math.log(bytes)/Math.log(1024)));return Math.round(bytes/Math.pow(1024,i),2)+' '+sizes[i];}}async function my_require(url){const script=document.createElement('script');script.type='text/javascript';script.src=url;document.head.appendChild(script);my_console_log(`import ${url} ...`);await new Promise((resolve)=>script.onload=resolve);}async function save_blob_file(blob,file_name){var url=URL.createObjectURL(blob);var a=document.createElement('a');a.href=url;a.download=file_name||"download";document.body.appendChild(a);a.click();a.remove();}function add_html(){const div=document.createElement("div");const style=document.createElement("style");div.classList.add("back-modal");style.nodeType="text/css";div.innerHTML=`<div class="modal"></div>`;style.innerHTML=`.back-modal {position:fixed;z-index:50;width:100%;height:100%;overflow:auto;left:0;top:0;padding-top:4em;}.modal {margin:auto;background-color:black;width:50vw;height:50vh;box-shadow:0px 0px 14px 5px rgb(0 0 0/85%);padding:2vh;overflow-y:scroll;overflow-x:overlay;color:#5c5cec;direction:ltr;font-size:medium;}`;document.body.appendChild(style);document.body.appendChild(div);}function my_console_log(txt){const modal=document.querySelector(".modal");modal.innerText+=txt+"\n";modal.scrollTo({top:modal.scrollHeight,behavior:"smooth"});}})().catch(error=>alert(error)); |