Skip to content
This repository was archived by the owner on Mar 16, 2021. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
node_modules
wikia-gif-avatar-*
releases
releases/*.zip
releases/wikia-nitro-*
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# Wikia Nitro
Application for setting GIF avatars on [Wikia](https://c.wikia.com). Documentation is available [here](https://dev.wikia.com/wiki/Nitro). See also [Saektide's version](https://github.com/Saektide/wikia-nitro).
Application for setting GIF avatars on [Fandom](https://community.fandom.com). Documentation is available [here](https://dev.fandom.com/wiki/Nitro). See also [Saektide's version](https://github.com/Saektide/wikia-nitro).
5 changes: 3 additions & 2 deletions i18n/_list.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"pl": "Polski",
"ru": "Русский",
"sr": "Српски",
"uk": "Українська"
"uk": "Українська",
"zh-hans": "简体中文",
"zh-hant": "繁體中文"
}

1 change: 0 additions & 1 deletion i18n/be.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,3 @@
"upload-lstat": "Не атрымалася вызначыць памер аватара.",
"upload-unknown": "Пры загрузцы аватара адбылася невядомая абмыла."
}

1 change: 0 additions & 1 deletion i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,3 @@
"upload-lstat": "Failed to determine size of avatar.",
"upload-unknown": "An unknown error occurred while uploading the avatar."
}

1 change: 0 additions & 1 deletion i18n/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,3 @@
"upload-lstat": "No pudo determinar el tamaño del avatar.",
"upload-unknown": "Un error desconocido ocurrió durante la subida del avatar."
}

1 change: 0 additions & 1 deletion i18n/pl.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,3 @@
"upload-lstat": "Nie udało się ustalić rozmiaru awataru.",
"upload-unknown": "Podczas przesyłania awataru wystąpił nieznany błąd."
}

1 change: 0 additions & 1 deletion i18n/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,3 @@
"upload-lstat": "Не удалось определить размер аватара.",
"upload-unknown": "При загрузке аватара произошла неизвестная ошибка."
}

1 change: 0 additions & 1 deletion i18n/sr.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,3 @@
"upload-lstat": "Неуспешно одређивање величине аватара.",
"upload-unknown": "Десила се непозната грешка приликом отпремања аватара."
}

1 change: 0 additions & 1 deletion i18n/uk.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,3 @@
"upload-lstat": "Не вдалося визначити розмір аватара.",
"upload-unknown": "Під час завантаження аватара сталася невідома помилка."
}

21 changes: 21 additions & 0 deletions i18n/zh-hans.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"language": "简体中文",
"name": "Wikia Nitro",
"logo": "时机已到,每个人都有GIF头像!",
"login": "登录",
"logout": "登出",
"username": "用户名",
"password": "密码",
"filetype": "GIF图片",
"select": "选择",
"upload": "上传",
"upload-header": "上传头像",
"login-success": "登录成功!",
"login-badpass": "用户名或密码错误!",
"login-unknown": "登录时发生未知错误。",
"login-auto": "自动登录!",
"upload-success": "头像上传成功!",
"upload-badsize": "头像大小超过512kb或不是方形。",
"upload-lstat": "无法确定头像大小。",
"upload-unknown": "上传头像时发生未知错误。"
}
21 changes: 21 additions & 0 deletions i18n/zh-hant.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"language": "繁體中文",
"name": "Wikia Nitro",
"logo": "時機已到,每個人都有GIF頭像!",
"login": "登錄",
"logout": "登出",
"username": "用戶名",
"password": "密碼",
"filetype": "GIF圖片",
"select": "選擇",
"upload": "上傳",
"upload-header": "上傳頭像",
"login-success": "登錄成功!",
"login-badpass": "用戶名或密碼錯誤!",
"login-unknown": "登錄時發生未知錯誤。",
"login-auto": "自動登錄!",
"upload-success": "頭像上傳成功!",
"upload-badsize": "頭像大小超過512kb或不是方形。",
"upload-lstat": "無法確定頭像大小。",
"upload-unknown": "上傳頭像時發生未知錯誤。"
}
74 changes: 37 additions & 37 deletions js/main.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/**
* main.js
*
* Main JS file of Nitro
* Main JS file of Nitro.
*/
'use strict';

/**
* Importing modules
* Importing modules.
*/
const http = require('request-promise-native'),
fs = require('fs'),
Expand All @@ -15,19 +15,19 @@ const http = require('request-promise-native'),
langs = require('./i18n/_list.json');

/**
* Constants
* Constants.
*/
const jar = http.jar(),
statuses = {};

/**
* Variables
* Variables.
*/
let userId, loginForm, uploadForm, spinner, avatarFile, uploading, avatarSize,
progress, i18n, autoLogin = true;

/**
* Sends an HTTP request to Service API
* Sends an HTTP request to Service API.
* @param {String} path Path to request
* @param {String} method HTTP method to use
* @param {Object} form Form data to send
Expand All @@ -43,27 +43,27 @@ function request(path, method, form) {
jar,
json: !form,
method,
uri: `https://services.wikia.com/${path}`
uri: `https://services.fandom.com/${path}`
});
}

/**
* Shows the WDS spinner
* Shows the WDS spinner.
*/
function showSpinner() {
spinner.classList.remove('hidden');
progress.textContent = '';
}

/**
* Hides the WDS spinner
* Hides the WDS spinner.
*/
function hideSpinner() {
spinner.classList.add('hidden');
}

