Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tooling to bundle a browser build #1253

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions browser-build/dist/es2020/ytdl-core.js

Large diffs are not rendered by default.

12 changes: 12 additions & 0 deletions browser-build/dist/es2020/ytdl-core.js.LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/*!
* The buffer module from node.js, for the browser.
*
* @author Feross Aboukhadijeh <https://feross.org>
* @license MIT
*/

/*! http://mths.be/fromcodepoint v0.1.0 by @mathias */

/*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> */

/*! safe-buffer. MIT License. Feross Aboukhadijeh <https://feross.org/opensource> */
1 change: 1 addition & 0 deletions browser-build/dist/es2020/ytdl-core.map

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions browser-build/dist/es5/ytdl-core.js

Large diffs are not rendered by default.

14 changes: 14 additions & 0 deletions browser-build/dist/es5/ytdl-core.js.LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*!
* The buffer module from node.js, for the browser.
*
* @author Feross Aboukhadijeh <https://feross.org>
* @license MIT
*/

/*! http://mths.be/fromcodepoint v0.1.0 by @mathias */

/*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> */

/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */

/*! safe-buffer. MIT License. Feross Aboukhadijeh <https://feross.org/opensource> */
1 change: 1 addition & 0 deletions browser-build/dist/es5/ytdl-core.map

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions browser-build/example/es2020/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
tested in:

* Chrome desktop 85.0.4350.0 w/ Tampermonkey 4.19.0
32 changes: 32 additions & 0 deletions browser-build/example/es2020/html/ytdl-core.with-proxy.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<html>
<head>
<script src="../../../dist/es2020/ytdl-core.js"></script>
<script>
if (window.ytdl) {
window.ytdl.getInfo(
'https://www.youtube.com/watch?v=CICY20dQUPk',
{
requestOptions: {
headers: {"x-requested-with": "ytdl-core"},
proxyUrl: "https://cors-anywhere.herokuapp.com/",
debug: true
}
}
)
.then(function(info) {
var json = JSON.stringify(info, null, 2)
var body = window.document.body

body.innerHTML = '<pre>' + json + '</pre>'
body.style.overflow = 'auto'
body.style.fontFamily = 'monospace'
body.style.fontSize = '14px'
})
.catch(function(error) {
window.alert(error.message)
})
}
</script>
</head>
<body></body>
</html>
28 changes: 28 additions & 0 deletions browser-build/example/es2020/ytdl-core.no-proxy.user.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// ==UserScript==
// @name ytdl-core: no proxy
// @description example: CORS restricts usage to 'youtube.com' domain
// @version 0.0.0-development
// @require ../../dist/es2020/ytdl-core.js
// @match *://youtube.com/watch?v=*
// @match *://youtube.com/embed/*
// @match *://*.youtube.com/watch?v=*
// @match *://*.youtube.com/embed/*
// @icon https://www.youtube.com/favicon.ico
// @run-at document_end
// ==/UserScript==

if (window.ytdl) {
window.ytdl.getInfo(window.location.href)
.then(info => {
const json = JSON.stringify(info, null, 2)
const body = window.document.body

body.innerHTML = `<pre>${json}</pre>`
body.style.overflow = 'auto'
body.style.fontFamily = 'monospace'
body.style.fontSize = '14px'
})
.catch(error => {
window.alert(error.message)
})
}
34 changes: 34 additions & 0 deletions browser-build/example/es2020/ytdl-core.with-proxy.user.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// ==UserScript==
// @name ytdl-core: with proxy
// @description example: proxy is used to bypass CORS restriction, when CSP allows
// @version 0.0.0-development
// @require ../../dist/es2020/ytdl-core.js
// @match *://example.com/*
// @icon https://www.youtube.com/favicon.ico
// @run-at document_end
// ==/UserScript==

if (window.ytdl) {
window.ytdl.getInfo(
'https://www.youtube.com/watch?v=CICY20dQUPk',
{
requestOptions: {
headers: {"x-requested-with": "ytdl-core"},
proxyUrl: "https://cors-anywhere.herokuapp.com/",
debug: true
}
}
)
.then(info => {
const json = JSON.stringify(info, null, 2)
const body = window.document.body

body.innerHTML = `<pre>${json}</pre>`
body.style.overflow = 'auto'
body.style.fontFamily = 'monospace'
body.style.fontSize = '14px'
})
.catch(error => {
window.alert(error.message)
})
}
4 changes: 4 additions & 0 deletions browser-build/example/es5/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
tested in:

