|
1 |
/**
|
|
2 |
* Copyright (C) 2021, Wojtek Kosior
|
|
3 |
*
|
|
4 |
* This program is free software: you can redistribute it and/or modify
|
|
5 |
* it under the terms of the CC0 1.0 Universal License as published by
|
|
6 |
* the Creative Commons Corporation.
|
|
7 |
*
|
|
8 |
* This program is distributed in the hope that it will be useful,
|
|
9 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
10 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
11 |
* CC0 1.0 Universal License for more details.
|
|
12 |
* Available under the terms of Creative Commons Zero.
|
|
13 |
*/
|
|
14 |
|
|
15 |
/* Use with https://www.youtube.com/*** */
|
|
16 |
|
|
17 |
/* Redirect youtube.com to yewtu.be */
|
|
18 |
|
|
19 |
function decode_query_options(url)
|
|
20 |
{
|
|
21 |
const query_options = {};
|
|
22 |
const match = /^[^?]*\?(.*)/.exec(url);
|
|
23 |
if (!match)
|
|
24 |
return query_options;
|
|
25 |
|
|
26 |
for (const opt of match[1].split("&")) {
|
|
27 |
const [key, val] =
|
|
28 |
/^([^=]*)=?(.*)/.exec(opt).splice(1, 2).map(decodeURIComponent);
|
|
29 |
query_options[key] = val;
|
|
30 |
}
|
|
31 |
|
|
32 |
return query_options;
|
|
33 |
}
|
|
34 |
|
|
35 |
function encode_query_options(query_options)
|
|
36 |
{
|
|
37 |
return Object.entries(query_options)
|
|
38 |
.map(ar => ar.map(encodeURIComponent).join("=")).join("&");
|
|
39 |
}
|
|
40 |
|
|
41 |
function remake_url(youtube_url)
|
|
42 |
{
|
|
43 |
const query_options = decode_query_options(youtube_url);
|
|
44 |
|
|
45 |
let endpoint = "";
|
|
46 |
|
|
47 |
const match = /^(?:(?:https?)?\/\/)?[^/]*\/([^?]*)/.exec(youtube_url);
|
|
48 |
if (match)
|
|
49 |
endpoint = match[1];
|
|
50 |
|
|
51 |
if (/^embed\//.test(query_options.v))
|
|
52 |
endpoint = query_options.v;
|
|
53 |
|
|
54 |
if (/^embed\/.+/.test(endpoint))
|
|
55 |
delete query_options.v
|
|
56 |
|
|
57 |
const encoded_options = encode_query_options(query_options);
|
|
58 |
return `https://yewtu.be/${endpoint}?${encoded_options}`;
|
|
59 |
}
|
|
60 |
|
|
61 |
window.location.href = remake_url(document.URL);
|
add script that redirect youtube.com to invidious.snopyta