/**
* Shorthand function for getting an element based on its ID
* Shorthand function for getting an element based on its ID.
* @param {String} i ID of the element
* @returns {Node} Element with the given ID
*/
Expand All @@ -72,7 +72,7 @@ function id(i) {
}

/**
* Puts an notice below a form
* Puts an notice below a form.
* @param {String} form Form below which to put the notice
* @param {String} status "error" or "success" notice type
* @param {String} text I18n key of the string to put
Expand All @@ -85,7 +85,7 @@ function notice(form, status, text) {
}

/**
* Switches to upload mode
* Switches to upload mode.
*/
function setUpload() {
['username', 'password'].forEach(function(el) {
Expand All @@ -96,7 +96,7 @@ function setUpload() {
}

/**
* Callback after finding user's ID through the Service API
* Callback after finding user's ID through the Service API.
* @param {Object} d Data returned by the Service API
*/
function cbWhoami(d) {
Expand All @@ -108,30 +108,30 @@ function cbWhoami(d) {
}

/**
* Callback after finding user's ID failed
* Callback after finding user's ID failed.
* @param {Error} error HTTP error that occurred
*/
function errWhoami(error) {
if (error.statusCode !== 401) {
// Unknwon error
console.log(error);
// Unknown error.
console.error(error);
}
}

/**
* Sets the access_token cookie
* Sets the access_token cookie.
* @param {String} token Access token to set
*/
function setCookie(token) {
const date = new Date();
date.setFullYear(date.getFullYear() + 10);
jar.setCookie(http.cookie(
`access_token=${token}; Expires=${date.toGMTString()}; Domain=wikia.com; Path=/; HttpOnly; hostOnly=false;`
), 'http://wikia.com');
`access_token=${token}; Expires=${date.toGMTString()}; Domain=fandom.com; Path=/; HttpOnly; hostOnly=false;`
), 'https://fandom.com');
}

/**
* Callback after logging in
* Callback after logging in.
* @param {String} d Login API response
*/
function cbLogin(d) {
Expand All @@ -145,7 +145,7 @@ function cbLogin(d) {
}

/**
* Callback after logging in failed
* Callback after logging in failed.
* @param {Error} error HTTP error that occurred
*/
function errLogin(error) {
Expand All @@ -158,7 +158,7 @@ function errLogin(error) {
}

/**
* Logs the user in
* Logs the user in.
* @param {Event} e DOM event that triggered the login
*/
function login(e) {
Expand All @@ -178,22 +178,22 @@ function login(e) {
}

/**
* Callback after finding avatar's file size
* Callback after finding avatar's file size.
* @param {Error} err Error that occurred
* @param {Number} size Size of the file
*/
function cbLstat(err, {size}) {
if (err) {
notice('upload', 'error', 'upload-lstat');
console.log(err);
console.error(err);
} else {
avatarSize = size;
uploadForm.submit.disabled = false;
}
}

/**
* Shows the upload file dialog
* Shows the upload file dialog.
* @param {Event} e DOM event that triggered enabling of the upload
*/
function setupUpload(e) {
Expand All @@ -213,17 +213,17 @@ function setupUpload(e) {
}

/**
* Callback after uploading the avatar
* Callback after uploading the avatar.
* @param {Object} d Data returned by the upload API
*/
function cbUpload(d) {
hideSpinner();
notice('upload', 'success', 'upload-success');
console.log(d);
console.info(d);
}

/**
* Callback after the upload progresses
* Callback after the upload progresses.
*/
function cbProgress() {
progress.textContent = `${Math.round(
Expand All @@ -232,7 +232,7 @@ function cbProgress() {
}

/**
* Callback after the upload fails
* Callback after the upload fails.
* @param {Error} error HTTP error that occurred
*/
function errUpload(error) {
Expand All @@ -242,11 +242,11 @@ function errUpload(error) {
} else {
notice('upload', 'error', 'upload-unknown');
}
console.log(error);
console.error(error);
}

/**
* Uploads the avatar
* Uploads the avatar.
* @param {Event} e DOM event that triggered the upload
*/
function upload(e) {
Expand All @@ -261,7 +261,7 @@ function upload(e) {
}

/**
* Sets the user's language and updates messages
* Sets the user's language and updates messages.
* @param {String} lang Language to set
*/
function setLanguage(lang) {
Expand All @@ -288,15 +288,15 @@ function setLanguage(lang) {
}

/**
* Event called after a language has been selected
* Event called after a language has been selected.
* @param {ClickEvent} e DOM event that triggered the switch
*/
function selectLang(e) {
setLanguage(e.target.dataset.lang);
}

/**
* Sets up the DOM elements
* Sets up the DOM elements.
*/
function setupDOM() {
loginForm = id('login');
Expand All @@ -315,7 +315,7 @@ function setupDOM() {
}

/**
* Sets up the current language
* Sets up the current language.
*/
function setupLanguage() {
const arr = app.getLocale().split('-');
Expand All @@ -324,7 +324,7 @@ function setupLanguage() {
}

/**
* Sets up the language list
* Sets up the language list.
*/
function setupList() {
const list = document.querySelector('#language > #list > ul');
Expand All @@ -338,7 +338,7 @@ function setupList() {
}

/**
* Sets up the token and continues to find user's ID
* Sets up the token and continues to find user's ID.
*/
function setupToken() {
const token = localStorage.getItem('token');
Expand All @@ -349,7 +349,7 @@ function setupToken() {
}

/**
* Callback after the document loads
* Callback after the document loads.
*/
function onload() {
setupDOM();
Expand Down
Loading