* Chrome desktop 30.0.1650.0 w/ Tampermonkey 4.0.69
- note: this version is a good representation of the Android 4.4 WebView
34 changes: 34 additions & 0 deletions browser-build/example/es5/html/ytdl-core.with-proxy.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<html>
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/core-js/3.33.3/minified.min.js"></script>
<script src="https://unpkg.com/whatwg-fetch@3.6.19/dist/fetch.umd.js"></script>
<script src="../../../dist/es5/ytdl-core.js"></script>
<script>
if (window.ytdl) {
window.ytdl.getInfo(
'https://www.youtube.com/watch?v=CICY20dQUPk',
{
requestOptions: {
headers: {"x-requested-with": "ytdl-core"},
proxyUrl: "https://cors-anywhere.herokuapp.com/",
debug: true
}
}
)
.then(function(info) {
var json = JSON.stringify(info, null, 2)
var body = window.document.body

body.innerHTML = '<pre>' + json + '</pre>'
body.style.overflow = 'auto'
body.style.fontFamily = 'monospace'
body.style.fontSize = '14px'
})
.catch(function(error) {
window.alert(error.message)
})
}
</script>
</head>
<body></body>
</html>
64 changes: 64 additions & 0 deletions browser-build/example/es5/ytdl-core.no-proxy.user.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// ==UserScript==
// @name ytdl-core: no proxy
// @description example: CORS restricts usage to 'youtube.com' domain
// @version 0.0.0-development
// @require https://cdnjs.cloudflare.com/ajax/libs/core-js/3.33.3/minified.min.js
// @require https://unpkg.com/whatwg-fetch@3.6.19/dist/fetch.umd.js
// @require ../../dist/es5/ytdl-core.js
// @match *://youtube.com/watch?v=*
// @match *://youtube.com/embed/*
// @match *://*.youtube.com/watch?v=*
// @match *://*.youtube.com/embed/*
// @icon https://www.youtube.com/favicon.ico
// @run-at document_end
// ==/UserScript==

var addGlobals = function(whats) {
var what, obj

if (!Array.isArray(whats))
whats = [whats]

for (var i=0; i < whats.length; i++) {
what = whats[i]
if (window[what] !== unsafeWindow[what]) {
try {
obj = {}
obj[what] = unsafeWindow[what]
Object.assign(window, obj)
}
catch(e) {}
}
}
}

var addAllGlobals = function() {
// DOM for "youtube.com" is dirty.
// It contains many of its own polyfill libraries,
// and changes "window" property attributes in such a way to cause:
// TamperMonkey stores the userscript polyfill library Objects in "unsafeWindow".

if ((typeof unsafeWindow !== 'undefined') && (unsafeWindow !== window)) {
addGlobals(
Object.getOwnPropertyNames(unsafeWindow)
)
}
}

if (window.ytdl) {
addAllGlobals()

window.ytdl.getInfo(window.location.href)
.then(function(info) {
var json = JSON.stringify(info, null, 2)
var body = window.document.body

body.innerHTML = '<pre>' + json + '</pre>'
body.style.overflow = 'auto'
body.style.fontFamily = 'monospace'
body.style.fontSize = '14px'
})
.catch(function(error) {
window.alert(error.message)
})
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// ==UserScript==
// @name ytdl-core: no proxy
// @description example: CORS restricts usage to 'youtube.com' domain
// @version 0.0.0-development
// @require https://github.com/warren-bank/js-url/raw/v3.1.4/es5-browser/jsURL.js
// @require ../../dist/es5/ytdl-core.js
// @match *://youtube.com/watch?v=*
// @match *://youtube.com/embed/*
// @match *://*.youtube.com/watch?v=*
// @match *://*.youtube.com/embed/*
// @icon https://www.youtube.com/favicon.ico
// @run-at document_end
// ==/UserScript==

var addAllGlobals = function() {
// DOM for "youtube.com" is dirty.
// It contains many of its own polyfill libraries.
// This script depends on them!
//
// Note that this is a brittle methodology,
// and this script could break if these libraries
// were to be removed from the YouTube web site.
//
// In addition to the provided polyfills, "URL" is required.
// The old testing browser provides a non-functional "URL",
// and YouTube's polyfill libraries don't replace it.

Object.assign(window, {"URL": window.jsURL.URL})
}

if (window.ytdl) {
addAllGlobals()

window.ytdl.getInfo(window.location.href)
.then(function(info) {
var json = JSON.stringify(info, null, 2)
var body = window.document.body

body.innerHTML = '<pre>' + json + '</pre>'
body.style.overflow = 'auto'
body.style.fontFamily = 'monospace'
body.style.fontSize = '14px'
})
.catch(function(error) {
window.alert(error.message)
})
}
50 changes: 50 additions & 0 deletions browser-build/example/es5/ytdl-core.with-proxy.user.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// ==UserScript==
// @name ytdl-core: with proxy
// @description example: proxy is used to bypass CORS restriction, when CSP allows
// @version 0.0.0-development
// @require https://cdnjs.cloudflare.com/ajax/libs/core-js/3.33.3/minified.min.js
// @require https://unpkg.com/whatwg-fetch@3.6.19/dist/fetch.umd.js
// @require ../../dist/es5/ytdl-core.js
// @match *://example.com/*
// @icon https://www.youtube.com/favicon.ico
// @run-at document_end
// ==/UserScript==

var addAllGlobals = function() {
// No op.
//
// DOM for "example.com" is pure.
// TamperMonkey stores the userscript polyfill library Objects in "window".
//
// DOM for "youtube.com" is dirty.
// It contains many of its own polyfill libraries,
// and changes "window" property attributes in such a way to cause:
// TamperMonkey stores the userscript polyfill library Objects in "unsafeWindow".
}

if (window.ytdl) {
addAllGlobals()

window.ytdl.getInfo(
'https://www.youtube.com/watch?v=CICY20dQUPk',
{
requestOptions: {
headers: {"x-requested-with": "ytdl-core"},
proxyUrl: "https://cors-anywhere.herokuapp.com/",
debug: true
}
}
)
.then(function(info) {
var json = JSON.stringify(info, null, 2)
var body = window.document.body

body.innerHTML = '<pre>' + json + '</pre>'
body.style.overflow = 'auto'
body.style.fontFamily = 'monospace'
body.style.fontSize = '14px'
})
.catch(function(error) {
window.alert(error.message)
})
}
Loading