forked from vimpr/vimperator-plugins
-
Notifications
You must be signed in to change notification settings - Fork 1
/
hd-youkai-youtube.js
52 lines (45 loc) · 1.33 KB
/
hd-youkai-youtube.js
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
// ==VimperatorPlugin==
// @name YouTube HD
// @description High-Quality Movie Monster YoUTuBe
// @description-ja 高画質妖怪ようつべ
// @license Creative Commons 2.1 (Attribution + Share Alike)
// @version 1.0
// @author anekos (anekos@snca.net)
// @minVersion 2.0pre
// @maxVersion 2.0pre
// ==/VimperatorPlugin==
//
// Links:
//
(function () {
function monsterize (url) {
if (url.match(/&fmt=22/))
return url;
if (url.match(/^http:\/\/(?:[^.]+\.)?youtube\.com\/watch/))
return url + '&fmt=22';
let m = url.match(/^http:\/\/(?:[^.]+\.)?youtube\.com\/.*\?.*v=([^&]+)/);
if (m)
return 'http://www.youtube.com/watch?v=' + m[1] + '&fmt=22';
return url;
}
let original = liberator.plugins.hd_youkai_youtube;
if (!original) {
liberator.plugins.youtubehd = original = {
open: liberator.open,
followLink: buffer.followLink
};
}
liberator.open = function (urls) {
if (typeof urls === 'string')
arguments[0] = monsterize(urls);
else
arguments[0] = urls.map(monsterize);
return original.open.apply(this, arguments);
};
buffer.followLink = function (elem) {
if (elem.href)
elem.href = monsterize(elem.href);
original.followLink.apply(this, arguments);
};
})();
// vim:sw=2 ts=2 et si fdm=marker: