Skip to content

Commit 08678ab

Browse files
committed
fixes #191
1 parent e9f0757 commit 08678ab

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+2902
-125
lines changed

Diff for: src/iaextractor.xpi renamed to builds/0.5.9.xpi

426 KB
Binary file not shown.

Diff for: src/data/formats/permanent.css

+8
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@
135135
transition: transform 300ms;
136136
}
137137
.iaextractor-item {
138+
font-size: 13px;
138139
display: block;
139140
line-height: 30px;
140141
height: 30px;
@@ -244,3 +245,10 @@
244245
#formats-button-small:hover{
245246
opacity: 1;
246247
}
248+
249+
#formats-button-small-2 {
250+
background: url('./injected-button.png') center center no-repeat;
251+
background-size: 16px 16px;
252+
width: 36px;
253+
cursor: pointer;
254+
}

Diff for: src/data/formats/permanent.js

+61-28
Original file line numberDiff line numberDiff line change
@@ -33,51 +33,84 @@ function remove () {
3333
}
3434

3535
function init () {
36-
var parent = $('watch8-secondary-actions') || $('vo');
37-
if (!parent) {
38-
return;
39-
}
4036
// Remove old button
4137
remove();
42-
// Add new button
43-
var button = html('button', {
44-
'id': 'formats-button-small',
45-
'title': 'Detect all possible download links',
46-
'class': 'yt-uix-button yt-uix-button-size-default yt-uix-button-opacity yt-uix-button-has-icon yt-uix-tooltip'
47-
}, parent);
48-
button.addEventListener('click', function () {
49-
this.blur();
50-
self.port.emit('formats');
51-
});
38+
// old UI
39+
var parent = $('watch8-secondary-actions') || $('vo');
40+
if (parent) {
41+
// Add new button
42+
var button = html('button', {
43+
'id': 'formats-button-small',
44+
'title': 'Detect all possible download links',
45+
'class': 'yt-uix-button yt-uix-button-size-default yt-uix-button-opacity yt-uix-button-has-icon yt-uix-tooltip'
46+
}, parent);
47+
button.addEventListener('click', function () {
48+
this.blur();
49+
self.port.emit('formats');
50+
});
5251

53-
var title = html('span', {
54-
'class': 'yt-uix-button-content'
55-
});
56-
title.textContent = 'Download';
57-
var imgContainer = html('span', {
58-
'class': 'yt-uix-button-icon-wrapper'
59-
});
60-
html('img', {
61-
'class': 'yt-uix-button-icon yt-sprite',
62-
'src': 'resource://feca4b87-3be4-43da-a1b1-137c24220968-at-jetpack/data/formats/injected-button.png'
63-
}, imgContainer);
64-
button.appendChild(imgContainer);
65-
button.appendChild(title);
52+
var title = html('span', {
53+
'class': 'yt-uix-button-content'
54+
});
55+
title.textContent = 'Download';
56+
var imgContainer = html('span', {
57+
'class': 'yt-uix-button-icon-wrapper'
58+
});
59+
html('img', {
60+
'class': 'yt-uix-button-icon yt-sprite',
61+
'src': 'resource://feca4b87-3be4-43da-a1b1-137c24220968-at-jetpack/data/formats/injected-button.png'
62+
}, imgContainer);
63+
button.appendChild(imgContainer);
64+
button.appendChild(title);
65+
}
6666
}
67+
68+
// new UI
69+
(function () {
70+
function observe () {
71+
const top = document.querySelector('ytd-video-primary-info-renderer #top-level-buttons');
72+
if (top) {
73+
let button = top.querySelector('ytd-button-renderer');
74+
if (button) {
75+
button = button.cloneNode(false);
76+
let a = top.querySelector('ytd-button-renderer a');
77+
if (a) {
78+
a = a.cloneNode(true);
79+
button.appendChild(a);
80+
}
81+
button.id = 'formats-button-small-2';
82+
button.addEventListener('click', () => self.port.emit('formats'));
83+
const lastChild = [...top.parentNode.children].pop();
84+
if (lastChild) {
85+
top.parentNode.insertBefore(button, lastChild);
86+
}
87+
else {
88+
top.parentNode.appendChild(button);
89+
}
90+
}
91+
window.removeEventListener('yt-visibility-refresh', observe);
92+
}
93+
}
94+
window.addEventListener('yt-visibility-refresh', observe);
95+
})();
96+
6797
// init
6898
document.addEventListener('DOMContentLoaded', init, false);
6999
if (document.readyState !== 'loading') {
70100
init();
71101
}
72102
function loader () {
73103
init();
74-
self.port.emit('page-update');}
104+
self.port.emit('page-update');
105+
}
75106
// Update toolbar button (HTML5 History API)
76107
self.port.emit('page-update');
77108
document.addEventListener('spfdone', loader);
109+
document.addEventListener('yt-navigate-start', loader);
78110
self.port.on('detach', function () {
79111
remove();
80112
document.removeEventListener('spfdone', loader);
113+
document.removeEventListener('yt-navigate-start', loader);
81114
});
82115

