From 3ec6522e535079d17ce36107e97c389a2685f10d Mon Sep 17 00:00:00 2001 From: Dmitry Date: Wed, 13 Mar 2019 13:20:25 +0500 Subject: [PATCH 1/6] Changed the link for js-yaml lib Because [RawGit](https://rawgit.com) will close soon. --- src/js/translate.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/js/translate.js b/src/js/translate.js index 772bc8f7..8a4c00b6 100644 --- a/src/js/translate.js +++ b/src/js/translate.js @@ -268,7 +268,7 @@ document.getElementById("upload").onclick = () => { } if (window.location.hash === "#translator-mode") { - loadScript("https://cdn.rawgit.com/nodeca/js-yaml/bee7e998/dist/js-yaml.min.js") + loadScript("https://cdnjs.cloudflare.com/ajax/libs/js-yaml/3.12.2/js-yaml.min.js") .then(() => { formatSelect.disabled = false; }) @@ -277,4 +277,4 @@ if (window.location.hash === "#translator-mode") { formatSelect.value = "json"; document.getElementById("yaml").disabled = true; }); -} \ No newline at end of file +} From 91fc95f16cf5f24b62ca0331256ef98e854eee11 Mon Sep 17 00:00:00 2001 From: Cojam Date: Wed, 13 Mar 2019 14:29:05 +0500 Subject: [PATCH 2/6] Some updates "build" task is fixed, XMLHttpRequest is replaced by fetch --- .gitignore | 3 +++ gulpfile.js | 16 +++++++++++++--- package.json | 3 ++- src/js/script.js | 26 +++++--------------------- src/js/translate.js | 31 +++++++++++++------------------ 5 files changed, 36 insertions(+), 43 deletions(-) diff --git a/.gitignore b/.gitignore index be0cfbb7..e066d942 100644 --- a/.gitignore +++ b/.gitignore @@ -22,6 +22,9 @@ Thumbs.db # NPM packages folder. node_modules/ +package-lock.json +npm-debug.log + # Gulp output folder. dist/ diff --git a/gulpfile.js b/gulpfile.js index e8ca85b0..bfc34b42 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -1,14 +1,20 @@ const util = require("util"); const path = require("path"); -const SRC = "./src"; +const SRC_DIR_NAME = "src"; +const SRC = `./${SRC_DIR_NAME}`; + const DEST = "./dist"; const JS_DIR = path.join(SRC, "js/*.js"); const SCSS_DIR = path.join(SRC, "scss/*.scss"); const HTML_DIR = path.join(SRC, "*.html"); -const ASSETS_DIR = path.join(SRC, "assets/**/*"); -const LOCALES_DIR = path.join(SRC, "locales/*.json"); + +const ASSETS_DIR_NAME = "assets"; +const ASSETS_DIR = path.join(SRC, `${ASSETS_DIR_NAME}/**/*`); + +const LOCALES_DIR_NAME = "locales"; +const LOCALES_DIR = path.join(SRC, `${LOCALES_DIR_NAME}/*.json`); // Polyfill of the future stream.pipeline API // Can be changed when Node 10.0.0 hits LTS @@ -18,6 +24,7 @@ const gulp = require("gulp"); const gulpif = require("gulp-if") const sourcemaps = require("gulp-sourcemaps"); const through = require("through2"); +const rename = require("gulp-rename"); const browserSync = require('browser-sync').create(); @@ -91,6 +98,7 @@ function html() { return pipeline( gulp.src(HTML_DIR), htmlmin({collapseWhitespace: true}), + rename(file => file.dirname = ""), gulp.dest(DEST) ) } @@ -98,6 +106,7 @@ function html() { function assets() { return pipeline( gulp.src(ASSETS_DIR), + rename(file => file.dirname = file.dirname.replace(`${SRC_DIR_NAME}\\${ASSETS_DIR_NAME}\\`, '')), gulp.dest(DEST) ); } @@ -105,6 +114,7 @@ function assets() { function locales() { return pipeline( gulp.src(LOCALES_DIR), + rename(file => file.dirname = file.dirname.replace(`${SRC_DIR_NAME}\\${LOCALES_DIR_NAME}`, '')), gulp.dest(path.join(DEST, "locales")) ); } diff --git a/package.json b/package.json index e89ba07d..ba9d9702 100644 --- a/package.json +++ b/package.json @@ -21,7 +21,7 @@ "@babel/preset-env": "^7.3.1", "autoprefixer": "^9.4.7", "browser-sync": "^2.26.3", - "del": "^3.0.0", + "del": "^4.0.0", "gulp": "^4.0.0", "gulp-babel": "^8.0.0", "gulp-concat": "^2.6.1", @@ -29,6 +29,7 @@ "gulp-htmlmin": "^5.0.1", "gulp-if": "^2.0.2", "gulp-postcss": "^8.0.0", + "gulp-rename": "^1.4.0", "gulp-sourcemaps": "^2.6.4", "gulp-uglify": "^3.0.1", "node-sass": "^4.11.0", diff --git a/src/js/script.js b/src/js/script.js index 1d57da10..953d0e1d 100644 --- a/src/js/script.js +++ b/src/js/script.js @@ -171,7 +171,7 @@ searchbar.onclick = event => { case "search-by-voice": span.innerText = javascriptLocales.searchByVoice; break; - + case "search-button": span.innerText = javascriptLocales.searchButton; break; @@ -253,25 +253,9 @@ document.body.onkeyup = event => { } function getContent(url) { - return new Promise((resolve, reject) => { - let req = new XMLHttpRequest(); - req.open("GET", url, true); - req.onreadystatechange = function () { - if (req.readyState !== 4) return; - - const contentType = req.getResponseHeader("content-type") || ''; - - let res = contentType.startsWith("application/json") ? JSON.parse(req.responseText) : req.responseText; - - if (req.status.toString().startsWith(2)) { - resolve(res); - } else { - reject(res); - } - }; - req.onerror = reject; - req.send(); - }); + return fetch(url, { cache: "no-store" }) + .then(response => response.json()) + .catch(err => console.warn(err)) } function discordInfo(invite) { @@ -305,7 +289,7 @@ function updateCounts() { document.getElementById("reddit-count").style.display = "inline-block"; } - document.getElementById('last-updated').innerText = + document.getElementById('last-updated').innerText = (new Date(1519743162656)) .toLocaleDateString(document.body.parentElement.lang, { year: 'numeric', diff --git a/src/js/translate.js b/src/js/translate.js index 8a4c00b6..8c1f9848 100644 --- a/src/js/translate.js +++ b/src/js/translate.js @@ -108,7 +108,7 @@ function changeLocale(localeName, skipReset) { handleObject(locales[localeName], document.body); window.javascriptLocales = locales[localeName]._javascriptLocales; document.documentElement.lang = localeName; - + if (!skipReset) { if (localeName === defaultLocale) { window.history.pushState('', '', window.location.pathname) @@ -136,20 +136,15 @@ for (const option of options) { } if (option.value !== defaultLocale) { - const xhr = new XMLHttpRequest(); - xhr.open("GET", "locales/" + option.value + ".json", true); - xhr.onreadystatechange = function() { - if (xhr.readyState === 4 && xhr.status === 200) { - var translation = JSON.parse(xhr.responseText); + fetch("locales/" + option.value + ".json", { cache: "no-store" }) + .then(response => response.json()) + .then(translation => { locales[option.value] = translation; option.disabled = false; postDownload(); - } - }; - - xhr.send(); - + }) + .catch(err => console.warn(err)) } else { setTimeout(postDownload); } @@ -187,7 +182,7 @@ document.getElementById("download").onclick = () => { let download = document.createElement("A"), isYAML = formatSelect.value === "yaml"; download.href = URL.createObjectURL(new Blob( - [isYAML ? prettyYAML(jsyaml.safeDump(locales[defaultLocale])) : JSON.stringify(locales[defaultLocale], null, "\t")], + [isYAML ? prettyYAML(jsyaml.safeDump(locales[defaultLocale])) : JSON.stringify(locales[defaultLocale], null, "\t")], { type : isYAML ? " application/x-yaml" : "application/json" } @@ -207,12 +202,12 @@ function selectFile(options = {}) { upload.accept = options.accept || ""; upload.multiple = options.multiple || false; upload.webkitdirectory = options.directory || false; - upload.setAttribute("style", + upload.setAttribute("style", "position:absolute !important;" + - "top:-9999vh !important;" + - "opacity:0 !important;" + - "height:0 !important;" + - "width:0 !important; " + + "top:-9999vh !important;" + + "opacity:0 !important;" + + "height:0 !important;" + + "width:0 !important; " + "z-index:-9999 !important;"); document.body.appendChild(upload); @@ -268,7 +263,7 @@ document.getElementById("upload").onclick = () => { } if (window.location.hash === "#translator-mode") { - loadScript("https://cdnjs.cloudflare.com/ajax/libs/js-yaml/3.12.2/js-yaml.min.js") + loadScript("https://cdn.rawgit.com/nodeca/js-yaml/bee7e998/dist/js-yaml.min.js") .then(() => { formatSelect.disabled = false; }) From bd4f62a07e98a8668cd350dcd6797bb119b866d4 Mon Sep 17 00:00:00 2001 From: Cojam Date: Wed, 13 Mar 2019 14:34:51 +0500 Subject: [PATCH 3/6] Ooops MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ¯\_(ツ)_/¯ --- src/js/translate.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/js/translate.js b/src/js/translate.js index 8c1f9848..027b7d99 100644 --- a/src/js/translate.js +++ b/src/js/translate.js @@ -263,7 +263,7 @@ document.getElementById("upload").onclick = () => { } if (window.location.hash === "#translator-mode") { - loadScript("https://cdn.rawgit.com/nodeca/js-yaml/bee7e998/dist/js-yaml.min.js") + loadScript("https://cdnjs.cloudflare.com/ajax/libs/js-yaml/3.12.2/js-yaml.min.js") .then(() => { formatSelect.disabled = false; }) From 8899c7e795951e91d7a696d45e25d6706e7e4317 Mon Sep 17 00:00:00 2001 From: Cojam Date: Wed, 13 Mar 2019 20:37:27 +0500 Subject: [PATCH 4/6] More some updates Fix previous fix (with build paths issue), added fetch and js-yaml polyfills --- gulpfile.js | 2 +- package.json | 4 +++- src/index.html | 42 +++++++++++++++++++++--------------------- src/js/script.js | 1 + src/js/translate.js | 25 ++----------------------- 5 files changed, 28 insertions(+), 46 deletions(-) diff --git a/gulpfile.js b/gulpfile.js index bfc34b42..24ecfbc4 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -106,7 +106,7 @@ function html() { function assets() { return pipeline( gulp.src(ASSETS_DIR), - rename(file => file.dirname = file.dirname.replace(`${SRC_DIR_NAME}\\${ASSETS_DIR_NAME}\\`, '')), + rename(file => file.dirname = file.dirname.replace(`${SRC_DIR_NAME}\\${ASSETS_DIR_NAME}`, '')), gulp.dest(DEST) ); } diff --git a/package.json b/package.json index ba9d9702..2ceabbde 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,9 @@ "babel-polyfill": "^6.26.0", "fluent-langneg": "^0.1.1", "gulp-sass": "^4.0.2", - "howler": "^2.1.1" + "howler": "^2.1.1", + "js-yaml": "^3.12.2", + "whatwg-fetch": "^3.0.0" }, "devDependencies": { "@babel/core": "^7.0.0", diff --git a/src/index.html b/src/index.html index 2f1a2976..28cb5c35 100644 --- a/src/index.html +++ b/src/index.html @@ -124,7 +124,7 @@

Satania

胡桃沢=サタニキア=マクドウェル

The best Waifu. Ever.

- +
Join the Discord
@@ -132,26 +132,26 @@

The best Waifu. Ever.

members
- + Join the Subreddit
subscribers
- +
- + (These communities use English as their primary language)
- + Scroll to learn more! - +

I am really sorry, but the mobile version of this website was kinda rushed and it's really shit, I didn't think anyone would visit it on a phone tbh.

- +
@@ -159,7 +159,7 @@

The best Waifu. Ever.

Would you like to view this website in English?
Use this drop-down to select a language!
- +
@@ -190,23 +190,23 @@

The best Waifu. Ever.

- +
- - +
- + - + - +
@@ -228,7 +228,7 @@

The best Waifu. Ever.

- +
@@ -247,14 +247,14 @@

The best Waifu. Ever.

- +
- +

You can also listen on YouTube and SoundCloud.

@@ -264,7 +264,7 @@

The best Waifu. Ever.

- +
@@ -661,7 +661,7 @@

She replaces all the other waifus in the show

- +
- +
- +