Skip to content

Commit 3ef0fd1

Browse files
authored
Merge pull request #4 from Davilarek/server-overhaul
Add option to disable serving JS
2 parents 0974b23 + c6b537b commit 3ef0fd1

File tree

6 files changed

+498
-8
lines changed

6 files changed

+498
-8
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ TekstowoAPI.js
22
1TekstowoAPI.js
33
index copy.html
44
notes.txt
5+
/node_modules

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ It currently uses latest build of [Tekstowo-Unofficial-API](https://github.com/D
66
To self host, you need to have Node.js installed (latest LTS recommended).
77
1. Clone this repo
88
2. `cd` to your cloned directory
9-
3. `node server.js`
9+
3. If you want to host with JavaScript disabled, run `node server.js false`, If JS is ok for you, `node server.js`
1010

1111
## Features
1212
- [x] Search bar

main.js

+32-6
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,11 @@ function setupElements() {
125125
// const songSearch = document.getElementById(`songSearch`);
126126
// const artistSearch = document.getElementById(`artistSearch`);
127127
const querySearch = document.getElementById(`querySearch`);
128+
if (window.NO_JS) {
129+
searchButton.remove();
130+
querySearch.remove();
131+
return;
132+
}
128133
searchButton.addEventListener('click', () => {
129134
location.href = (useQuestionMark ? '?' : '') + `${TekstowoAPIInstance.ConstantURLPaths.search},` + querySearch.value.replace(/\s/g, "+") + ".html";
130135
});
@@ -163,6 +168,8 @@ const TekstowoAPIInstance = initializeTekstowo();
163168
*/
164169
function injectComments(postInfo, postType) {
165170
document.getElementsByClassName("comments-section")[0].before(docCreateElement("p", { textContent: "Loaded comments: ", style: "text-align: center;", id: "loadedCommentsCount" }, [docCreateElement("p", { textContent: "0", style: "display: inline;" }), docCreateElement("p", { textContent: `/${postInfo.commentCount}`, style: "display: inline;" })]));
171+
if (window.NO_JS)
172+
return;
166173
document.getElementsByClassName("comments-section")[0].appendChild(docCreateElement("button", {
167174
textContent: "Load comments",
168175
onclick() {
@@ -245,6 +252,8 @@ function loadLyricsViewer(currentUrlInfo) {
245252
}
246253
document.getElementsByClassName("metadata-section")[0].appendChild(newTable);
247254
document.title = lyrics.lyricsName + " - lyrics and translation of the song";
255+
if (window.NO_JS)
256+
window.bridgeTest.finishedDeferred.resolve();
248257
});
249258
});
250259
}
@@ -345,16 +354,23 @@ function loadSearchResults(currentUrlInfo) {
345354
const result = searchResults.pageCount;
346355
for (let i = 0; i < result; i++) {
347356
const newButton = document.createElement('button');
348-
newButton.textContent = i + 1;
349-
newButton.onclick = () => {
350-
location.href = (useQuestionMark ? '?' : '') + `${TekstowoAPIInstance.ConstantURLPaths.search},` + settings.tytul + ",strona," + (i + 1) + ".html";
351-
};
357+
if (!window.NO_JS) {
358+
newButton.textContent = i + 1;
359+
newButton.onclick = () => {
360+
location.href = (useQuestionMark ? '?' : '') + `${TekstowoAPIInstance.ConstantURLPaths.search},` + settings.tytul + ",strona," + (i + 1) + ".html";
361+
};
362+
}
363+
else {
364+
newButton.appendChild(docCreateElement("a", { textContent: i + 1, href: (useQuestionMark ? '?' : '') + `${TekstowoAPIInstance.ConstantURLPaths.search},` + settings.tytul + ",strona," + (i + 1) + ".html" }));
365+
}
352366
if ((i + 1).toString() == settings.strona || (settings.strona == undefined && (i + 1) == 1))
353367
newButton.style.color = "red";
354368
pageSelection.appendChild(newButton);
355369
}
356370
}
357371
document.title = "Search - lyrics and translations";
372+
if (window.NO_JS)
373+
window.bridgeTest.finishedDeferred.resolve();
358374
});
359375
});
360376
}
@@ -501,6 +517,8 @@ function loadArtistSongList(currentUrlInfo) {
501517
}
502518
}
503519
document.title = "Search - lyrics and translations";
520+
if (window.NO_JS)
521+
window.bridgeTest.finishedDeferred.resolve();
504522
});
505523
});
506524
}
@@ -549,6 +567,8 @@ function loadArtistProfile(currentUrlInfo) {
549567
),
550568
)]));
551569
document.title = response.displayName + " - photos, discography";
570+
if (window.NO_JS)
571+
window.bridgeTest.finishedDeferred.resolve();
552572
});
553573
});
554574
}
@@ -588,11 +608,17 @@ function processOperation() {
588608
case TekstowoAPIInstance.ConstantURLPaths.artistProfile:
589609
loadArtistProfile(currentUrl);
590610
break;
591-
case "":
611+
case "": {
612+
if (window.NO_JS)
613+
window.bridgeTest.finishedDeferred.resolve();
592614
break;
593-
default:
615+
}
616+
default: {
594617
alert("Operation (currently) unsupported.");
618+
if (window.NO_JS)
619+
window.bridgeTest.finishedDeferred.resolve();
595620
break;
621+
}
596622
}
597623
}
598624
// eslint-disable-next-line no-unused-vars

package.json

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"name": "TekstowoAlternativeFrontend",
3+
"version": "1.0.0",
4+
"description": "",
5+
"main": "server.js",
6+
"scripts": {
7+
"serveNoJs": "node server.js false",
8+
"serve": "node server.js"
9+
},
10+
"keywords": [],
11+
"author": "",
12+
"license": "ISC",
13+
"dependencies": {
14+
"jsdom": "^24.1.0",
15+
"tekstowo-api": "github:Davilarek/Tekstowo-Unofficial-API"
16+
}
17+
}

0 commit comments

Comments
 (0)