-
Notifications
You must be signed in to change notification settings - Fork 35
/
video-downloader.bundle.es
100 lines (83 loc) · 2.67 KB
/
video-downloader.bundle.es
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/*!
* Copyright (c) 2014-present Cliqz GmbH. All rights reserved.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
/* global $, Handlebars */
/* eslint-disable no-param-reassign */
import helpers from './content/helpers';
import templates from './templates';
import createModuleWrapper from '../core/helpers/action-module-wrapper';
const videoDownloader = createModuleWrapper('video-downloader');
Handlebars.partials = templates;
function localizeDocument() {
Array.from(document.querySelectorAll('[data-i18n]')).forEach((el) => {
const elArgs = el.dataset.i18n.split(',');
const key = elArgs.shift();
el.innerHTML = chrome.i18n.getMessage(key, elArgs);
});
}
function draw(data) {
if (data.hidePairingIframe) {
$('#connect-iframe').addClass('hidden');
} else {
$('#video-downloader').html(templates.template(data));
}
localizeDocument();
}
$(() => {
Object.keys(helpers).forEach((helperName) => {
Handlebars.registerHelper(helperName, helpers[helperName]);
});
$('#video-downloader').html(templates.template({ loading: true }));
videoDownloader.getVideoLinks(undefined).then(draw);
});
let lastClickedId;
$(document).on('click', 'ul.vd-tabs li', function itemClick(e) {
e.stopPropagation();
const tabId = $(this).attr('data-tab');
if (tabId === lastClickedId) {
return;
}
lastClickedId = tabId;
$('ul.vd-tabs li').removeClass('active');
$(this).addClass('active');
$('#vd-tab-content').attr('class', tabId);
});
$(document).on('click', '.link-button', function btnClick(e) {
e.stopPropagation();
const selectedItem = $("#download-links input[type='radio']:checked")[0];
const url = selectedItem.dataset.href;
const filename = selectedItem.value;
const title = selectedItem.dataset.title;
const type = selectedItem.dataset.type;
const size = selectedItem.dataset.size;
const format = selectedItem.dataset.format.toLowerCase().replace(' ', '_');
const origin = decodeURI(selectedItem.dataset.origin);
const buttonId = $(this)[0].id;
if (buttonId === 'download-desktop') {
videoDownloader.download({
url,
filename,
size,
format,
origin,
}).then(window.close);
} else if (buttonId === 'download-mobile') {
videoDownloader.sendToMobile({
url,
title,
type,
format,
});
$('#sending-status').addClass('show');
setTimeout(() => {
$('#sending-status').removeClass('show');
}, 5000);
}
});
$(document).on('click', '.connect-page-link', () => {
videoDownloader.openConnectPage();
});