Add Svelte app boilerplate (#27)
* Add Svelte app boilerplate * Delete www folder * Web app setup * Fix vector images * README
No files matched your search
@@ -26,11 +26,16 @@ function WebServerLoop()
|
||||
homeRouter = new Http.HttpRouter()
|
||||
homeRouter.Get("/", function(context as object) as boolean
|
||||
response = context.response
|
||||
response.Redirect("/index.html?tab=settings", 302)
|
||||
response.Redirect("/index.v1.html", 302)
|
||||
return true
|
||||
end function)
|
||||
|
||||
m.server.UseRouter(new Http.CorsMiddleware(`http://${GetLocalIpAddress()}:8888`))
|
||||
#if DEBUG
|
||||
allowedOrigin = "*"
|
||||
#else
|
||||
allowedOrigin = `http://${GetLocalIpAddress()}:8888`
|
||||
#end if
|
||||
m.server.UseRouter(new Http.CorsMiddleware(allowedOrigin))
|
||||
m.server.UseRouter(homeRouter)
|
||||
m.server.UseRouter(new Http.DashRouter())
|
||||
m.server.UseRouter(new Http.CommandsApiRouter())
|
||||
|
||||
|
Before Width: | Height: | Size: 36 KiB After Width: | Height: | Size: 36 KiB |
|
Before Width: | Height: | Size: 23 KiB After Width: | Height: | Size: 21 KiB |
|
Before Width: | Height: | Size: 12 KiB After Width: | Height: | Size: 11 KiB |
@@ -7,8 +7,31 @@
|
||||
viewBox="0 0 508 285.75"
|
||||
version="1.1"
|
||||
id="svg10011"
|
||||
sodipodi:docname="logo-dark.svg"
|
||||
inkscape:version="1.2.1 (9c6d41e4, 2022-07-14)"
|
||||
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
|
||||
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
xmlns:svg="http://www.w3.org/2000/svg">
|
||||
<sodipodi:namedview
|
||||
id="namedview396"
|
||||
pagecolor="#ffffff"
|
||||
bordercolor="#000000"
|
||||
borderopacity="0.25"
|
||||
inkscape:showpageshadow="2"
|
||||
inkscape:pageopacity="0.0"
|
||||
inkscape:pagecheckerboard="0"
|
||||
inkscape:deskcolor="#d1d1d1"
|
||||
showgrid="false"
|
||||
inkscape:zoom="0.21851852"
|
||||
inkscape:cx="382.11864"
|
||||
inkscape:cy="540"
|
||||
inkscape:window-width="1440"
|
||||
inkscape:window-height="758"
|
||||
inkscape:window-x="0"
|
||||
inkscape:window-y="25"
|
||||
inkscape:window-maximized="1"
|
||||
inkscape:current-layer="svg10011" />
|
||||
<defs
|
||||
id="defs10008">
|
||||
<rect
|
||||
@@ -66,75 +89,75 @@
|
||||
y="88.402878"
|
||||
rx="20.13974"
|
||||
ry="19.408449" />
|
||||
<text
|
||||
xml:space="preserve"
|
||||
<g
|
||||
aria-label="P"
|
||||
transform="matrix(1.3208994,0,0,1.3208994,-115.36013,-354.38654)"
|
||||
id="text416-2-13"
|
||||
style="font-size:74.6667px;font-family:'The Amaranth';-inkscape-font-specification:'The Amaranth, Normal';white-space:pre;shape-inside:url(#rect418-2-51);display:inline;fill:#ff1c30;fill-opacity:1;stroke:none;stroke-width:1.06591;stroke-linejoin:round;stroke-dasharray:none"><tspan
|
||||
x="180.21484"
|
||||
y="397.45387"
|
||||
id="tspan11055"><tspan
|
||||
style="font-family:'Bunya PERSONAL';-inkscape-font-specification:'Bunya PERSONAL, Normal'"
|
||||
id="tspan11053">P</tspan></tspan></text>
|
||||
<text
|
||||
xml:space="preserve"
|
||||
style="font-size:74.6667px;font-family:'The Amaranth';-inkscape-font-specification:'The Amaranth, Normal';white-space:pre;shape-inside:url(#rect418-2-51);display:inline;fill:#ff1c30;stroke-width:1.06591;stroke-linejoin:round">
|
||||
<path
|
||||
d="m 182.08151,397.45387 v -50.02669 h 15.38134 q 4.032,0 7.54134,1.49333 3.50933,1.49334 6.12267,4.18134 2.61333,2.61333 4.10667,6.12267 1.49333,3.50933 1.49333,7.54133 0,3.95734 -1.49333,7.46667 -1.49334,3.50934 -4.10667,6.12267 -2.61334,2.53867 -6.12267,4.03201 -3.50934,1.49333 -7.54134,1.49333 h -8.81067 v 11.57334 z m 6.57067,-18.14401 h 8.81067 q 2.61334,0 4.928,-0.97067 2.31467,-1.04533 4.03201,-2.688 1.71733,-1.71733 2.688,-3.95733 1.04533,-2.31467 1.04533,-4.92801 0,-2.688 -1.04533,-5.00267 -0.97067,-2.31466 -2.688,-4.032 -1.71734,-1.71733 -4.03201,-2.688 -2.31466,-0.97067 -4.928,-0.97067 h -8.81067 z"
|
||||
style="font-family:'Bunya PERSONAL';-inkscape-font-specification:'Bunya PERSONAL, Normal'"
|
||||
id="path533" />
|
||||
</g>
|
||||
<g
|
||||
aria-label="l"
|
||||
transform="matrix(1.3208994,0,0,1.3208994,-65.866935,-354.45042)"
|
||||
id="text416-2-1-4"
|
||||
style="font-size:74.6667px;font-family:'The Amaranth';-inkscape-font-specification:'The Amaranth, Normal';white-space:pre;shape-inside:url(#rect418-2-8-2);display:inline;fill:#ff1c30;fill-opacity:1;stroke:none;stroke-width:1.06591;stroke-linejoin:round;stroke-dasharray:none"><tspan
|
||||
x="180.21484"
|
||||
y="397.45387"
|
||||
id="tspan11059"><tspan
|
||||
style="font-family:'Bunya PERSONAL';-inkscape-font-specification:'Bunya PERSONAL, Normal'"
|
||||
id="tspan11057">l</tspan></tspan></text>
|
||||
<text
|
||||
xml:space="preserve"
|
||||
style="font-size:74.6667px;font-family:'The Amaranth';-inkscape-font-specification:'The Amaranth, Normal';white-space:pre;shape-inside:url(#rect418-2-8-2);display:inline;fill:#ff1c30;stroke-width:1.06591;stroke-linejoin:round">
|
||||
<path
|
||||
d="m 189.92152,349.36851 v 48.08536 h -6.27201 v -48.08536 z"
|
||||
style="font-family:'Bunya PERSONAL';-inkscape-font-specification:'Bunya PERSONAL, Normal'"
|
||||
id="path530" />
|
||||
</g>
|
||||
<g
|
||||
aria-label="e"
|
||||
transform="matrix(1.3208994,0,0,1.3208994,87.108046,-354.30193)"
|
||||
id="text416-2-5-8"
|
||||
style="font-size:74.6667px;font-family:'The Amaranth';-inkscape-font-specification:'The Amaranth, Normal';white-space:pre;shape-inside:url(#rect418-2-53-6);display:inline;fill:#ff1c30;fill-opacity:1;stroke:none;stroke-width:1.06591;stroke-linejoin:round;stroke-dasharray:none"><tspan
|
||||
x="180.21484"
|
||||
y="397.45387"
|
||||
id="tspan11063"><tspan
|
||||
style="font-family:'Bunya PERSONAL';-inkscape-font-specification:'Bunya PERSONAL, Normal'"
|
||||
id="tspan11061">e</tspan></tspan></text>
|
||||
<text
|
||||
xml:space="preserve"
|
||||
style="font-size:74.6667px;font-family:'The Amaranth';-inkscape-font-specification:'The Amaranth, Normal';white-space:pre;shape-inside:url(#rect418-2-53-6);display:inline;fill:#ff1c30;stroke-width:1.06591;stroke-linejoin:round">
|
||||
<path
|
||||
d="m 216.35353,388.8672 q -3.06134,4.55467 -7.24267,6.64533 -4.10667,2.09067 -8.96001,2.09067 -3.808,0 -7.168,-1.41867 -3.36,-1.49333 -5.824,-3.95733 -2.464,-2.464 -3.95734,-5.824 -1.41867,-3.36001 -1.41867,-7.16801 0,-3.88267 1.41867,-7.24267 1.49334,-3.36 3.95734,-5.824 2.464,-2.53867 5.824,-3.95734 3.36,-1.49333 7.168,-1.49333 4.85334,0 9.10934,2.24 4.33067,2.24 7.46667,6.944 l -21.65334,20.16001 q 1.19466,0.82134 2.98667,1.19467 1.792,0.29867 3.584,0.0747 3.136,-0.37334 5.824,-2.09067 2.76267,-1.792 4.62934,-4.48 z m -28.59735,-10.60267 q -0.224,2.83733 0.74667,5.22666 0.97066,2.38934 2.76267,3.73334 l 17.09867,-16.65067 q -1.41867,-1.71734 -3.808,-2.76267 -2.38934,-1.12 -5.22667,-0.97067 -2.31467,0.14933 -4.33067,1.04533 -2.016,0.896 -3.584,2.46401 -1.49333,1.49333 -2.464,3.50933 -0.97067,2.016 -1.19467,4.40534 z"
|
||||
style="font-family:'Bunya PERSONAL';-inkscape-font-specification:'Bunya PERSONAL, Normal'"
|
||||
id="path527" />
|
||||
</g>
|
||||
<g
|
||||
aria-label="t"
|
||||
transform="matrix(1.3208994,0,0,1.3208994,138.55003,-354.31168)"
|
||||
id="text416-2-59-6"
|
||||
style="font-size:74.6667px;font-family:'The Amaranth';-inkscape-font-specification:'The Amaranth, Normal';white-space:pre;shape-inside:url(#rect418-2-6-6);display:inline;fill:#ff1c30;fill-opacity:1;stroke:none;stroke-width:1.06591;stroke-linejoin:round;stroke-dasharray:none"><tspan
|
||||
x="180.21484"
|
||||
y="397.45387"
|
||||
id="tspan11067"><tspan
|
||||
style="font-family:'Bunya PERSONAL';-inkscape-font-specification:'Bunya PERSONAL, Normal'"
|
||||
id="tspan11065">t</tspan></tspan></text>
|
||||
<text
|
||||
xml:space="preserve"
|
||||
style="font-size:74.6667px;font-family:'The Amaranth';-inkscape-font-specification:'The Amaranth, Normal';white-space:pre;shape-inside:url(#rect418-2-6-6);display:inline;fill:#ff1c30;stroke-width:1.06591;stroke-linejoin:round">
|
||||
<path
|
||||
d="m 180.21484,360.71785 h 3.43467 v -11.34934 h 6.34667 v 11.34934 h 6.64534 v 5.22667 h -6.64534 v 20.23468 q 0,2.61333 1.64267,4.256 1.64267,1.568 4.256,1.568 v 5.6 q -6.048,0 -9.184,-2.912 -3.06134,-2.912 -3.06134,-8.512 v -20.23468 h -3.43467 z"
|
||||
style="font-family:'Bunya PERSONAL';-inkscape-font-specification:'Bunya PERSONAL, Normal'"
|
||||
id="path524" />
|
||||
</g>
|
||||
<g
|
||||
aria-label="l"
|
||||
transform="matrix(1.3208994,0,0,1.3208994,69.600141,-354.30583)"
|
||||
id="text416-2-8-1"
|
||||
style="font-size:74.6667px;font-family:'The Amaranth';-inkscape-font-specification:'The Amaranth, Normal';white-space:pre;shape-inside:url(#rect418-2-5-5);display:inline;fill:#ff1c30;fill-opacity:1;stroke:none;stroke-width:1.06591;stroke-linejoin:round;stroke-dasharray:none"><tspan
|
||||
x="180.21484"
|
||||
y="397.45387"
|
||||
id="tspan11071"><tspan
|
||||
style="font-family:'Bunya PERSONAL';-inkscape-font-specification:'Bunya PERSONAL, Normal'"
|
||||
id="tspan11069">l</tspan></tspan></text>
|
||||
<text
|
||||
xml:space="preserve"
|
||||
style="font-size:74.6667px;font-family:'The Amaranth';-inkscape-font-specification:'The Amaranth, Normal';white-space:pre;shape-inside:url(#rect418-2-5-5);display:inline;fill:#ff1c30;stroke-width:1.06591;stroke-linejoin:round">
|
||||
<path
|
||||
d="m 189.92152,349.36851 v 48.08536 h -6.27201 v -48.08536 z"
|
||||
style="font-family:'Bunya PERSONAL';-inkscape-font-specification:'Bunya PERSONAL, Normal'"
|
||||
id="path521" />
|
||||
</g>
|
||||
<g
|
||||
aria-label="a"
|
||||
transform="matrix(1.3208994,0,0,1.3208994,-48.469095,-354.51494)"
|
||||
id="text416-2-4-5"
|
||||
style="font-size:74.6667px;font-family:'The Amaranth';-inkscape-font-specification:'The Amaranth, Normal';white-space:pre;shape-inside:url(#rect418-2-1-4);display:inline;fill:#ff1c30;fill-opacity:1;stroke:none;stroke-width:1.06591;stroke-linejoin:round;stroke-dasharray:none"><tspan
|
||||
x="180.21484"
|
||||
y="397.45387"
|
||||
id="tspan11075"><tspan
|
||||
style="font-family:'Bunya PERSONAL';-inkscape-font-specification:'Bunya PERSONAL, Normal'"
|
||||
id="tspan11073">a</tspan></tspan></text>
|
||||
<text
|
||||
xml:space="preserve"
|
||||
style="font-size:74.6667px;font-family:'The Amaranth';-inkscape-font-specification:'The Amaranth, Normal';white-space:pre;shape-inside:url(#rect418-2-1-4);display:inline;fill:#ff1c30;stroke-width:1.06591;stroke-linejoin:round">
|
||||
<path
|
||||
d="m 181.85751,379.23519 q 0,-3.88267 1.344,-7.24267 1.344,-3.36 3.584,-5.824 2.31467,-2.53867 5.37601,-3.95734 3.136,-1.49333 6.72,-1.49333 4.256,0 7.76534,2.09067 3.50933,2.016 5.74933,5.45067 v -7.39201 h 6.34667 v 36.58669 h -6.34667 v -7.31734 q -2.24,3.43467 -5.74933,5.45067 -3.50934,2.016 -7.76534,2.016 -3.584,0 -6.72,-1.41867 -3.06134,-1.49333 -5.37601,-3.95733 -2.24,-2.464 -3.584,-5.824 -1.344,-3.36001 -1.344,-7.16801 z m 6.34667,0 q 0,2.464 0.896,4.704 0.97067,2.16534 2.53867,3.80801 1.64267,1.64266 3.808,2.61333 2.24,0.896 4.77867,0.896 2.464,0 4.62934,-0.896 2.24,-0.97067 3.88266,-2.61333 1.64267,-1.64267 2.61334,-3.80801 0.97067,-2.24 0.97067,-4.704 0,-2.464 -0.97067,-4.704 -0.97067,-2.24 -2.61334,-3.88267 -1.64266,-1.64267 -3.88266,-2.61333 -2.16534,-0.97067 -4.62934,-0.97067 -2.53867,0 -4.77867,0.97067 -2.16533,0.97066 -3.808,2.61333 -1.568,1.64267 -2.53867,3.88267 -0.896,2.24 -0.896,4.704 z"
|
||||
style="font-family:'Bunya PERSONAL';-inkscape-font-specification:'Bunya PERSONAL, Normal'"
|
||||
id="path518" />
|
||||
</g>
|
||||
<g
|
||||
aria-label="y"
|
||||
transform="matrix(1.3208994,0,0,1.3208994,9.0695965,-354.11012)"
|
||||
id="text416-2-84-0"
|
||||
style="font-size:74.6667px;font-family:'The Amaranth';-inkscape-font-specification:'The Amaranth, Normal';white-space:pre;shape-inside:url(#rect418-2-3-1);display:inline;fill:#ff1c30;fill-opacity:1;stroke:none;stroke-width:1.06591;stroke-linejoin:round;stroke-dasharray:none"><tspan
|
||||
x="180.21484"
|
||||
y="397.45387"
|
||||
id="tspan11079"><tspan
|
||||
style="font-family:'Bunya PERSONAL';-inkscape-font-specification:'Bunya PERSONAL, Normal'"
|
||||
id="tspan11077">y</tspan></tspan></text>
|
||||
style="font-size:74.6667px;font-family:'The Amaranth';-inkscape-font-specification:'The Amaranth, Normal';white-space:pre;shape-inside:url(#rect418-2-3-1);display:inline;fill:#ff1c30;stroke-width:1.06591;stroke-linejoin:round">
|
||||
<path
|
||||
d="m 186.56151,360.86718 10.97601,28.07468 10.752,-28.07468 h 6.72001 l -18.74135,47.56269 h -6.272 l 4.256,-10.82667 -14.48534,-36.73602 z"
|
||||
style="font-family:'Bunya PERSONAL';-inkscape-font-specification:'Bunya PERSONAL, Normal'"
|
||||
id="path515" />
|
||||
</g>
|
||||
</g>
|
||||
</svg>
|
||||
|
Before Width: | Height: | Size: 6.1 KiB After Width: | Height: | Size: 8.7 KiB |
@@ -78,6 +78,7 @@ namespace WebUtils
|
||||
jpe: "image/jpeg",
|
||||
jpg: "image/jpeg",
|
||||
png: "image/png",
|
||||
svg: "image/svg+xml",
|
||||
css: "text/css",
|
||||
html: "text/html",
|
||||
js: "text/javascript",
|
||||
|
||||
|
Before Width: | Height: | Size: 15 KiB |
@@ -1,346 +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;">
|
||||
|
||||
<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>
|
||||
</br>
|
||||
<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, stay tuned for a redesigned page!
|
||||
</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>
|
||||
|
||||
<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)}
|
||||
\`\`\``;
|
||||
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 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) {
|
||||
document.getElementById("logged-in").innerHTML = `Logged In: true (<a href="${appState.invidious.logged_in_instance}" target="_blank">${appState.invidious.logged_in_instance}</a>)`
|
||||
} 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)
|
||||
});
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
Initialize();
|
||||
</script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||