diff options
Diffstat (limited to 'viewtube.js')
-rw-r--r-- | viewtube.js | 52 |
1 files changed, 14 insertions, 38 deletions
diff --git a/viewtube.js b/viewtube.js index c18a548..f20007d 100644 --- a/viewtube.js +++ b/viewtube.js @@ -26,11 +26,10 @@ var userscript = 'ViewTube'; // Page - var page = {win: window, doc: document, body: document.body, url: window.location.href, title: document.title, site: window.location.hostname.match(/([^.]+)\.[^.]+$/)[1]}; + var page = {dom: document.documentElement.outerHTML, win: window, url: window.location.href}; // Player var player = {}; - var option = {'definition': 'HD', 'container': 'MP4', 'direct': false}; var mimetypes = { 'MPEG': 'video/mpeg', 'MP4': 'video/mp4', @@ -41,7 +40,6 @@ 'AVI': 'video/x-msvideo', '3GP': 'video/3gpp', }; - var sources = {}; // Links var website = 'https://git.systemreboot.net/youtube-noscript-shim/about'; @@ -162,41 +160,21 @@ } function getMyContent(url, pattern, clean) { - var myPageContent, myVideosParse, myVideosContent; - var getMethod = (url != page.url) ? 'XHR' : 'DOM'; - if (!sources[url]) sources[url] = {}; - if (getMethod == 'DOM') { - if (!sources[url]['DOM']) - sources[url]['DOM'] = document.querySelector("html").innerHTML; - myPageContent = sources[url]['DOM']; + var myPageContent, myVideosParse; + // Get content + if (url == page.url) myPageContent = page.dom; + else { + var xmlHTTP = new XMLHttpRequest(); + xmlHTTP.open('GET', url, false); + xmlHTTP.send(); + myPageContent = xmlHTTP.responseText; + } + // Match pattern + if (pattern == "TEXT") return myPageContent; + else { if (clean) myPageContent = cleanMyContent(myPageContent, true); myVideosParse = myPageContent.match(pattern); - myVideosContent = (myVideosParse) ? myVideosParse[1] : null; - if (myVideosContent) return myVideosContent; - else getMethod = 'XHR'; - } - if (getMethod == 'XHR') { - if (!sources[url]['XHR']) sources[url]['XHR'] = {}; - if ((pattern == 'XML' && !sources[url]['XHR']['XML']) || (pattern != 'XML' && !sources[url]['XHR']['TEXT'])) { - var xmlHTTP = new XMLHttpRequest(); - xmlHTTP.open('GET', url, false); - xmlHTTP.send(); - if (pattern == 'XML') sources[url]['XHR']['XML'] = xmlHTTP.responseXML; - else sources[url]['XHR']['TEXT'] = xmlHTTP.responseText; - } - if (pattern == 'XML') { - myVideosContent = sources[url]['XHR']['XML']; - } - else if (pattern == 'TEXT') { - myVideosContent = sources[url]['XHR']['TEXT']; - } - else { - myPageContent = sources[url]['XHR']['TEXT']; - if (clean) myPageContent = cleanMyContent(myPageContent, true); - myVideosParse = myPageContent.match(pattern); - myVideosContent = (myVideosParse) ? myVideosParse[1] : null; - } - return myVideosContent; + return myVideosParse ? myVideosParse[1] : null; } } @@ -331,8 +309,6 @@ 'videoPlay': ytDefaultVideo, 'videoThumb': ytVideoThumb }; - option['definitions'] = ['Ultra High Definition', 'Full High Definition', 'High Definition', 'Standard Definition', 'Low Definition', 'Very Low Definition']; - option['containers'] = ['MP4', 'WebM', 'FLV', '3GP', 'Any']; createMyPlayer(); } |