diff --git a/node_modules/.cache/.eslintcache b/node_modules/.cache/.eslintcache index af35d112..3b5a1751 100644 --- a/node_modules/.cache/.eslintcache +++ b/node_modules/.cache/.eslintcache @@ -1 +1 @@ -[{"/home/seanedmunds/dev/home-page/src/index.js":"1"},{"size":8516,"mtime":1639427704000,"results":"2","hashOfConfig":"3"},{"filePath":"4","messages":"5","errorCount":0,"fatalErrorCount":0,"warningCount":5,"fixableErrorCount":0,"fixableWarningCount":0,"source":"6"},"szjdbt","/home/seanedmunds/dev/home-page/src/index.js",["7","8","9","10","11"],"import React from 'react';\nimport { useState, useEffect } from 'react';\nimport ReactDOM from 'react-dom';\nimport { unstable_createPortal } from 'react-dom';\nimport './index.css';\n\nfunction Homepage() {\n return (\n
\n
\n \n
\n
\n \n
\n
\n \n
\n
\n \n
\n
\n \n
\n
\n \n
\n
\n );\n}\n\nfunction Search() {\n return (\n
\n
\n \n \n
\n
\n )\n}\n\nfunction Header(props) {\n return (\n
\n
\n

{props.greet}

\n
\n
\n

{props.date}

\n \n
\n
\n );\n}\n\nfunction Applications() {\n let appList = getApps();\n var items = [];\n for (var i = 0; i < appList.apps.length; i++) {\n items.push(\n \n );\n }\n return (\n
\n

Applications

\n
\n {items}\n
\n
\n );\n}\n\nfunction App(props) {\n let classType = props.NSFW + \"-content\";\n let hrefUrl = \"https://\" + props.url;\n let iconName = \"mdi-\" + props.icon;\n return (\n
\n \n
\n
\n \n
\n
\n {props.name}\n {props.url}\n
\n
\n
\n
\n );\n}\n\nfunction Bookmarks() {\n let bookmarkList = getLinks();\n var items = [];\n for (var i = 0; i < bookmarkList.bookmarks.length; i++) {\n items.push(\n \n );\n }\n return (\n
\n

Bookmarks

\n \n
\n );\n}\n\nfunction LinkGroups(props) {\n var items = [];\n for (var i = 0; i < props.links.length; i++) {\n items.push(\n \n );\n }\n return (\n \n );\n}\n\nfunction LinkItem(props) {\n return (\n
\n {props.link.name}\n
\n );\n}\n\nfunction ModalMenu() {\n var providers = getProviders();\n var items = [];\n for (var i = 0; i < providers.providers.length; i++) {\n items.push(\n \n );\n }\n return (\n
\n
\n
\n

Options

\n \n \n \n
\n\n

Color themes

\n\n
\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
\n\n\n

Search options

\n
\n \n \n \n \n \n \n {items}\n \n
WebsitePrefix
\n
\n\n
\n \n \n
\n
\n
\n
\n
\n );\n}\n\nfunction Provider(props) {\n console.log(props);\n return (\n \n {props.provider.name}\n {props.provider.prefix}\n \n );\n}\n\nfunction ModalInit() {\n return (\n
\n \n \n \n
\n );\n}\n\nReactDOM.render(\n ,\n document.getElementById('root')\n);\n\n//Functions below this line are for calculating data for\n//other functions\n\nfunction date() {\n let currentDate = new Date();\n let dateOptions = {\n weekday: \"long\",\n year: \"numeric\",\n month: \"long\",\n day: \"numeric\"\n };\n let date = currentDate.toLocaleDateString(\"en-GB\", dateOptions);\n return date;\n}\nfunction fixDigits(k) {\n if (k < 10) {\n return \"0\" + k;\n }\n else {\n return k;\n }\n}\nfunction greet() {\n let currentTime = new Date();\n let greet = Math.floor(currentTime.getHours() / 6);\n let easterEggChance = Math.floor(Math.random() * 100);\n let greetings = require('./messages.json');\n let timeBased = [];\n let easterEggs = [];\n for (var i = 0; i < greetings.messages.length; i++) {\n if (greetings.messages[i].easteregg == \"FALSE\") {\n timeBased = timeBased.concat(greetings.messages[i]);\n } else {\n easterEggs = easterEggs.concat(greetings.messages[i]);\n }\n }\n if (easterEggChance > 10) {\n return timeBased[greet].message;\n } else {\n let easterEggText = Math.floor(Math.random() * easterEggs.length);\n return easterEggs[easterEggText].message;\n }\n}\nfunction Clock() {\n const [date, setDate] = useState(new Date());\n\n function refreshClock() {\n setDate(new Date());\n }\n useEffect(() => {\n const timerId = setInterval(refreshClock, 1000);\n return function cleanup() {\n clearInterval(timerId);\n };\n }, []);\n\n var hour = date.getHours();\n var minutes = date.getMinutes();\n var seconds = date.getSeconds();\n var midday = \"AM\";\n midday = (hour >= 12) ? \"PM\" : \"AM\";\n hour = (hour == 0) ? 12 : ((hour > 12) ? (hour - 12) : hour);\n minutes = fixDigits(minutes);\n seconds = fixDigits(seconds);\n let time = hour + \":\" + minutes + \" \" + midday;\n\n return (\n

