mirror of
https://github.com/Tzahi12345/YoutubeDL-Material.git
synced 2026-04-15 12:21:28 +03:00
Updated Chrome/Firefox extension to 0.4
This commit is contained in:
@@ -1,20 +0,0 @@
|
|||||||
// background.js
|
|
||||||
|
|
||||||
// Called when the user clicks on the browser action.
|
|
||||||
chrome.browserAction.onClicked.addListener(function(tab) {
|
|
||||||
// get the frontend_url
|
|
||||||
chrome.storage.sync.get({
|
|
||||||
frontend_url: 'http://localhost',
|
|
||||||
audio_only: false
|
|
||||||
}, function(items) {
|
|
||||||
chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
|
|
||||||
var activeTab = tabs[0];
|
|
||||||
var url = activeTab.url;
|
|
||||||
if (url.includes('youtube.com')) {
|
|
||||||
var new_url = items.frontend_url + '/#/home;url=' + encodeURIComponent(url) + ';audioOnly=' + items.audio_only;
|
|
||||||
chrome.tabs.create({ url: new_url });
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
});
|
|
||||||
@@ -1,17 +1,20 @@
|
|||||||
{
|
{
|
||||||
"manifest_version": 2,
|
"manifest_version": 2,
|
||||||
"name": "YoutubeDL-Material",
|
"name": "YoutubeDL-Material",
|
||||||
"version": "0.3",
|
"version": "0.4",
|
||||||
"description": "The Official Firefox & Chrome Extension of YoutubeDL-Material, an open-source and self-hosted YouTube downloader.",
|
"description": "The Official Firefox & Chrome Extension of YoutubeDL-Material, an open-source and self-hosted YouTube downloader.",
|
||||||
"background": {
|
"background": {
|
||||||
"scripts": ["background.js"]
|
"scripts": ["background.js"]
|
||||||
},
|
},
|
||||||
"browser_action": {
|
"browser_action": {
|
||||||
"default_icon": "favicon.png"
|
"default_icon": "favicon.png",
|
||||||
|
"default_popup": "popup.html",
|
||||||
|
"default_title": "YoutubeDL-Material"
|
||||||
},
|
},
|
||||||
"permissions": [
|
"permissions": [
|
||||||
"tabs",
|
"tabs",
|
||||||
"storage"
|
"storage",
|
||||||
|
"contextMenus"
|
||||||
],
|
],
|
||||||
"options_ui": {
|
"options_ui": {
|
||||||
"page": "options.html",
|
"page": "options.html",
|
||||||
|
|||||||
35
chrome-extension/popup.html
Normal file
35
chrome-extension/popup.html
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<!-- Scripts -->
|
||||||
|
<script src="js/jquery-3.4.1.min.js"></script>
|
||||||
|
<script src="js/popper.min.js"></script>
|
||||||
|
<script src="js/bootstrap.min.js"></script>
|
||||||
|
|
||||||
|
<!-- Cascading Style Sheets -->
|
||||||
|
<link href="css/bootstrap.min.css" rel="stylesheet" media="screen">
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
|
||||||
|
<div style="width: 400px; margin: 0 auto;">
|
||||||
|
<div style="margin: 10px;">
|
||||||
|
<div class="checkbox">
|
||||||
|
<label>
|
||||||
|
<input type="checkbox" id="audio_only">
|
||||||
|
Audio only
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="input-group mb-3">
|
||||||
|
<input id="url_input" type="text" class="form-control" placeholder="URL" aria-label="URL" aria-describedby="basic-addon2">
|
||||||
|
<div class="input-group-append">
|
||||||
|
<button class="btn btn-outline-secondary" type="button" id="download">Download</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<script src="popup.js"></script>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
50
chrome-extension/popup.js
Normal file
50
chrome-extension/popup.js
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
function audioOnlyClicked() {
|
||||||
|
console.log('audio only clicked');
|
||||||
|
var audio_only = document.getElementById("audio_only").checked;
|
||||||
|
|
||||||
|
// save state
|
||||||
|
|
||||||
|
chrome.storage.sync.set({
|
||||||
|
audio_only: audio_only
|
||||||
|
}, function() {});
|
||||||
|
}
|
||||||
|
|
||||||
|
function downloadVideo() {
|
||||||
|
var input_url = document.getElementById("url_input").value
|
||||||
|
// get the frontend_url
|
||||||
|
chrome.storage.sync.get({
|
||||||
|
frontend_url: 'http://localhost',
|
||||||
|
audio_only: false
|
||||||
|
}, function(items) {
|
||||||
|
var download_url = items.frontend_url + '/#/home;url=' + encodeURIComponent(input_url) + ';audioOnly=' + items.audio_only;
|
||||||
|
chrome.tabs.create({ url: download_url });
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function loadInputs() {
|
||||||
|
// load audio-only input
|
||||||
|
chrome.storage.sync.get({
|
||||||
|
frontend_url: 'http://localhost',
|
||||||
|
audio_only: false
|
||||||
|
}, function(items) {
|
||||||
|
document.getElementById("audio_only").checked = items.audio_only;
|
||||||
|
});
|
||||||
|
|
||||||
|
// load url input
|
||||||
|
chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
|
||||||
|
var activeTab = tabs[0];
|
||||||
|
var current_url = activeTab.url;
|
||||||
|
console.log(current_url);
|
||||||
|
if (current_url && current_url.includes('youtube.com')) {
|
||||||
|
document.getElementById("url_input").value = current_url;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
document.getElementById('download').addEventListener('click',
|
||||||
|
downloadVideo);
|
||||||
|
|
||||||
|
document.getElementById('audio_only').addEventListener('click',
|
||||||
|
audioOnlyClicked);
|
||||||
|
|
||||||
|
document.addEventListener('DOMContentLoaded', loadInputs);
|
||||||
Reference in New Issue
Block a user