aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArun Isaac2017-08-01 23:07:46 +0530
committerArun Isaac2017-08-01 23:17:07 +0530
commit8a6feadcc6cc170a45b194a330e7a4064fee99d4 (patch)
tree65b164728c09313e69d45760df5732e5b598d2ac
parent63b010991a3b606c4b0311e85f0672eeac8451e6 (diff)
downloadyoutube-noscript-shim-8a6feadcc6cc170a45b194a330e7a4064fee99d4.tar.gz
youtube-noscript-shim-8a6feadcc6cc170a45b194a330e7a4064fee99d4.tar.lz
youtube-noscript-shim-8a6feadcc6cc170a45b194a330e7a4064fee99d4.zip
Simplify `getMyContent'.
* viewtube.js (getMyContent): Remove getting XML. Simplify logic. Remove unnecessary global variables.
-rw-r--r--viewtube.js52
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();
}