parent
c808f02aa2
commit
9484698825
|
@ -48,6 +48,23 @@ function updateTable() {
|
||||||
getRequests(document.getElementById("count").value,allRequests);
|
getRequests(document.getElementById("count").value,allRequests);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function applyUrlTransforms(url) {
|
||||||
|
console.log("Begin applyUrlTransforms:" + url);
|
||||||
|
if (url.match(/^https?:\/\/(www\.)?youtu(\.be|be\.com)\//)) { // Youtube
|
||||||
|
console.log("Youtube");
|
||||||
|
var videoid = "";
|
||||||
|
// youtu.be share url - Do not anchor to $ due to parameters such as ?t=
|
||||||
|
if (url.match(/^https?:\/\/youtu.be\/[A-Za-z0-9_-]{11}/)) {
|
||||||
|
videoid = url.match(/(?<=^https:\/\/youtu.be\/)[A-Za-z0-9_-]{11}/)[0];
|
||||||
|
} else if (url.match(/^https?:\/\/(www\.)?youtube\.com\//)) {
|
||||||
|
videoid = url.match(/(?<=^https?:\/\/(www\.)?youtube\.com\/watch.*[?&]v=)[A-Za-z0-9_-]{11}/)[0];
|
||||||
|
}
|
||||||
|
var result = 'https://www.youtube.com/watch?v=' + videoid;
|
||||||
|
console.log("Result: " + result);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function addRequestErr(msg) {
|
function addRequestErr(msg) {
|
||||||
document.getElementById('addRequestError').style.display = "inline-block";
|
document.getElementById('addRequestError').style.display = "inline-block";
|
||||||
document.getElementById('addRequestError').innerText = msg;
|
document.getElementById('addRequestError').innerText = msg;
|
||||||
|
@ -142,7 +159,7 @@ const validUrlRegexes = [
|
||||||
];
|
];
|
||||||
function validateAndSubmitRequest() {
|
function validateAndSubmitRequest() {
|
||||||
addRequestErrReset();
|
addRequestErrReset();
|
||||||
var url = document.getElementById("addRequestUrl").value;
|
var url = applyUrlTransforms(document.getElementById("addRequestUrl").value);
|
||||||
var validUrl = false;
|
var validUrl = false;
|
||||||
for (var regex of validUrlRegexes) {
|
for (var regex of validUrlRegexes) {
|
||||||
if (regex.test(url)) {
|
if (regex.test(url)) {
|
||||||
|
|
Loading…
Reference in New Issue