Normalize line endings in the repository

parent a2449ead
{
"include": [
"./src/**/*"
],
"compilerOptions": {
"baseUrl": ".",
"paths": {
"pages/*": [
"pages/components/*"
]
}
}
{
"include": [
"./src/**/*"
],
"compilerOptions": {
"baseUrl": ".",
"paths": {
"pages/*": [
"pages/components/*"
]
}
}
}
\ No newline at end of file
This diff is collapsed.
import browser from "webextension-polyfill";
import statsEvents from './stats-events';
/**
* This file defines a function called on extension init which initialize version and check informations
*/
/**
* Returns the week number for this date. dowOffset is the day of week the week
* "starts" on for your locale - it can be from 0 to 6. If dowOffset is 1 (Monday),
* the week returned is the ISO 8601 week number.
* @param int dowOffset
* @return int
*/
Date.prototype.getWeek = function (dowOffset) {
/*getWeek() was developed by Nick Baicoianu at MeanFreePath: http://www.meanfreepath.com */
dowOffset = typeof (dowOffset) == 'int' ? dowOffset : 0; //default dowOffset to zero
var newYear = new Date(this.getFullYear(), 0, 1);
var day = newYear.getDay() - dowOffset; //the day of week the year begins on
day = (day >= 0 ? day : day + 7);
var daynum = Math.floor((this.getTime() - newYear.getTime() -
(this.getTimezoneOffset() - newYear.getTimezoneOffset()) * 60000) / 86400000) + 1;
var weeknum;
//if the year starts before the middle of a week
if (day < 4) {
weeknum = Math.floor((daynum + day - 1) / 7) + 1;
if (weeknum > 52) {
nYear = new Date(this.getFullYear() + 1, 0, 1);
nday = nYear.getDay() - dowOffset;
nday = nday >= 0 ? nday : nday + 7;
/*if the next year starts before the middle of
the week, it is week #1 of that year*/
weeknum = nday < 4 ? 1 : 53;
}
} else {
weeknum = Math.floor((daynum + day - 1) / 7);
}
return weeknum;
}
const getDailyStr = function () {
var d = new Date();
var m = d.getMonth() + 1;
var mstr = "" + m;
if (m < 10) {
mstr = "0" + mstr;
}
var j = d.getDate();
var jstr = "" + j;
if (j < 10) {
jstr = "0" + jstr;
}
return d.getFullYear() + "/" + mstr + "/" + jstr;
}
const getWeeklyStr = function () {
var d = new Date();
var w = d.getWeek();
var wstr = "" + w;
if (w < 10) {
wstr = "0" + wstr;
}
return d.getFullYear() + "/" + wstr;
}
const getMonthlyStr = function () {
var d = new Date();
var m = d.getMonth() + 1;
var mstr = "" + m;
if (m < 10) {
mstr = "0" + mstr;
}
return d.getFullYear() + "/" + mstr;
}
/**
* Initialize AMR version and track version changes
*/
export default function () {
let manifest = browser.runtime.getManifest();
let ancVersion = localStorage["version"];
let curVersion = manifest.version;
let url = manifest.homepage_url;
let beta = false;
//TODO
/*if (url && url.indexOf("gitlab.com") > 0) {
beta = true;
}*/
if (!ancVersion || curVersion !== ancVersion) {
localStorage.version = curVersion;
if (beta) {
statsEvents.trackBeta(curVersion);
} else {
statsEvents.trackInstall(curVersion);
}
}
if (beta) {
browser.browserAction.setTitle({
title: "All Mangas Reader Beta Channel " + curVersion
});
} else {
browser.browserAction.setTitle({
title: "All Mangas Reader " + curVersion
});
}
let dailyStr = getDailyStr();
let weeklyStr = getWeeklyStr();
let monthlyStr = getMonthlyStr();
if (!localStorage["dailyStr"] || localStorage["dailyStr"] != dailyStr) {
statsEvents.trackActive('Day', dailyStr);
localStorage["dailyStr"] = dailyStr;
}
if (!localStorage["weeklyStr"] || localStorage["weeklyStr"] != weeklyStr) {
statsEvents.trackActive('Week', weeklyStr);
localStorage["weeklyStr"] = weeklyStr;
}
if (!localStorage["monthlyStr"] || localStorage["monthlyStr"] != monthlyStr) {
statsEvents.trackActive('Month', monthlyStr);
localStorage["monthlyStr"] = monthlyStr;
}
import browser from "webextension-polyfill";
import statsEvents from './stats-events';
/**
* This file defines a function called on extension init which initialize version and check informations
*/
/**
* Returns the week number for this date. dowOffset is the day of week the week
* "starts" on for your locale - it can be from 0 to 6. If dowOffset is 1 (Monday),
* the week returned is the ISO 8601 week number.
* @param int dowOffset
* @return int
*/
Date.prototype.getWeek = function (dowOffset) {
/*getWeek() was developed by Nick Baicoianu at MeanFreePath: http://www.meanfreepath.com */
dowOffset = typeof (dowOffset) == 'int' ? dowOffset : 0; //default dowOffset to zero
var newYear = new Date(this.getFullYear(), 0, 1);
var day = newYear.getDay() - dowOffset; //the day of week the year begins on
day = (day >= 0 ? day : day + 7);
var daynum = Math.floor((this.getTime() - newYear.getTime() -
(this.getTimezoneOffset() - newYear.getTimezoneOffset()) * 60000) / 86400000) + 1;
var weeknum;
//if the year starts before the middle of a week
if (day < 4) {
weeknum = Math.floor((daynum + day - 1) / 7) + 1;
if (weeknum > 52) {
nYear = new Date(this.getFullYear() + 1, 0, 1);
nday = nYear.getDay() - dowOffset;
nday = nday >= 0 ? nday : nday + 7;
/*if the next year starts before the middle of
the week, it is week #1 of that year*/
weeknum = nday < 4 ? 1 : 53;
}
} else {
weeknum = Math.floor((daynum + day - 1) / 7);
}
return weeknum;
}
const getDailyStr = function () {
var d = new Date();
var m = d.getMonth() + 1;
var mstr = "" + m;
if (m < 10) {
mstr = "0" + mstr;
}
var j = d.getDate();
var jstr = "" + j;
if (j < 10) {
jstr = "0" + jstr;
}
return d.getFullYear() + "/" + mstr + "/" + jstr;
}
const getWeeklyStr = function () {
var d = new Date();
var w = d.getWeek();
var wstr = "" + w;
if (w < 10) {
wstr = "0" + wstr;
}
return d.getFullYear() + "/" + wstr;
}
const getMonthlyStr = function () {
var d = new Date();
var m = d.getMonth() + 1;
var mstr = "" + m;
if (m < 10) {
mstr = "0" + mstr;
}
return d.getFullYear() + "/" + mstr;
}
/**
* Initialize AMR version and track version changes
*/
export default function () {
let manifest = browser.runtime.getManifest();
let ancVersion = localStorage["version"];
let curVersion = manifest.version;
let url = manifest.homepage_url;
let beta = false;
//TODO
/*if (url && url.indexOf("gitlab.com") > 0) {
beta = true;
}*/
if (!ancVersion || curVersion !== ancVersion) {
localStorage.version = curVersion;
if (beta) {
statsEvents.trackBeta(curVersion);
} else {
statsEvents.trackInstall(curVersion);
}
}
if (beta) {
browser.browserAction.setTitle({
title: "All Mangas Reader Beta Channel " + curVersion
});
} else {
browser.browserAction.setTitle({
title: "All Mangas Reader " + curVersion
});
}
let dailyStr = getDailyStr();
let weeklyStr = getWeeklyStr();
let monthlyStr = getMonthlyStr();
if (!localStorage["dailyStr"] || localStorage["dailyStr"] != dailyStr) {
statsEvents.trackActive('Day', dailyStr);
localStorage["dailyStr"] = dailyStr;
}
if (!localStorage["weeklyStr"] || localStorage["weeklyStr"] != weeklyStr) {
statsEvents.trackActive('Week', weeklyStr);
localStorage["weeklyStr"] = weeklyStr;
}
if (!localStorage["monthlyStr"] || localStorage["monthlyStr"] != monthlyStr) {
statsEvents.trackActive('Month', monthlyStr);
localStorage["monthlyStr"] = monthlyStr;
}
}
\ No newline at end of file
import store from '../store';
import iconHelper from './icon-helper';
/**
* This class is used to update periodically manga chapters lists and mirrors list
*/
class Updater {
/**
* Initialize refresh checkers
*/
load() {
this.checkChaptersUpdates();
this.checkMirrorsUpdates();
}
/**
* Check if we need to refresh chapters lists according to frequency every minutes
*/
checkChaptersUpdates() {
let lastUpdt = store.state.options.lastChaptersUpdate;
let frequency = store.state.options.updatechap;
if (lastUpdt + frequency < Date.now()) {
// time to refresh !
store.dispatch("updateChaptersLists", {force: false}); // force to false to avoid updating if not necessary
}
setTimeout(this.checkChaptersUpdates.bind(this), 60 * 1000); // check every minutes
}
/**
* Check if we need to refresh mirrors lists according to frequency every minutes
*/
checkMirrorsUpdates() {
let lastUpdt = store.state.options.lastMirrorsUpdate;
let frequency = store.state.options.updatemg;
if (lastUpdt + frequency < Date.now()) {
// time to refresh !
store.dispatch("updateMirrorsLists");
}
setTimeout(this.checkMirrorsUpdates.bind(this), 60 * 1000); // check every minutes
}
/**
* Refresh badge and icon
*/
refreshBadgeAndIcon() {
let nbnew = store.getters.nbNewMangas;
if (store.state.options.nocount == 1) {
iconHelper.resetBadge(); // remove badge
// display a grey badge if no new mangas
if (nbnew > 0) iconHelper.resetIcon();
else iconHelper.setBWIcon();
} else {
iconHelper.resetIcon();
if (store.state.options.displayzero === 1) {
iconHelper.updateBadge(nbnew);
} else {
if (nbnew == 0) iconHelper.resetBadge();
else iconHelper.updateBadge(nbnew);
}
}
}
}
import store from '../store';
import iconHelper from './icon-helper';
/**
* This class is used to update periodically manga chapters lists and mirrors list
*/
class Updater {
/**
* Initialize refresh checkers
*/
load() {
this.checkChaptersUpdates();
this.checkMirrorsUpdates();
}
/**
* Check if we need to refresh chapters lists according to frequency every minutes
*/
checkChaptersUpdates() {
let lastUpdt = store.state.options.lastChaptersUpdate;
let frequency = store.state.options.updatechap;
if (lastUpdt + frequency < Date.now()) {
// time to refresh !
store.dispatch("updateChaptersLists", {force: false}); // force to false to avoid updating if not necessary
}
setTimeout(this.checkChaptersUpdates.bind(this), 60 * 1000); // check every minutes
}
/**
* Check if we need to refresh mirrors lists according to frequency every minutes
*/
checkMirrorsUpdates() {
let lastUpdt = store.state.options.lastMirrorsUpdate;
let frequency = store.state.options.updatemg;
if (lastUpdt + frequency < Date.now()) {
// time to refresh !
store.dispatch("updateMirrorsLists");
}
setTimeout(this.checkMirrorsUpdates.bind(this), 60 * 1000); // check every minutes
}
/**
* Refresh badge and icon
*/
refreshBadgeAndIcon() {
let nbnew = store.getters.nbNewMangas;
if (store.state.options.nocount == 1) {
iconHelper.resetBadge(); // remove badge
// display a grey badge if no new mangas
if (nbnew > 0) iconHelper.resetIcon();
else iconHelper.setBWIcon();
} else {
iconHelper.resetIcon();
if (store.state.options.displayzero === 1) {
iconHelper.updateBadge(nbnew);
} else {
if (nbnew == 0) iconHelper.resetBadge();
else iconHelper.updateBadge(nbnew);
}
}
}
}
export default (new Updater)
\ No newline at end of file
import browser from "webextension-polyfill";
/**
* To reduce code size of i18n
* @param {*} message
* @param {*} args
*/
export default function(message, ...args) {
return browser.i18n.getMessage(message, [...args]);
import browser from "webextension-polyfill";
/**
* To reduce code size of i18n
* @param {*} message
* @param {*} args
*/
export default function(message, ...args) {
return browser.i18n.getMessage(message, [...args]);
}
\ No newline at end of file
import browser from "webextension-polyfill";
import * as utils from "./utils";
import store from "../store";
import amrUpdater from "./amr-updater";
/**
* Class used to change AMR icon
*/
class IconHelper {
/**
* Initialize canvas to draw icon on chrome which does not support animated svg as icon
*/
constructor() {
// We spin the sharingan programmatically even in Firefox (which supports animated svg) because this way, we can pass from grey to colored sharingan smoothly and stop the spinning properly
//if (!utils.isFirefox()) {
this.doEase = true;
this.canvas = document.createElement('canvas');
this.canvas.width = '32';
this.canvas.height = '32';
this.canvasContext = this.canvas.getContext('2d');
this.animationFrames = 20;
this.animationSpeed = 50;
this.rotation = 0;
this.icon = document.createElement('img');
this.icon.src = '/icons/icon_32.png';
this.icon_bw = document.createElement('img');
this.icon_bw.src = '/icons/icon_32_bw.png';
//}
this.requireStop = false;
this.spinning = false;
}
updateBadge(nb) {
browser.browserAction.setBadgeText({text: ""+nb});
if (nb === 0) {
//set grey background
browser.browserAction.setBadgeBackgroundColor({color:"#aaaaaa"});
} else {
//set red background
browser.browserAction.setBadgeBackgroundColor({color:"red"});
}
}
resetBadge() {
browser.browserAction.setBadgeText({text: ""});
}
/**
* Set AMR icon to blue sharingan
*/
setBlueIcon() {
if (this.spinning) return;
browser.browserAction.setIcon({ path: "/icons/icon_32_blue.png" });
}
/**
* Set AMR icon to grayscale sharingan
*/
setBWIcon() {
if (this.spinning) return;
browser.browserAction.setIcon({ path: "/icons/icon_32_bw.png" });
}
/**
* Set AMR icon to default sharingan
*/
resetIcon() {
if (this.spinning) return;
browser.browserAction.setIcon({ path: "/icons/icon_32.png" });
}
/**
* Set AMR icon to spinning sharingan (normal or grayscale depending on options)
*/
spinIcon() {
// Let's do it the chrome way, it's smoother.
//if (!utils.isFirefox()) {
// chrome does not support animated svg as icon
this.waitSpinning();
this.spinning = true;
/*} else {
if (store.state.options.nocount == 1 && !store.getters.hasNewMangas) {
browser.browserAction.setIcon({ path: "/icons/icon_32_bw.svg" });
} else {
browser.browserAction.setIcon({ path: "/icons/icon_32.svg" });
}
}*/
}
/**
* Stop the spinning
*/
stopSpinning() {
this.requireStop = true;
}
/**
* Draw spinning sharingan on chrome
* @param {*} doEase
*/
drawIconAtRotation(doEase) {
if (doEase == undefined) {
doEase = false;
}
this.canvasContext.save();
this.canvasContext.clearRect(0, 0, this.canvas.width, this.canvas.height);
this.canvasContext.translate(this.canvas.width / 2, this.canvas.height / 2);
this.canvasContext.rotate(2 * Math.PI * (doEase ? this.ease(this.rotation) : this.rotation));
if (store.state.options.nocount == 1 && !store.getters.hasNewMangas) {
this.canvasContext.drawImage(this.icon_bw, -this.canvas.width / 2, -this.canvas.height / 2);
} else {
this.canvasContext.drawImage(this.icon, -this.canvas.width / 2, -this.canvas.height / 2);
}
this.canvasContext.restore();
browser.browserAction.setIcon({
imageData: this.canvasContext.getImageData(0, 0, this.canvas.width, this.canvas.height)
});
}
/**
* Animation loop
*/
waitSpinning() {
this.rotation += 1 / this.animationFrames;
if (this.rotation > 1) {
// stop the rotation once the turn is over
if (this.requireStop) {
this.requireStop = false;
this.spinning = false;
// update the badge and icon one last time
amrUpdater.refreshBadgeAndIcon();
return;
}
this.rotation = this.rotation - 1;
this.doEase = false;
}
this.drawIconAtRotation(false);
setTimeout(this.waitSpinning.bind(this), this.animationSpeed);
}
/**
* Ease for rotation
* @param {*} x
*/
ease(x) {
return (1 - Math.sin(Math.PI / 2 + x * Math.PI)) / 2;
}
}
import browser from "webextension-polyfill";
import * as utils from "./utils";
import store from "../store";
import amrUpdater from "./amr-updater";
/**
* Class used to change AMR icon
*/
class IconHelper {
/**
* Initialize canvas to draw icon on chrome which does not support animated svg as icon
*/
constructor() {
// We spin the sharingan programmatically even in Firefox (which supports animated svg) because this way, we can pass from grey to colored sharingan smoothly and stop the spinning properly
//if (!utils.isFirefox()) {
this.doEase = true;
this.canvas = document.createElement('canvas');
this.canvas.width = '32';
this.canvas.height = '32';
this.canvasContext = this.canvas.getContext('2d');
this.animationFrames = 20;
this.animationSpeed = 50;
this.rotation = 0;
this.icon = document.createElement('img');
this.icon.src = '/icons/icon_32.png';
this.icon_bw = document.createElement('img');
this.icon_bw.src = '/icons/icon_32_bw.png';
//}
this.requireStop = false;
this.spinning = false;
}
updateBadge(nb) {
browser.browserAction.setBadgeText({text: ""+nb});
if (nb === 0) {
//set grey background
browser.browserAction.setBadgeBackgroundColor({color:"#aaaaaa"});
} else {
//set red background
browser.browserAction.setBadgeBackgroundColor({color:"red"});
}
}
resetBadge() {
browser.browserAction.setBadgeText({text: ""});
}
/**
* Set AMR icon to blue sharingan
*/
setBlueIcon() {
if (this.spinning) return;
browser.browserAction.setIcon({ path: "/icons/icon_32_blue.png" });
}
/**
* Set AMR icon to grayscale sharingan
*/
setBWIcon() {
if (this.spinning) return;
browser.browserAction.setIcon({ path: "/icons/icon_32_bw.png" });
}
/**
* Set AMR icon to default sharingan
*/
resetIcon() {
if (this.spinning) return;
browser.browserAction.setIcon({ path: "/icons/icon_32.png" });
}
/**
* Set AMR icon to spinning sharingan (normal or grayscale depending on options)
*/
spinIcon() {
// Let's do it the chrome way, it's smoother.
//if (!utils.isFirefox()) {
// chrome does not support animated svg as icon
this.waitSpinning();
this.spinning = true;
/*} else {
if (store.state.options.nocount == 1 && !store.getters.hasNewMangas) {
browser.browserAction.setIcon({ path: "/icons/icon_32_bw.svg" });
} else {
browser.browserAction.setIcon({ path: "/icons/icon_32.svg" });
}
}*/
}
/**
* Stop the spinning
*/
stopSpinning() {
this.requireStop = true;
}
/**
* Draw spinning sharingan on chrome
* @param {*} doEase
*/
drawIconAtRotation(doEase) {
if (doEase == undefined) {
doEase = false;
}
this.canvasContext.save();
this.canvasContext.clearRect(0, 0, this.canvas.width, this.canvas.height);
this.canvasContext.translate(this.canvas.width / 2, this.canvas.height / 2);
this.canvasContext.rotate(2 * Math.PI * (doEase ? this.ease(this.rotation) : this.rotation));
if (store.state.options.nocount == 1 && !store.getters.hasNewMangas) {
this.canvasContext.drawImage(this.icon_bw, -this.canvas.width / 2, -this.canvas.height / 2);
} else {
this.canvasContext.drawImage(this.icon, -this.canvas.width / 2, -this.canvas.height / 2);
}
this.canvasContext.restore();
browser.browserAction.setIcon({
imageData: this.canvasContext.getImageData(0, 0, this.canvas.width, this.canvas.height)
});
}
/**
* Animation loop
*/
waitSpinning() {
this.rotation += 1 / this.animationFrames;
if (this.rotation > 1) {
// stop the rotation once the turn is over
if (this.requireStop) {
this.requireStop = false;
this.spinning = false;
// update the badge and icon one last time
amrUpdater.refreshBadgeAndIcon();
return;
}
this.rotation = this.rotation - 1;
this.doEase = false;
}