83116
// Clean up

Diff for: src/install.rdf

-25
This file was deleted.

Diff for: src/lib/main.js

+11-11
Original file line numberDiff line numberDiff line change
@@ -489,9 +489,10 @@ yButton = toolbarbutton.ToolbarButton({
489489
}
490490
});
491491

492-
exports.main = function (options, callbacks) {
492+
// onInstall
493+
(function () {
493494
//Install
494-
if (options.loadReason == 'install' || prefs.forceVisible) {
495+
if (self.loadReason == 'install' || prefs.forceVisible) {
495496
//If adjacent button is restartless wait for its creation
496497
timer.setTimeout(function () {
497498
yButton.moveTo(config.toolbar.move);
@@ -500,16 +501,16 @@ exports.main = function (options, callbacks) {
500501
// Check current page
501502
monitor(tabs.activeTab);
502503
//Welcome page
503-
if (options.loadReason === 'install' || options.loadReason === 'upgrade') {
504-
prefs.newVer = options.loadReason;
504+
if (self.loadReason === 'install' || self.loadReason === 'upgrade') {
505+
prefs.newVer = self.loadReason;
505506
}
506-
if (options.loadReason == 'startup' || options.loadReason == 'install') {
507+
if (self.loadReason == 'startup' || self.loadReason == 'install') {
507508
welcome();
508509
}
509-
if (options.loadReason == 'install' && !prefs.ffmpegPath && !prefs.showFFmpegInstall) {
510+
if (self.loadReason == 'install' && !prefs.ffmpegPath && !prefs.showFFmpegInstall) {
510511
external.checkFFmpeg();
511512
}
512-
}
513+
})();
513514

514515
/** Welcome page **/
515516
function welcome () {
@@ -547,8 +548,7 @@ tabs.on('ready', function () {
547548
});
548549
tabs.on('activate', monitor);
549550

550-
551-
exports.onUnload = function (reason) {
551+
unload.when(function () {
552552
//Close tools window
553553
let wm = Cc['@mozilla.org/appshell/window-mediator;1']
554554
.getService(Ci.nsIWindowMediator);
@@ -559,7 +559,7 @@ exports.onUnload = function (reason) {
559559
}
560560
//Remove observer
561561
//http.destroy();
562-
}
562+
});
563563

564564
/** HTTP Observer **/
565565
var http = (function () {
@@ -1325,4 +1325,4 @@ unload.when(function () {
13251325
win.close();
13261326
}
13271327
};
1328-
})
1328+
});

Diff for: src/lib/youtube.js

+9-24
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,6 @@ function signatureLocal(info) {
197197
}
198198

199199
var scriptURL = doMatch(info.response.text, /\"js\":\s*\"([^\"]+)\"/);
200-
console.error(scriptURL)
201200
if (!scriptURL) {
202201
return d.reject(Error('signatureLocal: Cannot resolve signature;1'));
203202
}
@@ -234,42 +233,29 @@ function signatureLocal(info) {
234233
response.text,
235234
/([\w$]*)\s*:\s*function\s*\(\s*[\w$]*\s*\)\s*{\s*(?:return\s*)?[\w$]*\.reverse\s*\(\s*\)\s*}/
236235
);
237-
238-
if (revFunName) revFunName = revFunName.replace('$', '\\$');
239236
var slcFuncName = doMatch(
240237
response.text,
241238
/([\w$]*)\s*:\s*function\s*\(\s*[\w$]*\s*,\s*[\w$]*\s*\)\s*{\s*(?:return\s*)?[\w$]*\.(?:slice|splice)\(.+\)\s*}/
242239
);
243-
if (slcFuncName) slcFuncName = slcFuncName.replace('$', '\\$');
244-
var regSlice = new RegExp(
245-
'\\.(?:' + 'slice' + (slcFuncName ? '|' + slcFuncName : '') + ')\\s*\\(\\s*(?:[a-zA-Z_$][\\w$]*\\s*,)?\\s*([0-9]+)\\s*\\)'
246-
);
247-
var regReverse = new RegExp(
248-
'\\.(?:' + 'reverse' + (revFunName ? '|' + revFunName : '') + ')\\s*\\([^\\)]*\\)'
249-
);
250-
var regSwap = new RegExp('[\\w$]+\\s*\\(\\s*[\\w$]+\\s*,\\s*([0-9]+)\\s*\\)');
251240
var regInline = new RegExp(
252241
'[\\w$]+\\[0\\]\\s*=\\s*[\\w$]+\\[([0-9]+)\\s*%\\s*[\\w$]+\\.length\\]'
253242
);
254243
var funcPieces = functionCode.split(/\s*\;\s*/), decodeArray = [], signatureLength = 81;
244+
255245
for (var i = 0; i < funcPieces.length; i++) {
256246
funcPieces[i] = funcPieces[i].trim();
257247
var codeLine = funcPieces[i];
258248
if (codeLine.length > 0) {
259-
var arrSlice = codeLine.match(regSlice);
260-
var arrReverse = codeLine.match(regReverse);
261-
262-
if (arrSlice && arrSlice.length >= 2) { // slice
263-
var slice = parseInt(arrSlice[1]);
264-
if (isInteger(slice)) {
265-
decodeArray.push('s', slice);
266-
signatureLength += slice;
249+
if (codeLine.indexOf(slcFuncName) !== -1) { // slice
250+
let slice = /\d+/.exec(codeLine.split(',').pop()); // oE.s4(a,43) or oE["s4"](a,43) or oE['s4'](a,43)
251+
if (slice && slice.length) {
252+
decodeArray.push('s', slice[0]);
267253
}
268254
else {
269255
d.reject(Error('signatureLocal: Cannot resolve signature;4'));
270256
}
271257
}
272-
else if (arrReverse && arrReverse.length >= 1) { // reverse
258+
else if (codeLine.indexOf(revFunName) !== -1) { // reverse
273259
decodeArray.push('r');
274260
}
275261
else if (codeLine.indexOf('[0]') >= 0) { // inline swap
@@ -286,10 +272,9 @@ function signatureLocal(info) {
286272
}
287273
}
288274
else if (codeLine.indexOf(',') >= 0) { // swap
289-
var swap = doMatch(codeLine, regSwap);
290-
swap = parseInt(swap);
291-
if (isInteger(swap)) {
292-
decodeArray.push('w', swap);
275+
let swap = /\d+/.exec(codeLine.split(',').pop()); // oE.s4(a,43) or oE["s4"](a,43) or oE['s4'](a,43)
276+
if (swap && swap.length) {
277+
decodeArray.push('w', swap[0]);
293278
}
294279
else {
295280
return d.reject(Error('signatureLocal: Cannot resolve signature;6'));

0 commit comments

Comments
 (0)