Last active
June 30, 2022 09:34
-
-
Save outring/eff0d1c2925a51413eb7c4091bdf4a41 to your computer and use it in GitHub Desktop.
VK video links extractor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function() { | |
function setStyle(node, style) { | |
Object.keys(style).forEach(function(key) { | |
node.style[key] = style[key]; | |
}); | |
} | |
if (location.host !== "m.vk.com") { | |
alert("Для начала надо зайти на m.vk.com, например."); | |
return; | |
} | |
var errorHeading = "Что-то пошло не так."; | |
var windowId = "linksBookmarklet"; | |
var windowStyle = { | |
position: "absolute", | |
top: "100px", | |
left: 0, | |
right: 0, | |
width: "175px", | |
margin: "auto", | |
padding: "10px 20px", | |
backgroundColor: "#666666", | |
borderRadius: "15px" | |
}; | |
var rowStyle = { | |
margin: "5px 0" | |
}; | |
var linkStyle = { | |
color: "#ffffff" | |
}; | |
var crossStyle = { | |
position: "absolute", | |
top: 0, | |
right: "2px", | |
width: "30px", | |
height: "30px", | |
textAlign: "center", | |
lineHeight: "30px", | |
color: "#ffffff" | |
}; | |
var qualities = [240, 360, 480, 720, 1080]; | |
var sourceRegExp = /^(.*\.)(\d+)(\.mp4.*)$/; | |
var playerNode = document.querySelector(".vv_inline_video"); | |
if (!playerNode) { | |
alert("Надо зайти на страницу с видео и тогда всё получится."); | |
return; | |
} | |
function close() { | |
var oldWindowNode = document.getElementById(windowId); | |
if (oldWindowNode) { | |
oldWindowNode.parentNode.removeChild(oldWindowNode); | |
} | |
} | |
var sourceNode = playerNode.getElementsByTagName("source")[0]; | |
var source = sourceNode.src; | |
var sources = qualities.map(function(q) { | |
return { | |
src: source.replace(sourceRegExp, "$1" + q + "$3"), | |
quality: q | |
}; | |
}); | |
var windowNode = document.createElement("div"); | |
windowNode.id = windowId; | |
setStyle(windowNode, windowStyle); | |
var crossNode = document.createElement("div"); | |
crossNode.textContent = "×"; | |
crossNode.addEventListener("click", close); | |
setStyle(crossNode, crossStyle); | |
windowNode.appendChild(crossNode); | |
sources.forEach(function(source) { | |
var rowNode = document.createElement("div"); | |
setStyle(rowNode, rowStyle); | |
var linkNode = document.createElement("a"); | |
setStyle(linkNode, linkStyle); | |
linkNode.href = source.src; | |
linkNode.textContent = source.quality; | |
rowNode.appendChild(linkNode); | |
windowNode.appendChild(rowNode); | |
}); | |
document.body.appendChild(windowNode); | |
})(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
javascript:(function(){function a(a,b){Object.keys(b).forEach(function(c){a.style[c]=b[c]})}function k(){var a=document.getElementById(c);a&&a.parentNode.removeChild(a)}if("m.vk.com"!==location.host)return void alert("Для начала надо зайти на m.vk.com, например.");var c="linksBookmarklet",d={position:"absolute",top:"100px",left:0,right:0,width:"175px",margin:"auto",padding:"10px 20px",backgroundColor:"#666666",borderRadius:"15px"},e={margin:"5px 0"},f={color:"#ffffff"},g={position:"absolute",top:0,right:"2px",width:"30px",height:"30px",textAlign:"center",lineHeight:"30px",color:"#ffffff"},h=[240,360,480,720,1080],i=/^(.*\.)(\d+)(\.mp4.*)$/,j=document.querySelector(".vv_inline_video");if(!j)return void alert("Надо зайти на страницу с видео и тогда всё получится.");var l=j.getElementsByTagName("source")[0],m=l.src,n=h.map(function(a){return{src:m.replace(i,"$1"+a+"$3"),quality:a}}),o=document.createElement("div");o.id=c,a(o,d);var p=document.createElement("div");p.textContent="×",p.addEventListener("click",k),a(p,g),o.appendChild(p),n.forEach(function(b){var c=document.createElement("div");a(c,e);var d=document.createElement("a");a(d,f),d.href=b.src,d.textContent=b.quality,c.appendChild(d),o.appendChild(c)}),document.body.appendChild(o)})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@2080