Last active
January 10, 2017 20:40
-
-
Save kissarat/8817386 to your computer and use it in GitHub Desktop.
Для ex.ua получает ссылки на видео со страницы. Ищет видеофайлы с расшырением mkv, avi, mp4, ts
This file contains 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
//Tested in Chromium 39, Firefox 34 on Linux Mint 17.1 | |
(function() { | |
//Regex filter for filenames. Filename can contain whitespaces in the end | |
var filter = /\.(mkv|avi|mp4|ts)\s*$/; | |
var requestFileSystem = window.requestFileSystem || window.webkitRequestFileSystem; | |
//{ link: name } dictionary of video links found on page | |
var list = {}; | |
var links = document.querySelectorAll('table a[title][rel=nofollow]'); | |
//Stores list of links after user selection | |
var result; | |
for(var i = 0; i < links.length; i++) { | |
var t = links[i].innerHTML; | |
if (t.match(filter)) | |
list[links[i].href] = links[i].innerHTML; | |
} | |
//Create window with selected links | |
function open_in_window(e) { | |
if (e) console.log(e); | |
result = result.join('\n'); | |
var output_window = open('data:text/plain;base64,' + btoa(result)); | |
if (!output_window) | |
alert(result); | |
} | |
function download_links() { | |
//Collect selected links | |
var links = this.document.querySelectorAll('input[type=checkbox]:checked'); | |
result = []; | |
for(var i=0; i<links.length; i++) | |
result.push(links.item(i).getAttribute('value')); | |
if (requestFileSystem) | |
//Write selected links list to file. This works only for webkit | |
requestFileSystem(TEMPORARY, 1024*16, function(fs) { | |
fs.root.getFile('list.txt', {create:true}, function(f) { | |
f.createWriter(function(w) { | |
w.truncate(0); | |
w.onwriteend = function() { | |
f.createWriter(function(w) { | |
w.onwriteend = function() { | |
open(f.toURL()); | |
}; | |
var blob = new Blob([result.join('\n')], {type : 'text/pain'}); | |
w.write(blob); | |
}); | |
}; | |
w.onerror = open_in_window; | |
}) | |
}, open_in_window); | |
}, open_in_window); | |
else | |
open_in_window(); | |
this.close(); | |
} | |
//Sends statistics of this script usage | |
//You may remove this code | |
if (!document.getElementById('zenothing_statistics')) { | |
var statistics = document.createElement('script'); | |
statistics.id = 'zenothing_statistics'; | |
statistics.src = 'http://zenothing.com/statistics/ex.ua' + location.pathname; | |
document.body.appendChild(statistics); | |
} | |
//Creates window for file selection | |
var $select = open('', 'select', 'menubar=no,resizable=1,location=no,scrollbars=no,status=no,width=600'); | |
if (!$select) { | |
result = Object.keys(list); | |
open_in_window(); | |
return console.error('Please enable popup windows for ex.ua'); | |
} | |
//$select.resizeTo(600, 800); | |
$select.document.title = 'Select files'; | |
var $style = document.createElement('style'); | |
$style.setAttribute('type', 'text/css'); | |
$style.innerHTML = | |
"label, #get_links {display:block}"; | |
$select.document.head.appendChild($style); | |
function each_checkboxs(call) { | |
var checkboxes = $select.document.querySelectorAll('[type=checkbox]'); | |
for(var i=0; i<checkboxes.length; i++) | |
call(checkboxes[i]); | |
} | |
//Select all checkboxes button | |
var $button_all = document.createElement('button'); | |
$button_all.onclick = function() { | |
each_checkboxs(function(checkbox) { | |
checkbox.checked = true; | |
}) | |
}; | |
$button_all.innerHTML = 'all'; | |
$select.document.body.appendChild($button_all); | |
//Select none checkboxes button | |
var $button_none = document.createElement('button'); | |
$button_none.onclick = function() { | |
each_checkboxs(function(checkbox) { | |
checkbox.checked = false; | |
}) | |
}; | |
$button_none.innerHTML = 'none'; | |
$select.document.body.appendChild($button_none); | |
//Creates checkboxes for links selection | |
for(var href in list) { | |
var text = list[href]; | |
var $label = document.createElement('label'); | |
var $input = document.createElement('input'); | |
$input.type = 'checkbox'; | |
$input.value = href; | |
$input.checked = true; | |
$label.appendChild($input); | |
$label.appendChild(document.createTextNode(text)); | |
$select.document.body.appendChild($label); | |
} | |
var $submit = document.createElement('button'); | |
$submit.id = "get_links"; | |
$submit.innerHTML = 'Get list of links'; | |
$submit.onclick = download_links.bind($select); | |
$select.document.body.appendChild($submit); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment