mirror of
https://github.com/nikdoof/ohayodash.git
synced 2025-12-23 06:49:23 +00:00
Use client side rendering
This commit is contained in:
16
ohayodash/static/js/data.js
Normal file
16
ohayodash/static/js/data.js
Normal file
@@ -0,0 +1,16 @@
|
||||
function fetchAndRender (name) {
|
||||
fetch(name + '.json')
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
const mysource = document.getElementById(name + '-template').innerHTML;
|
||||
const mytemplate = Handlebars.compile(mysource);
|
||||
const myresult = mytemplate(data);
|
||||
document.getElementById(name).innerHTML = myresult;
|
||||
});
|
||||
}
|
||||
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
fetchAndRender('apps');
|
||||
fetchAndRender('links');
|
||||
fetchAndRender('providers');
|
||||
});
|
||||
38
ohayodash/static/js/script.js
Normal file
38
ohayodash/static/js/script.js
Normal file
@@ -0,0 +1,38 @@
|
||||
function date() {
|
||||
let currentDate = new Date();
|
||||
let dateOptions = {
|
||||
weekday: "long",
|
||||
year: "numeric",
|
||||
month: "long",
|
||||
day: "numeric"
|
||||
};
|
||||
let date = currentDate.toLocaleDateString("en-GB", dateOptions);
|
||||
document.getElementById("header_date").innerHTML = date;
|
||||
}
|
||||
|
||||
function greet() {
|
||||
let currentTime = new Date();
|
||||
let greet = Math.floor(currentTime.getHours() / 6);
|
||||
let greeting = "こんにちは!";
|
||||
switch (greet) {
|
||||
case 0:
|
||||
greeting = "おやすみなさい!";
|
||||
break;
|
||||
case 1:
|
||||
greeting = "おはようございます!";
|
||||
break;
|
||||
case 2:
|
||||
greeting = "こんにちは!";
|
||||
break;
|
||||
case 3:
|
||||
greeting = "こんばんは!";
|
||||
break;
|
||||
}
|
||||
document.getElementById("header_greet").innerHTML = greeting;
|
||||
document.title = greeting;
|
||||
}
|
||||
|
||||
function loadFunctions() {
|
||||
date();
|
||||
greet();
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
var sindex = 0;
|
||||
var cycle = false;
|
||||
var sengine = "https://www.google.com/?q="; // Default search engine
|
||||
|
||||
function start() {
|
||||
var query = getParameterByName('q');
|
||||
@@ -20,7 +21,30 @@ function handleKeyPress(e) {
|
||||
if (key == 13) { // Search functions
|
||||
search(text);
|
||||
}
|
||||
if (key == 32) { //Space to go to search
|
||||
if (key == 9) { // Tab Completion Functions
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
if (text[0] === ';') {
|
||||
switch (option) {
|
||||
case 't':
|
||||
var streamers = ['admiralbahroo', 'moonmoon_ow', 'witwix'];
|
||||
if (!subtext || cycle) {
|
||||
cycle = true;
|
||||
if (sindex > streamers.length - 1) sindex = 0;
|
||||
document.getElementById("keywords").value = ';t ' + streamers[sindex++];
|
||||
return;
|
||||
}
|
||||
for (var streamer of streamers) {
|
||||
if (subtext === streamer.substr(0, subtext.length)) {
|
||||
document.getElementById("keywords").value = ';t ' + streamer;
|
||||
return;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(key == 32){ //Space to go to search
|
||||
document.getElementById("keywords").focus();
|
||||
}
|
||||
sindex = 0;
|
||||
@@ -28,13 +52,75 @@ function handleKeyPress(e) {
|
||||
}
|
||||
|
||||
function search(text) {
|
||||
if (validURL(text)) {
|
||||
var option = text.substr(1, text.indexOf(' ') - 1) || text.substr(1);
|
||||
var subtext = text.substr(2 + option.length);
|
||||
if (text[0] === '/') {
|
||||
if (text.indexOf(' ') > -1) {
|
||||
switch (option) {
|
||||
case "am":
|
||||
window.location = "https://www.allmusic.com/search/all/" + subtext;
|
||||
break;
|
||||
case "d":
|
||||
window.location = "https://duckduckgo.com/?q=" + subtext;
|
||||
break;
|
||||
case "di":
|
||||
window.location = "https://www.discogs.com/search/?q=" + subtext;
|
||||
break;
|
||||
case "i":
|
||||
window.location = "https://www.imdb.com/find?q=" + subtext;
|
||||
break;
|
||||
case "m":
|
||||
window.location = "https://www.themoviedb.org/search?query=" + subtext;
|
||||
break;
|
||||
case "r":
|
||||
window.location = "https://www.reddit.com/search?q=" + subtext;
|
||||
break;
|
||||
case "q":
|
||||
window.location = "https://www.qwant.com/?q=" + subtext;
|
||||
break;
|
||||
case "so":
|
||||
window.location = "https://soundcloud.com/search?q=" + subtext;
|
||||
break;
|
||||
case "s":
|
||||
window.location = "https://open.spotify.com/search/results/" + subtext;
|
||||
break;
|
||||
case "t":
|
||||
window.location = "https://trakt.tv/search?query=" + subtext;
|
||||
break;
|
||||
case "tv":
|
||||
window.location = "https://www.thetvdb.com/search?query=" + subtext;
|
||||
break;
|
||||
case "y":
|
||||
window.location = "https://www.youtube.com/results?search_query=" + subtext;
|
||||
break;
|
||||
case "g":
|
||||
window.location = "https://www.google.com/?q=" + subtext;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
var option = text.substr(1);
|
||||
switch (option) {
|
||||
case "d":
|
||||
window.location = "https://www.duckduckgo.com";
|
||||
break;
|
||||
case "y":
|
||||
window.location = "https://www.youtube.com";
|
||||
break;
|
||||
case "r":
|
||||
window.location = "https://reddit.com";
|
||||
break;
|
||||
case "s":
|
||||
window.location = "https://open.spotify.com";
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else if (validURL(text)) {
|
||||
if (containsProtocol(text))
|
||||
window.location = text;
|
||||
else
|
||||
window.location = "https://" + text;
|
||||
} else {
|
||||
window.location = "https://www.google.com/search?q=" + text;
|
||||
window.location = sengine + text;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,7 +140,7 @@ function containsProtocol(str) {
|
||||
return !!pattern.test(str);
|
||||
}
|
||||
|
||||
String.prototype.replaceAll = function (search, replacement) {
|
||||
String.prototype.replaceAll = function(search, replacement) {
|
||||
var target = this;
|
||||
return target.split(search).join(replacement);
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user