Commit 19b23c2f authored by Duhoux Pierre-Louis's avatar Duhoux Pierre-Louis

Help messages every n chapters

 - Message rate us on firefox every 20 chaps
 - Message patreon amr every 50 chaps
 - Message wow every 1000 chaps
All messages have a do not view anymore button
parent adb4aeb2
......@@ -1443,5 +1443,41 @@
"reader_social_discord": {
"message": "Join our community on Discord ! It's the right place for any question about AMR.",
"description": "Tooltip of the discord button"
},
"reader_help_rate_title": {
"message": "Give us five stars !",
"description": "Title of the rate us dialog, appear once in a while, can stop receiving this dialog"
},
"reader_help_rate_message": {
"message": "You seem to **enjoy reading using All Mangas Reader** ! \n Maintaining and improving your All Mangas Reader experience takes us a lot of time and efforts. That would be nice if you could take a few seconds to give us feedback on **Firefox Addons**. Rate us and leave us a message, that will be really appreciated !\n Click on the _I give feedback now !_ button to go to Firefox Addons ! _(in another tab, we won't spoil your reading, don't worry :))_\n Remember that if you need help or if want to help, you can always join our community on [Discord](https://discord.gg/bdzk9hR) or [help us on Patreon](https://www.patreon.com/allmangasreader) !",
"description": "Message of the rate us dialog, appear once in a while, can stop receiving this dialog"
},
"reader_help_rate_action": {
"message": "I give feedback now !",
"description": "Action button label to go rate us on Firefox addons in the rate us dialog, appear once in a while, can stop receiving this dialog"
},
"reader_help_patreon_title": {
"message": "Help us building All Mangas Reader",
"description": "Title of the help us dialog, appear once in a while, can stop receiving this dialog"
},
"reader_help_patreon_message": {
"message": "You really seem to **enjoy reading using All Mangas Reader** ! \n Maintaining and developing new features to your favorite reader takes a considerable amount of time, and even if the project is open sourced, it is supported by mainly one contributor. We don't need a full time developer on that project but a week per month is a minimum to fix things and create awesome features.\n Click on the _Become a patron_ button to go to our Patreon, giving even little will be greatly appreciated, this helps us a lot ! _(we will open it in another tab, we won't spoil your reading, don't worry :))_\n Remember that if you need help or if want to help, you can always join us on [Discord](https://discord.gg/bdzk9hR) !",
"description": "Message of the help us dialog, appear once in a while, can stop receiving this dialog"
},
"reader_help_patreon_action": {
"message": "Become a patron",
"description": "Action button label to go patreon in the help us dialog, appear once in a while, can stop receiving this dialog"
},
"reader_help_1000_title": {
"message": "You read $1 manga chapters !",
"description": "Title of the help us dialog, appear once in a while, can stop receiving this dialog"
},
"reader_help_1000_message": {
"message": "Wow ! You really **read a lot using All Mangas Reader** ! Already **$1 chapters !** \n We hope that you enjoy this extension, if you do, you can help us by [rating us on Firefox](https://addons.mozilla.org/firefox/addon/all-mangas-reader/) or by [giving us on Patreon](https://www.patreon.com/allmangasreader), every little contributions is really appreciated !\n Remember that if you need help or if want to help, you can always join us on [Discord](https://discord.gg/bdzk9hR) !",
"description": "Message of the help us dialog, appear once in a while, can stop receiving this dialog"
},
"reader_help_stop": {
"message": "Stop showing that",
"description": "Action button label to stop showing help messages"
}
}
......@@ -1439,5 +1439,41 @@
"reader_social_discord": {
"message": "Rejoignez notre communauté sur Discord ! C'est l'endroit idéal si vous avez une question sur AMR.",
"description": "Tooltip of the discord button"
},
"reader_help_rate_title": {
"message": "Donnez nous cinq étoiles !",
"description": "Title of the rate us dialog, appear once in a while, can stop receiving this dialog"
},
"reader_help_rate_message": {
"message": "Vous avez l'air **d'apprécier lire avec All Mangas Reader** ! \n Maintenir et améliorer votre expérience avec All Mangas Reader nous demande beaucoup de temps et d'efforts. Ce serait sympa si vous pouviez prendre quelques secondes pour nous faire un retour sur **Firefox Addons**. Notez nous et laissez nous un message, ça serait vraiment apprécié !\n Cliquez sur le bouton _Je donne mon avis !_ pour aller sur Firefox Addons ! _(dans un nouvel onglet, on ne va pas gacher votre expérience de lecture, ne vous inquietez pas :))_\n Souvenez vous que si vous avez besoin d'aide ou si vous voulez nous aider, vous pouvez rejoindre notre communauté sur [Discord](https://discord.gg/bdzk9hR) ou [nous aider sur Patreon](https://www.patreon.com/allmangasreader) !",
"description": "Message of the rate us dialog, appear once in a while, can stop receiving this dialog"
},
"reader_help_rate_action": {
"message": "Je donne mon avis !",
"description": "Action button label to go rate us on Firefox addons in the rate us dialog, appear once in a while, can stop receiving this dialog"
},
"reader_help_patreon_title": {
"message": "Aidez nous à construire All Mangas Reader",
"description": "Title of the help us dialog, appear once in a while, can stop receiving this dialog"
},
"reader_help_patreon_message": {
"message": "Vous semblez vraiment **apprécier lire avec All Mangas Reader** ! \n Maintenir et développer de nouvelles fonctionalités pour votre lecteur de manga favori nous prend un temps considérable, et, même si le projet est open source, il est principalement supporté par un seul contributeur. Nous n'avons pas besoin d'un développeur à plein temps sur ce projet mais prendre une semaine par mois est un minimum pour résoudre les bugs et créer de nouvelles fonctionalités.\n Cliquez sur _Devenir patron_ pour aller visiter notre Patreon, donner même peu est grandement apprécié, cela nous aide énormément ! _(nous ouvrirons le lien dans un nouvel onglet, on ne va pas gacher votre expérience de lecture, ne vous inquietez pas :))_\n Souvenez vous que si vous avez besoin d'aide ou si vous voulez nous aider, vous pouvez rejoindre notre communauté sur [Discord](https://discord.gg/bdzk9hR) !",
"description": "Message of the help us dialog, appear once in a while, can stop receiving this dialog"
},
"reader_help_patreon_action": {
"message": "Devenir patron",
"description": "Action button label to go patreon in the help us dialog, appear once in a while, can stop receiving this dialog"
},
"reader_help_1000_title": {
"message": "Vous avez lu $1 chapitres !",
"description": "Title of the help us dialog, appear once in a while, can stop receiving this dialog"
},
"reader_help_1000_message": {
"message": "Wow ! Vous lisez vraiment **énormément avec All Mangas Reader** ! Déjà **$1 chapitres !** \n Nous espérons que vous appréciez cette extension, si oui, vous pouvez nous aider en nous [notant sur Firefox](https://addons.mozilla.org/firefox/addon/all-mangas-reader/) ou en [donnant sur Patreon](https://www.patreon.com/allmangasreader), chaque petite contribution est vraiment appréciée !\n Souvenez vous que si vous avez besoin d'aide ou si vous voulez nous aider, vous pouvez rejoindre notre communauté sur [Discord](https://discord.gg/bdzk9hR) !",
"description": "Message of the help us dialog, appear once in a while, can stop receiving this dialog"
},
"reader_help_stop": {
"message": "Arrêter de montrer ça",
"description": "Action button label to stop showing help messages"
}
}
......@@ -46,7 +46,11 @@ class HandleManga {
return Promise.resolve();
}
case "readManga":
//count number of chapters read
let nb = localStorage["nb_read"] ? parseInt(localStorage["nb_read"]) : 1
localStorage["nb_read"] = "" + (nb + 1);
utils.debug("Read manga " + message.url);
// call store method to update reading list appropriately
return store.dispatch('readManga', message);
case "deleteManga":
utils.debug("Delete manga key " + key);
......
......@@ -355,6 +355,7 @@
import pageData from '../content/pagedata';
import options from '../content/options';
import util from "./util";
import * as dialogs from "./dialogs";
import Reader from "./Reader";
import Scan from "./Scan";
......@@ -444,7 +445,9 @@
/** Handle first time reader is opened */
this.handleFirstTime()
/** Handle tips */
this.handleTips()
dialogs.handleTips(this.$refs.wizdialog)
/** Handle help us dialogs once in a while */
dialogs.handleHelps(this.$refs.wizdialog)
// mark manga as read
if (options.markwhendownload === 0) {
......@@ -929,7 +932,7 @@
},
/** Display tips popup */
displayTips() {
this.handleTips(true)
dialogs.handleTips(this.$refs.wizdialog, true)
},
/** Toggle full screen mode */
toggleFullScreen() {
......@@ -953,81 +956,6 @@
}
this.fullscreen = ! this.fullscreen
},
/**
* Display tips
* - user can choose to display tips once a day or to stop it
* - button next go to next tip
* - saves previous tip and user preferences
* - force : force to display the popup (called on tips action button)
* All the tips are retrieved from i18n starting by reader_tips_ followed with numbers starting from 1. Numbers must be consecutive
*/
async handleTips(force = false) {
let display = true
if (!force) {
let lasttime = await util.getStorage("reader_tips_ts")
let stopped = await util.getStorage("reader_tips_stop")
if (stopped) display = false
if (lasttime && Date.now() - parseInt(lasttime) < 24 * 60 * 60 * 1000) {
display = false
}
}
if (force) display = true
if (display) {
let lasttip = await util.getStorage("reader_tips_last")
if (lasttip) lasttip = parseInt(lasttip)
// load tips in i18n
let tips = [], tip
while (tip = this.i18n("reader_tips_" + (tips.length + 1))) {
tips.push(tip)
}
// get the next tip
let nextTip = async () => {
if (!lasttip || lasttip + 1 > tips.length) lasttip = 0
let nxttip = lasttip + 1
await util.setStorage("reader_tips_last", ""+nxttip)
lasttip = nxttip
return tips[nxttip - 1] // lasttip is 1-based, tips array is 0-based
}
// Button to stop displaying tips
let butstop = {
title: this.i18n("reader_tips_stop"),
color: "grey",
click: async ({ agree }) => {
await util.setStorage("reader_tips_stop", "true")
agree()
}
}
let butnexttip = {
title: this.i18n("reader_tips_next"),
color: "primary",
click: async ({ changeMessage }) => {
changeMessage(await nextTip())
}
}
let butnexttomorrow = {
title: this.i18n("reader_tips_next_tomorrow"),
color: "primary",
click: ({ agree }) => {
agree()
}
}
let butclose = {
title: this.i18n("button_close"),
color: "grey",
click: ({ agree }) => {
agree()
}
}
let ntip = await nextTip()
await this.$refs.wizdialog.open(
this.i18n("reader_tips_title"),
ntip, {
cancel: false,
buttons: force ? [butclose, butnexttip] : [butstop, butnexttip, butnexttomorrow]
})
await util.setStorage("reader_tips_ts", "" + Date.now())
}
},
/** Called on reader's creation, display a welcome message first time reader is opened */
async handleFirstTime() {
let isfirst = await util.getStorage("reader_firsttime")
......
......@@ -68,16 +68,21 @@
let formatText = txt => {
let boldify = (text => {
var bold = /\*\*(\S(.*?\S)?)\*\*/gm;
var html = text.replace(bold, '<strong>$1</strong>');
return html;
let bold = /\*\*(\S(.*?\S)?)\*\*/gm
let html = text.replace(bold, '<strong>$1</strong>')
return html
})
let italicify = (text => {
var italic = /_(\S(.*?\S)?)_/gm;
var html = text.replace(italic, '<i>$1</i>');
return html;
let italic = /_(\S(.*?\S)?)_/gm
let html = text.replace(italic, '<i>$1</i>')
return html
})
return boldify(italicify(txt))
let linkify = (text => {
let link = /\[([^\[\]]+)\]\(([^)]+)\)/gm
let html = text.replace(link, '<a href="$2" target="_blank">$1</a>')
return html
})
return boldify(italicify(linkify(txt)))
}
let lines = this.message.split("\n")
......
import util from "./util";
import { i18n } from "../mixins/i18n-mixin";
import browser from "webextension-polyfill";
/**
* Display tips
* - user can choose to display tips once a day or to stop it
* - button next go to next tip
* - saves previous tip and user preferences
* - force : force to display the popup (called on tips action button)
* All the tips are retrieved from i18n starting by reader_tips_ followed with numbers starting from 1. Numbers must be consecutive
*/
export const handleTips = async function ($ref, force = false) {
let display = true
if (!force) {
let lasttime = await util.getStorage("reader_tips_ts")
let stopped = await util.getStorage("reader_tips_stop")
if (stopped) display = false
if (lasttime && Date.now() - parseInt(lasttime) < 24 * 60 * 60 * 1000) {
display = false
}
}
if (force) display = true
if (display) {
let lasttip = await util.getStorage("reader_tips_last")
if (lasttip) lasttip = parseInt(lasttip)
// load tips in i18n
let tips = [], tip
while (tip = i18n("reader_tips_" + (tips.length + 1))) {
tips.push(tip)
}
// get the next tip
let nextTip = async () => {
if (!lasttip || lasttip + 1 > tips.length) lasttip = 0
let nxttip = lasttip + 1
await util.setStorage("reader_tips_last", "" + nxttip)
lasttip = nxttip
return tips[nxttip - 1] // lasttip is 1-based, tips array is 0-based
}
// Button to stop displaying tips
let butstop = {
title: i18n("reader_tips_stop"),
color: "grey",
click: async ({ agree }) => {
await util.setStorage("reader_tips_stop", "true")
agree()
}
}
let butnexttip = {
title: i18n("reader_tips_next"),
color: "primary",
click: async ({ changeMessage }) => {
changeMessage(await nextTip())
}
}
let butnexttomorrow = {
title: i18n("reader_tips_next_tomorrow"),
color: "primary",
click: ({ agree }) => {
agree()
}
}
let butclose = {
title: i18n("button_close"),
color: "grey",
click: ({ agree }) => {
agree()
}
}
let ntip = await nextTip()
await $ref.open(
i18n("reader_tips_title"),
ntip, {
cancel: false,
buttons: force ? [butclose, butnexttip] : [butstop, butnexttip, butnexttomorrow]
})
await util.setStorage("reader_tips_ts", "" + Date.now())
}
}
/**
* Test if current browser is Firefox
*/
function isFirefox() {
// Firefox 1.0+ (tested on Firefox 45 - 53)
return typeof InstallTrigger !== 'undefined';
}
/**
* Display messages once in a while to give support to AMR
* - link to patreon
* - link to leave a comment on Firefox
* @param {} $ref
*/
export const handleHelps = async function ($ref) {
// number of read chapters with the extension since v2.1
let nbread = await util.getStorage("nb_read")
if (!nbread) return
nbread = parseInt(nbread)
/**
* title : title of the dialog to display
* message : message to display
* action_name : name of the action button (other buttons are close and stop showing that)
* action : what to do when clicked
* id : to store the fact that we don't want the message
* condition: a condition to respect to show that popup
* importance: if multiple are eligible, the greater wins the battle, if multiple same, randomly chosen
*/
let popups = [
{ // rate us on Firefox Addons
title: i18n("reader_help_rate_title"),
message: i18n("reader_help_rate_message"),
action_name: i18n("reader_help_rate_action"),
action: () => {
browser.runtime.sendMessage({
action: "opentab",
url: "https://addons.mozilla.org/firefox/addon/all-mangas-reader/"
});
},
id: "rate",
importance: 1,
condition: () => {
return isFirefox() && nbread % 20 === 0
}
},
{ // patreon popup
title: i18n("reader_help_patreon_title"),
message: i18n("reader_help_patreon_message"),
action_name: i18n("reader_help_patreon_action"),
action: () => {
browser.runtime.sendMessage({
action: "opentab",
url: "https://www.patreon.com/allmangasreader"
});
},
id: "patreon",
importance: 2,
condition: () => nbread % 50 === 0
},
{ // 1000 mangas read !!
title: i18n("reader_help_1000_title", nbread),
message: i18n("reader_help_1000_message", nbread),
id: "1000",
importance: 3,
condition: () => nbread % 1000 === 0
}
]
let displayable_popups = [], topimp = 0
for (let pop of popups) {
if (await util.getStorage("dialog_" + pop.id + "_stop")) continue
if (pop.condition()) {
displayable_popups.push(pop)
if (topimp < pop.importance) topimp = pop.importance
}
}
if (displayable_popups.length === 0) return // no popup matching display conditions
displayable_popups = displayable_popups.filter(pop => pop.importance === topimp) // keep top level popups
// choose randomly among winners
let to_display = displayable_popups[Math.floor(Math.random() * displayable_popups.length)]
console.log(to_display)
// Button to stop displaying this message
let butstop = {
title: i18n("reader_help_stop"),
color: "grey",
click: async ({ agree }) => {
await util.setStorage("dialog_" + to_display.id + "_stop", "true")
agree()
}
}
// button to close message
let butclose = {
title: i18n("button_close"),
color: "grey",
click: ({ agree }) => {
agree()
}
}
let dispbuts = [butstop, butclose]
if (to_display.action_name) {
// custom dialog button
let butcustom = {
title: to_display.action_name,
color: "primary",
click: ({ agree }) => {
to_display.action()
agree()
}
}
dispbuts.push(butcustom)
}
// display dialog
await $ref.open(
to_display.title,
to_display.message, {
cancel: false,
buttons: dispbuts
})
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment