Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name Download mp3 vk.com
- // @include https://vk.com/*
- // @include http://vk.com/*
- // @grant GM_xmlhttpRequest
- // ==/UserScript==
- var parseExt=S=>(S=/^[^?]+([.]\w+)[?]/.exec(S))? S[1]: '.mp3',
- Save = (Url, Name, isOK)=>{
- if(!Url || !Name || !isOK) return;
- var A;
- (A = document.createElement('A')).href = Url;
- A.download = Name.replace(/[^а-я\x21-\x7e\s\w]/gi,"-").replace(/[\/\\\:\*\?"<>\|\&]+/g, "-");
- document.body.appendChild(A).click(); document.body.removeChild(A);
- },
- GetFromServer = (link, name)=>GM_xmlhttpRequest({
- method: "GET",
- responseType: 'blob',
- overrideMimeType: 'text/plain; charset=x-user-defined',
- url: link,
- onload: R=>Save(window.URL.createObjectURL(R.response), name, R.status==200)
- });
- window.addEventListener('contextmenu', e=>{
- if (!e.ctrlKey) return; e.preventDefault();
- var link, info, a = e.target;
- while (!a.classList.contains('audio') && (a=a.parentNode)) if(a==document.body) return;
- link = a.querySelector('[id^="audio_info"]').value;
- info = a.getElementsByClassName('title_wrap')[0];
- GetFromServer(link, info.textContent.trim() + parseExt(link));
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement