mirror of
https://github.com/tubearchivist/browser-extension.git
synced 2024-12-24 10:50:13 +00:00
dedect and validate link type
This commit is contained in:
parent
62e7469e3d
commit
809134d90f
@ -182,6 +182,8 @@ document.addEventListener("DOMContentLoaded", async () => {
|
||||
function createButtons(result) {
|
||||
|
||||
let download = document.getElementById("download");
|
||||
let linkType = document.createElement("h3");
|
||||
linkType.innerText = result.youtube.type.charAt(0).toUpperCase() + result.youtube.type.slice(1);
|
||||
let title = document.createElement("p");
|
||||
title.innerText = result.youtube.title;
|
||||
|
||||
@ -199,6 +201,7 @@ function createButtons(result) {
|
||||
subscribeButton.setAttribute("data-id", result.youtube.url);
|
||||
subscribeButton.addEventListener("click", function(){subscribeEvent()}, false);
|
||||
|
||||
download.appendChild(linkType);
|
||||
download.appendChild(title);
|
||||
download.appendChild(downloadButton);
|
||||
download.appendChild(subscribeButton);
|
||||
|
@ -22,12 +22,41 @@ function getBrowser() {
|
||||
}
|
||||
|
||||
|
||||
function detectUrlType(url) {
|
||||
|
||||
const videoRe = new RegExp(/^https:\/\/(www\.)?(youtube.com\/watch\?v=|youtu\.be\/)\w{11}/);
|
||||
if (videoRe.test(url)) {
|
||||
return "video"
|
||||
}
|
||||
const channelRe = new RegExp(/^https:?\/\/www\.?youtube.com\/c|channel|user\/\w+(\/|featured|videos)?$/);
|
||||
if (channelRe.test(url)) {
|
||||
return "channel"
|
||||
}
|
||||
const playlistRe = new RegExp(/^https:\/\/(www\.)?youtube.com\/playlist\?list=/);
|
||||
if (playlistRe.test(url)) {
|
||||
return "playlist"
|
||||
}
|
||||
|
||||
return false
|
||||
|
||||
}
|
||||
|
||||
|
||||
function sendUrl() {
|
||||
|
||||
let url = document.URL
|
||||
|
||||
let urlType = detectUrlType(url);
|
||||
if (urlType == false) {
|
||||
console.log("not relevant")
|
||||
return
|
||||
}
|
||||
|
||||
let payload = {
|
||||
"youtube": {
|
||||
"url": document.URL,
|
||||
"title": document.title
|
||||
"url": url,
|
||||
"title": document.title,
|
||||
"type": urlType,
|
||||
}
|
||||
}
|
||||
console.log("youtube link: " + JSON.stringify(payload));
|
||||
|
@ -8,6 +8,10 @@ body {
|
||||
min-width: 300px;
|
||||
max-width: 400px;
|
||||
}
|
||||
.h3 {
|
||||
font-family: Sen-bold, sans-serif;
|
||||
text-transform: capitalize;
|
||||
}
|
||||
hr {
|
||||
height: 1px;
|
||||
color: white;
|
||||
|
Loading…
Reference in New Issue
Block a user