Preferences / Web App (#79)
* Add basic router * Add a preferences file * small changes * Basic settings navigation menu * Lint fix * Add bunch of controls * Lint fix * StringControl * Lint fix * Add description to keyboard * Settings saving and loading * Lint fix * Settings migration stuff * GET web api * Lint fix * PUT and DELETE (I really fucking hate BrightScript) * plug in sponsorblock settings * autoplay, quality, and video proxying * Remove unused stuff * Lint fix * Invidious instance stuff * cache public instances on start * Start loading home screen after fetching instances * Move web app out of settings to its own screen * picture in picture when in settings * Web app (#80) * Update instance stuff * Update dependencies * Add basic layout * Info and settings page, missing styling * Navbar fixes * Settings page formatting * Theme stuff * Feedback link * Fix username badge * Fix svelte warnings * A wip search page * Add a couple of api functions * Wip home screen * user country code * Expose token and proxy auth calls * Use auth requests server side * Some cleanup * Add svelte vs code extension * remove old web app * More layout stuff * Tweak for string control * Filter out old search suggestions * Search history stuff * img size for lazy loading * Basic modal to play video * Lint fix * Dependencies bump * Add video duration and LIVE indicator to cell * Delete legacy stuff * Add dev menu * Lint fix * Video cell layout * Cell stuff * prefs visibility * Modal layout * Drag and drop functionality * Clear search history * Move web calls to main app * changelog * changelog * Mostly comments * Lint fix --------- Co-authored-by: github-action linter <githubaction@githubaction.com>
This commit is contained in:
1 parent
9a631aab51
commit
8f8c7d38a8
91 files changed
+3979
-1787
No files matched your search
@@ -1,436 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Playlet</title>
|
||||
<style>
|
||||
table,
|
||||
th,
|
||||
td {
|
||||
border: 1px solid;
|
||||
cursor: all-scroll;
|
||||
}
|
||||
|
||||
table {
|
||||
-webkit-user-select: none;
|
||||
-ms-user-select: none;
|
||||
user-select: none;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body ondrop="OnBodyDrop(event);" ondragover="OnBodyDragover(event);">
|
||||
<h2>Playlet - Youtube Player for Roku</h2>
|
||||
<h4 id="app-version">Version: </h4>
|
||||
<h4>Invidious Instance: <a id="instance" target="_blank">None</a></h4>
|
||||
<button onclick="PlayVideo()">Play Video</button>
|
||||
<label for="video-id">Video ID:</label>
|
||||
<input type="text" id="video-id" name="video-id" style="min-width:300px;">
|
||||
<div><small>Hint: drag and drop links or video thumbnails from Youtube or Invidious into this page</small></div>
|
||||
|
||||
<h4 id="logged-in">Logged In: </h4>
|
||||
<button style="display: none" id="login-button" onclick="Login()">Login</button>
|
||||
<button style="display: none" id="logout-button" onclick="Logout()">Logout</button>
|
||||
|
||||
<br />
|
||||
|
||||
<table id="instances">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Instances - find more at <a href="https://api.invidious.io/" target="_blank">api.invidious.io</a></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
</tbody>
|
||||
<tbody>
|
||||
<tr id="instance-input-row">
|
||||
<td>
|
||||
<input type="text" id="instance-input" name="new-instance" oninput="OnNewInstanceTextChanged()"
|
||||
style="min-width:300px;">
|
||||
</td>
|
||||
<td>
|
||||
<button id="instance-add" disabled="true" onclick="AddInstance()">Add</button>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<div><small>Hint: drag and drop instances to reorder them. The one at the top will be used.</small></div>
|
||||
<button style="display: none" id="update-instances" onclick="UpdateInstances()">Update Instances</button>
|
||||
</br>
|
||||
<button onclick="ClearSearchHistory()">Clear Search History</button>
|
||||
|
||||
<h5>Instructions</h5>
|
||||
<ul>
|
||||
<li>Make sure you are logged in the Invidious instance before logging in on this page</li>
|
||||
<li>If this is your first time using this invidious Instance, you might want to create an account</li>
|
||||
<li>Once you are logged in to your current instance, click "Login" on this page, and authorize the token</li>
|
||||
<li>Once logged in, this page should show "Logged In: true"</li>
|
||||
<li>After login, the home page should refresh automatically. You should then be able to see your Subscription feed
|
||||
and Playlists, if you have any.</li>
|
||||
</ul>
|
||||
<p>
|
||||
This is a barebone page for now, <a href="/index.html">click here for the redesigned page!</a>
|
||||
</p>
|
||||
<h5>Feedback is welcome over at: <a id="feedback-url" href="https://github.com/iBicha/playlet"
|
||||
target="_blank">https://github.com/iBicha/playlet</a></h5>
|
||||
|
||||
<div id="dev-menu" style="display: none;">
|
||||
<h4>Developer menu</h4>
|
||||
<p><small>These are for testing purposes only, and are not meant to be used by end users.</small></p>
|
||||
<label for="playlet-lib-tag">Playlet Lib Tag:</label>
|
||||
<select name="playlet-lib-tag" id="playlet-lib-tag">
|
||||
<option value="">latest (default)</option>
|
||||
</select>
|
||||
<button onclick="SetPlayletLibUrls()">Apply</button>
|
||||
</div>
|
||||
<script>
|
||||
function Login() {
|
||||
if (!window.appState) {
|
||||
alert("Error with login, please refresh the page.")
|
||||
}
|
||||
window.location = window.appState.invidious.auth_url
|
||||
}
|
||||
|
||||
function Logout() {
|
||||
PostJson('/api/command', { command: "logout" })
|
||||
.then(function (response) {
|
||||
window.location.reload();
|
||||
})
|
||||
.catch(function (err) {
|
||||
alert(err)
|
||||
});
|
||||
}
|
||||
|
||||
function PlayVideo() {
|
||||
let v = document.getElementById('video-id').value
|
||||
if (IsValidHttpUrl(v)) {
|
||||
v = GetVideoId(v)
|
||||
}
|
||||
if (!v || v.length < 8) {
|
||||
alert("Please set video id")
|
||||
return
|
||||
}
|
||||
PostJson('/api/command', { command: "play", videoId: v })
|
||||
.catch(function (err) {
|
||||
alert(err)
|
||||
});
|
||||
}
|
||||
|
||||
function ClearSearchHistory() {
|
||||
PostJson('/api/command', { command: "clear-search-history" })
|
||||
.then(function (response) {
|
||||
alert("Search history cleared");
|
||||
})
|
||||
.catch(function (err) {
|
||||
alert(err)
|
||||
});
|
||||
}
|
||||
|
||||
function CreateGithubIssueUrl() {
|
||||
title = "[Feedback] Playlet"
|
||||
body = `### Feedback
|
||||
_insert feedback here_
|
||||
|
||||
#### App Info
|
||||
\`\`\`
|
||||
${JSON.stringify(window.appState.app, null, 2)}
|
||||
\`\`\`
|
||||
|
||||
#### Device Info
|
||||
\`\`\`
|
||||
${JSON.stringify(window.appState.device, null, 2)}
|
||||
\`\`\`
|
||||
|
||||
#### Invidious settings
|
||||
\`\`\`
|
||||
${JSON.stringify(window.appState.invidious, null, 2)}
|
||||
\`\`\``;
|
||||
return `https://github.com/iBicha/playlet/issues/new?title=${encodeURIComponent(title)}&body=${encodeURIComponent(body)}`
|
||||
}
|
||||
|
||||
function IsValidHttpUrl(string) {
|
||||
let url;
|
||||
try {
|
||||
url = new URL(string);
|
||||
} catch (_) {
|
||||
return false;
|
||||
}
|
||||
return url.protocol === "http:" || url.protocol === "https:";
|
||||
}
|
||||
|
||||
function GetVideoId(url) {
|
||||
// Share/Short url
|
||||
const YoutubeUrls = [
|
||||
"https://youtu.be/",
|
||||
"http://youtu.be/",
|
||||
"https://www.youtu.be/",
|
||||
"http://www.youtu.be/",
|
||||
"https://youtube.com/shorts/",
|
||||
"http://youtube.com/shorts/",
|
||||
"https://www.youtube.com/shorts/",
|
||||
"http://www.youtube.com/shorts/",
|
||||
]
|
||||
for (var i in YoutubeUrls) {
|
||||
let youtubeUrl = YoutubeUrls[i];
|
||||
if (url.startsWith(youtubeUrl)) {
|
||||
url = url.replace(youtubeUrl, "")
|
||||
if (url.includes("?")) {
|
||||
url = url.substring(0, url.indexOf("?"))
|
||||
}
|
||||
return url
|
||||
}
|
||||
}
|
||||
|
||||
// regular url
|
||||
url = new URL(url)
|
||||
const urlSearchParams = new URLSearchParams(url.search);
|
||||
return urlSearchParams.get('v')
|
||||
}
|
||||
|
||||
function OnNewInstanceTextChanged() {
|
||||
document.getElementById("instance-add").disabled = !IsValidHttpUrl(document.getElementById("instance-input").value)
|
||||
}
|
||||
|
||||
function AddInstance() {
|
||||
instance = document.getElementById("instance-input").value
|
||||
AddInstanceRow(instance)
|
||||
document.getElementById("instance-input").value = ""
|
||||
document.getElementById("update-instances").style.display = "block";
|
||||
}
|
||||
|
||||
function AddInstanceRow(instance) {
|
||||
instances = document.getElementById("instances").getElementsByTagName('tbody')[0];
|
||||
var row = instances.insertRow();
|
||||
row.draggable = true
|
||||
row.addEventListener('dragstart', OnTableRowDragStart);
|
||||
row.addEventListener('dragover', OnTableRowDragover);
|
||||
row.addEventListener('drop', OnTableRowDrop);
|
||||
var cell = row.insertCell();
|
||||
style = instance === window.appState.invidious.selected_instance ? `style="font-weight:bold"` : ""
|
||||
cell.innerHTML = `<a href="${instance}" ${style} target="_blank">${instance}</a>`
|
||||
cell = row.insertCell();
|
||||
cell.innerHTML = `<button onclick="RemoveInstance('${instance}')">Remove</button>`
|
||||
}
|
||||
|
||||
function RemoveInstance(instance) {
|
||||
instanceRows = Array.from(document.getElementById("instances")
|
||||
.getElementsByTagName('tbody')[0]
|
||||
.getElementsByTagName('tr'));
|
||||
|
||||
for (const i in instanceRows) {
|
||||
currentInstance = instanceRows[i].getElementsByTagName('a')[0].innerText
|
||||
if (currentInstance === instance) {
|
||||
instanceRows[i].remove()
|
||||
document.getElementById("update-instances").style.display = "block";
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function UpdateInstances() {
|
||||
instances = Array.from(document.getElementById("instances")
|
||||
.getElementsByTagName('tbody')[0]
|
||||
.getElementsByTagName('td'))
|
||||
.map(el => el.getElementsByTagName('a')[0])
|
||||
.filter(a => !!a)
|
||||
.map(a => a.innerText);
|
||||
|
||||
PostJson('/invidious/instances', instances)
|
||||
.then(function (response) {
|
||||
alert("Instances updated. Restart Playlet to reflect changes.")
|
||||
window.location.reload();
|
||||
})
|
||||
.catch(function (err) {
|
||||
alert(err)
|
||||
});
|
||||
}
|
||||
|
||||
function PostJson(url, payload) {
|
||||
return fetch(url,
|
||||
{
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
method: "POST",
|
||||
body: JSON.stringify(payload)
|
||||
})
|
||||
}
|
||||
|
||||
function FetchReleaseTags() {
|
||||
fetch("https://api.github.com/repos/iBicha/playlet/releases")
|
||||
.then(function (response) {
|
||||
return response.json();
|
||||
})
|
||||
.then(function (releases) {
|
||||
releases.filter(release => release.assets.filter(asset => asset.name === "playlet-lib.zip").length > 0)
|
||||
.forEach(r => {
|
||||
var option = document.createElement("option");
|
||||
option.text = r.tag_name;
|
||||
option.value = r.tag_name;
|
||||
document.getElementById("playlet-lib-tag").add(option);
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
function SetPlayletLibUrls() {
|
||||
var tags = document.getElementById("playlet-lib-tag");
|
||||
var value = tags.value;
|
||||
let content = null
|
||||
|
||||
if(value !== ""){
|
||||
content = JSON.stringify([{
|
||||
link: `https://github.com/iBicha/playlet/releases/download/${value}/playlet-lib.zip`,
|
||||
type: 'custom'
|
||||
}]);
|
||||
}
|
||||
|
||||
PostJson('/api/command', { command: "set-playlet-lib-urls", content: content })
|
||||
.then(function (response) {
|
||||
alert("Playlet lib tag updated. Restart Playlet to reflect changes.");
|
||||
window.location.reload();
|
||||
})
|
||||
.catch(function (err) {
|
||||
alert(err)
|
||||
});
|
||||
}
|
||||
|
||||
function ShouldShowDevMenu() {
|
||||
const urlSearchParams = new URLSearchParams(window.location.search);
|
||||
return !!urlSearchParams.get('dev')
|
||||
}
|
||||
|
||||
function Initialize() {
|
||||
fetch("/api/state")
|
||||
.then(function (response) {
|
||||
return response.json();
|
||||
})
|
||||
.then(function (appState) {
|
||||
window.appState = appState
|
||||
console.log(appState)
|
||||
|
||||
document.getElementById("app-version").innerText = `Version: ${appState.app.version}`
|
||||
|
||||
if (appState.invidious.logged_in) {
|
||||
let loggedIn = 'Logged In '
|
||||
if (appState.invidious.logged_in_username) {
|
||||
loggedIn += `as "${appState.invidious.logged_in_username}"`
|
||||
} else {
|
||||
loggedIn += ": true"
|
||||
}
|
||||
loggedIn += ` (<a href="${appState.invidious.logged_in_instance}" target="_blank">${appState.invidious.logged_in_instance}</a>)`
|
||||
document.getElementById("logged-in").innerHTML = loggedIn
|
||||
} else {
|
||||
document.getElementById("logged-in").innerHTML = "Logged In: false"
|
||||
}
|
||||
|
||||
instanceEl = document.getElementById("instance")
|
||||
instanceEl.innerText = instanceEl.href = appState.invidious.selected_instance
|
||||
|
||||
for (var i in appState.invidious.instances) {
|
||||
AddInstanceRow(appState.invidious.instances[i])
|
||||
}
|
||||
|
||||
loginButton = document.getElementById("login-button")
|
||||
loginButton.innerText = `Login (${appState.invidious.selected_instance})`
|
||||
loginButton.style.display = appState.invidious.logged_in ? "none" : "block";
|
||||
|
||||
document.getElementById("logout-button").style.display = !appState.invidious.logged_in ? "none" : "block";
|
||||
|
||||
document.getElementById("feedback-url").href = CreateGithubIssueUrl()
|
||||
})
|
||||
.catch(function (err) {
|
||||
alert(err)
|
||||
});
|
||||
|
||||
SetupWebSocket();
|
||||
if(ShouldShowDevMenu()){
|
||||
document.getElementById("dev-menu").style.display = "block";
|
||||
FetchReleaseTags();
|
||||
}
|
||||
}
|
||||
|
||||
var tableRow;
|
||||
function OnTableRowDragStart(event) {
|
||||
target = event.target;
|
||||
while (target && target.tagName !== 'TR') {
|
||||
target = target.parentNode
|
||||
}
|
||||
if (target.id === "instance-input-row") {
|
||||
return
|
||||
}
|
||||
tableRow = target
|
||||
}
|
||||
|
||||
function OnTableRowDragover(event) {
|
||||
event.preventDefault();
|
||||
|
||||
if (!tableRow) {
|
||||
return
|
||||
}
|
||||
|
||||
target = event.target;
|
||||
while (target && target.tagName !== 'TR') {
|
||||
target = target.parentNode
|
||||
}
|
||||
if (!target || target.id === "instance-input-row") {
|
||||
return
|
||||
}
|
||||
|
||||
let children = Array.from(target.parentNode.children);
|
||||
|
||||
if (children.indexOf(target) > children.indexOf(tableRow))
|
||||
target.after(tableRow);
|
||||
else
|
||||
target.before(tableRow);
|
||||
}
|
||||
|
||||
function OnTableRowDrop(event) {
|
||||
event.preventDefault();
|
||||
tableRow = undefined
|
||||
document.getElementById("update-instances").style.display = "block";
|
||||
}
|
||||
|
||||
function OnBodyDrop(event) {
|
||||
for (var i in event.dataTransfer.items) {
|
||||
let item = event.dataTransfer.items[i]
|
||||
if (item.kind = 'string' && item.getAsString) {
|
||||
item.getAsString((dataString) => {
|
||||
if (IsValidHttpUrl(dataString) && GetVideoId(dataString)) {
|
||||
document.getElementById('video-id').value = dataString
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
event.preventDefault();
|
||||
}
|
||||
|
||||
function OnBodyDragover(event) {
|
||||
event.preventDefault();
|
||||
}
|
||||
|
||||
function SetupWebSocket() {
|
||||
var socket = new WebSocket(`ws://${window.location.host}`);
|
||||
socket.onopen = function (event) {
|
||||
console.log("WebSocket connected!")
|
||||
const message = "Hello?"
|
||||
console.log(`Sending: "${message}"`)
|
||||
socket.send(message);
|
||||
};
|
||||
socket.onclose = function (event) {
|
||||
console.log("WebSocket closed!")
|
||||
};
|
||||
socket.onerror = function (event) {
|
||||
console.log('WebSocket error: ', event);
|
||||
};
|
||||
socket.onmessage = function (event) {
|
||||
console.log(`Received: "${event.data}"`);
|
||||
}
|
||||
}
|
||||
|
||||
Initialize();
|
||||
</script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
Reference in new issue
Block a user