Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add message dialogue for when returning to previous reading spot #102

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
42 changes: 36 additions & 6 deletions modules/paulbot/paulbot.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,21 @@ var paulbot;
{ "emote": "waving", "speak": message },
{ "mode": "off" }
];
var justStarted,
startingTimeout;

if(stats && stats.windows.previous) {
dialogue[0].prompts = [
{
"prompt": "Continue reading from last spot",
"do": function() { document.getElementsByTagName('body')[0].scrollTop = stats.windows.previous; }
"do": function() {
justStarted = true;
var clearJustStarted = function() {
justStarted = !justStarted;
}
startingTimeout = setTimeout(clearJustStarted, 500);
document.getElementsByTagName('body')[0].scrollTop = stats.windows.previous;
}
},
{
"prompt": "Go away"
Expand Down Expand Up @@ -74,6 +83,23 @@ var paulbot;
]
paulbot.dialogue(dialogue);
}
function alertJustStarting() {

var message = "Welcome back. Proceed.";

var dialogue = [
{
"emote": "explaining",
"speak": message,
"wait": 2000
},
{
"mode": "off"
}
];

module.bot.dialogue(dialogue);
}

function logScroll() {
scrollLog.push({
Expand All @@ -86,11 +112,15 @@ var paulbot;
var scrollSpeed =
(scrollLog[scrollLog.length-1].scrollTop - scrollLog[scrollLog.length-2].scrollTop) /
(scrollLog[scrollLog.length-1].timestamp - scrollLog[scrollLog.length-2].timestamp)

if(pageYOffset + innerHeight > $(document).height() - 400) {
completionThrottled();
} else if(scrollSpeed > 4 && fastSass.length) {
alertTooFastThrottled();
if(!justStarted) {
if(pageYOffset + innerHeight > $(document).height() - 400) {
completionThrottled();
} else if(scrollSpeed > 4 && fastSass.length) {
alertTooFastThrottled();
}
}
else {
alertJustStarting();
}
}

Expand Down