{time}

\n\n );\n}\nfunction getApps() {\n let applications = require('./apps.json');\n return applications;\n}\nfunction getLinks() {\n let links = require('./links.json');\n return links;\n}\nfunction getProviders() {\n let providers = require('./providers.json');\n return providers;\n}",{"ruleId":"12","severity":1,"message":"13","line":4,"column":10,"nodeType":"14","messageId":"15","endLine":4,"endColumn":31},{"ruleId":"16","severity":1,"message":"17","line":169,"column":11,"nodeType":"18","endLine":169,"endColumn":57},{"ruleId":"19","severity":1,"message":"20","line":275,"column":41,"nodeType":"21","messageId":"22","endLine":275,"endColumn":43},{"ruleId":"19","severity":1,"message":"20","line":306,"column":16,"nodeType":"21","messageId":"22","endLine":306,"endColumn":18},{"ruleId":"12","severity":1,"message":"23","line":308,"column":3,"nodeType":"14","messageId":"15","endLine":308,"endColumn":10},"no-unused-vars","'unstable_createPortal' is defined but never used.","Identifier","unusedVar","jsx-a11y/anchor-is-valid","The href attribute requires a valid value to be accessible. Provide a valid, navigable address as the href value. If you cannot provide a valid href, but still need the element to resemble a link, use a button and change it with appropriate styles. Learn more: https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/blob/HEAD/docs/rules/anchor-is-valid.md","JSXOpeningElement","eqeqeq","Expected '===' and instead saw '=='.","BinaryExpression","unexpected","'seconds' is assigned a value but never used."] \ No newline at end of file +[{"/home/seanedmunds/dev/home-page/src/index.js":"1","/home/seanedmunds/dev/home-page/src/search.js":"2","/home/seanedmunds/dev/home-page/src/themer.js":"3"},{"size":17989,"mtime":1639503841427,"results":"4","hashOfConfig":"5"},{"size":7513,"mtime":1639496882220,"results":"6","hashOfConfig":"5"},{"size":7478,"mtime":1639496786188,"results":"7","hashOfConfig":"5"},{"filePath":"8","messages":"9","errorCount":0,"fatalErrorCount":0,"warningCount":9,"fixableErrorCount":0,"fixableWarningCount":0,"source":null},"szjdbt",{"filePath":"10","messages":"11","errorCount":0,"fatalErrorCount":0,"warningCount":9,"fixableErrorCount":0,"fixableWarningCount":0,"source":null},{"filePath":"12","messages":"13","errorCount":0,"fatalErrorCount":0,"warningCount":1,"fixableErrorCount":0,"fixableWarningCount":0,"source":null},"/home/seanedmunds/dev/home-page/src/index.js",["14","15","16","17","18","19","20","21","22"],"/home/seanedmunds/dev/home-page/src/search.js",["23","24","25","26","27","28","29","30","31"],"/home/seanedmunds/dev/home-page/src/themer.js",["32"],{"ruleId":"33","severity":1,"message":"34","line":186,"column":11,"nodeType":"35","endLine":186,"endColumn":61},{"ruleId":"36","severity":1,"message":"37","line":384,"column":11,"nodeType":"38","messageId":"39","endLine":384,"endColumn":13},{"ruleId":"36","severity":1,"message":"37","line":387,"column":11,"nodeType":"38","messageId":"39","endLine":387,"endColumn":13},{"ruleId":"40","severity":1,"message":"41","line":391,"column":11,"nodeType":"42","messageId":"43","endLine":407,"endColumn":12},{"ruleId":"36","severity":1,"message":"37","line":410,"column":10,"nodeType":"38","messageId":"39","endLine":410,"endColumn":12},{"ruleId":"40","severity":1,"message":"41","line":482,"column":11,"nodeType":"42","messageId":"43","endLine":528,"endColumn":24},{"ruleId":"44","severity":1,"message":"45","line":530,"column":15,"nodeType":"46","messageId":"47","endLine":530,"endColumn":21},{"ruleId":"40","severity":1,"message":"41","line":531,"column":11,"nodeType":"42","messageId":"43","endLine":544,"endColumn":12},{"ruleId":"48","severity":1,"message":"49","line":572,"column":1,"nodeType":"50","messageId":"39","endLine":575,"endColumn":2},{"ruleId":"51","severity":1,"message":"52","line":15,"column":10,"nodeType":"46","messageId":"53","endLine":15,"endColumn":24},{"ruleId":"36","severity":1,"message":"37","line":20,"column":13,"nodeType":"38","messageId":"39","endLine":20,"endColumn":15},{"ruleId":"36","severity":1,"message":"37","line":23,"column":13,"nodeType":"38","messageId":"39","endLine":23,"endColumn":15},{"ruleId":"40","severity":1,"message":"41","line":27,"column":13,"nodeType":"42","messageId":"43","endLine":43,"endColumn":14},{"ruleId":"36","severity":1,"message":"37","line":46,"column":12,"nodeType":"38","messageId":"39","endLine":46,"endColumn":14},{"ruleId":"40","severity":1,"message":"41","line":118,"column":13,"nodeType":"42","messageId":"43","endLine":164,"endColumn":14},{"ruleId":"44","severity":1,"message":"45","line":166,"column":17,"nodeType":"46","messageId":"47","endLine":166,"endColumn":23},{"ruleId":"40","severity":1,"message":"41","line":167,"column":13,"nodeType":"42","messageId":"43","endLine":180,"endColumn":14},{"ruleId":"48","severity":1,"message":"49","line":208,"column":1,"nodeType":"50","messageId":"39","endLine":211,"endColumn":2},{"ruleId":"40","severity":1,"message":"41","line":44,"column":9,"nodeType":"42","messageId":"43","endLine":230,"endColumn":10},"jsx-a11y/anchor-is-valid","The href attribute requires a valid value to be accessible. Provide a valid, navigable address as the href value. If you cannot provide a valid href, but still need the element to resemble a link, use a button and change it with appropriate styles. Learn more: https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/blob/HEAD/docs/rules/anchor-is-valid.md","JSXOpeningElement","eqeqeq","Expected '===' and instead saw '=='.","BinaryExpression","unexpected","default-case","Expected a default case.","SwitchStatement","missingDefaultCase","no-redeclare","'option' is already defined.","Identifier","redeclared","no-extend-native","String prototype is read only, properties should not be added.","AssignmentExpression","no-unused-vars","'handleKeyPress' is defined but never used.","unusedVar"] \ No newline at end of file diff --git a/src/index.js b/src/index.js index 7967c04f..5173d687 100644 --- a/src/index.js +++ b/src/index.js @@ -1,12 +1,29 @@ import React from 'react'; import { useState, useEffect } from 'react'; import ReactDOM from 'react-dom'; -import { unstable_createPortal } from 'react-dom'; +//import { unstable_createPortal } from 'react-dom'; import './index.css'; +const setValueFromLocalStorage = property => { + let value = localStorage.getItem(property); + setValue(property, value); +}; +const setValue = (property, value) => { + if (value) { + document.documentElement.style.setProperty(`--${property}`, value); + + const input = document.querySelector(`#${property}`); + if (input) { + value = value.replace('px', ''); + input.value = value; + } + } +}; + function Homepage() { + setTheme(); return ( -
+
@@ -35,9 +52,9 @@ function Homepage() { function Search() { return ( ) @@ -82,17 +99,17 @@ function Applications() { } function App(props) { - let classType = props.NSFW + "-content"; + let classNameType = props.NSFW + "-content"; let hrefUrl = "https://" + props.url; let iconName = "mdi-" + props.icon; return (
- -
-
- + +
+
+
-
+
{props.name} {props.url}
@@ -145,7 +162,7 @@ function LinkGroups(props) { function LinkItem(props) { return (
); } @@ -166,30 +183,30 @@ function ModalMenu() {

Color themes

@@ -207,10 +224,10 @@ function ModalMenu() {
@@ -218,7 +235,6 @@ function ModalMenu() { } function Provider(props) { - console.log(props); return ( {props.provider.name} @@ -230,8 +246,8 @@ function Provider(props) { function ModalInit() { return ( ); @@ -272,7 +288,7 @@ function greet() { let timeBased = []; let easterEggs = []; for (var i = 0; i < greetings.messages.length; i++) { - if (greetings.messages[i].easteregg == "FALSE") { + if (greetings.messages[i].easteregg === "FALSE") { timeBased = timeBased.concat(greetings.messages[i]); } else { easterEggs = easterEggs.concat(greetings.messages[i]); @@ -300,12 +316,12 @@ function Clock() { var hour = date.getHours(); var minutes = date.getMinutes(); - var seconds = date.getSeconds(); + //var seconds = date.getSeconds(); var midday = "AM"; midday = (hour >= 12) ? "PM" : "AM"; - hour = (hour == 0) ? 12 : ((hour > 12) ? (hour - 12) : hour); + hour = (hour === 0) ? 12 : ((hour > 12) ? (hour - 12) : hour); minutes = fixDigits(minutes); - seconds = fixDigits(seconds); + //seconds = fixDigits(seconds); let time = hour + ":" + minutes + " " + midday; return ( @@ -324,4 +340,236 @@ function getLinks() { function getProviders() { let providers = require('./providers.json'); return providers; -} \ No newline at end of file +} +function getThemes() { + let themes = require('./themes.json'); + return themes; +} + +function updateTheme(e) { + var themes = getThemes(); + var themeName = e.target.innerHTML.toLowerCase(); + var index = themes.themes.findIndex(function(item, i){ + return item.name === themeName + }); + console.log(themes.themes[index]); + localStorage.setItem("image-background", themes.themes[index].imagebackground); + localStorage.setItem("color-background", themes.themes[index].colorbackground); + localStorage.setItem("color-search-background", themes.themes[index].colorserachbackground); + localStorage.setItem("color-text-pri",themes.themes[index].colortextpri); + localStorage.setItem("color-text-acc", themes.themes[index].colortextacc); + localStorage.setItem("color-border", themes.themes[index].colorborder); + + //document.documentElement.style.setProperty(prop, `var(--${themeName}${prop.substring(10)})`); + setTheme(); +} + +function setTheme() { + setValueFromLocalStorage('image-background'); + setValueFromLocalStorage('color-background'); + setValueFromLocalStorage('color-search-background'); + setValueFromLocalStorage('color-text-pri'); + setValueFromLocalStorage('color-text-acc'); + setValueFromLocalStorage('color-border'); + setValueFromLocalStorage('content-display'); +} + +function handleKeyPress(e) { + var sindex = 0; + var cycle = false; + var key = e.keyCode || e.which; + var text = e.target.value.replaceAll("+", "%2B"); + var option = text.substr(1, text.indexOf(' ') - 1) || text.substr(1); + var subtext = text.substr(2 + option.length); + if (key == 13) { // Search functions + search(text); + } + 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 +updateLabel(text); + } + sindex = 0; + cycle = false; + updateLabel(text); +} + +function updateLabel(text) { + var option = text.substr(1, text.indexOf(' ') - 1) || text.substr(1); + if (text[0] === '/') { +// if (text.indexOf(' ') > -1) { + switch (option) { + case "am": + document.getElementById("searchType").innerHTML = "Allmusic search"; + break; + case "d": + document.getElementById("searchType").innerHTML = "Duck Duck Go search"; + break; + case "di": + document.getElementById("searchType").innerHTML = "Discogs search"; + break; + case "i": + document.getElementById("searchType").innerHTML = "IMDB search"; + break; + case "m": + document.getElementById("searchType").innerHTML = "TheMovieDB search"; + break; + case "r": + document.getElementById("searchType").innerHTML = "Reddit search"; + break; + case "q": + document.getElementById("searchType").innerHTML = "Qwant search"; + break; + case "so": + document.getElementById("searchType").innerHTML = "Soundcloud search"; + break; + case "s": + document.getElementById("searchType").innerHTML = "Spotify search"; + break; + case "tv": + document.getElementById("searchType").innerHTML = "TheTVDB search"; + break; + case "t": + document.getElementById("searchType").innerHTML = "Trakt search"; + break; + case "y": + document.getElementById("searchType").innerHTML = "YouTube search"; + break; + case "w": + document.getElementById("searchType").innerHTML = "Wikipedia search"; + break; + case "p": + document.getElementById("searchType").innerHTML = "Plex search"; + break; + case "rt": + document.getElementById("searchType").innerHTML = "Rotten Tomatoes search"; + break; + default: + document.getElementById("searchType").innerHTML = "Invalid search"; + break; + } +}else { + document.getElementById("searchType").innerHTML = "Google search"; + } +} + +function search(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 "w": + window.location = "https://en.wikipedia.org/w/index.php?search=" + subtext; + break; + case "p": + window.location = "https://app.plex.tv/desktop/#!/search?query=" + subtext; + break; + case "rt": + window.location = "https://www.rottentomatoes.com/search?search=" + 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; + } +} + +// Source: https://stackoverflow.com/questions/5717093/check-if-a-javascript-string-is-a-url +function validURL(str) { + var pattern = new RegExp('^(https?:\\/\\/)?' + // protocol + '((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|' + // domain name + '((\\d{1,3}\\.){3}\\d{1,3}))' + // OR ip (v4) address + '(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*' + // port and path + '(\\?[;&a-z\\d%_.~+=-]*)?' + // query string + '(\\#[-a-z\\d_]*)?$', 'i'); // fragment locator + return !!pattern.test(str); +} + +function containsProtocol(str) { + var pattern = new RegExp('^(https?:\\/\\/){1}.*', 'i'); + return !!pattern.test(str); +} + +String.prototype.replaceAll = function(search, replacement) { + var target = this; + return target.split(search).join(replacement); +}; \ No newline at end of file