mirror of
https://github.com/internetarchive/brozzler.git
synced 2025-08-13 08:45:27 -04:00
change magic first line of behavior js files to a commented-out json blob, which should include the fields 'url_regex' and 'request_idle_timeout_sec'; behavior.is_finished() incorporates the custom idle timeout into its check; also rename variables in behavior scripts with umbra/UMBRA_ prefix to sort of namespace them; and add "finished" logic to facebook and vimeo behaviors (flickr needs work to support it)
This commit is contained in:
parent
2a9633ad77
commit
a62a07e6b7
5 changed files with 130 additions and 67 deletions
|
@ -1,23 +1,13 @@
|
|||
// {"request_idle_timeout_sec":10}
|
||||
//
|
||||
// vim:set sw=8 et:
|
||||
//
|
||||
// Scrolls to the bottom of the page. That's it at the moment.
|
||||
//
|
||||
|
||||
// STATES = ['NASCENT', 'NEED_SCROLL', 'WAITING', 'FINISHED']
|
||||
|
||||
// var transition = prepareTransition(state);
|
||||
// if (transition.callback) {
|
||||
// newState.callback(state, newState);
|
||||
// }
|
||||
// state = newState;
|
||||
|
||||
// if (state.status === 'NASCENT') {
|
||||
// } else if (state.status == 'NEED_SCROLL') {
|
||||
// } else if (state.status == 'FINISHED') {
|
||||
|
||||
var UMBRA_FINISH_AFTER_IDLE_TIME = 10 * 1000; // ms
|
||||
var umbraState = {'idleSince':null};
|
||||
var umbraFinished = false;
|
||||
var umbraIntervalFunc = function() {
|
||||
// var needToScroll = (window.scrollY + window.innerHeight + 10 < document.body.clientHeight);
|
||||
// var needToScroll = (document.documentElement.scrollTop + document.documentElement.clientHeight < document.documentElement.scrollHeight);
|
||||
var needToScroll = (window.scrollY + window.innerHeight < document.documentElement.scrollHeight);
|
||||
|
||||
// console.log('intervalFunc umbraState.idleSince=' + umbraState.idleSince + ' needToScroll=' + needToScroll + ' window.scrollY=' + window.scrollY + ' window.innerHeight=' + window.innerHeight + ' document.documentElement.scrollHeight=' + document.documentElement.scrollHeight);
|
||||
|
@ -29,10 +19,15 @@ var umbraIntervalFunc = function() {
|
|||
}
|
||||
}
|
||||
|
||||
// If we haven't had anything to do (scrolled, clicked, etc) in this amount of
|
||||
// time, then we consider ourselves finished with the page.
|
||||
var UMBRA_USER_ACTION_IDLE_TIMEOUT_SEC = 10;
|
||||
|
||||
// Called from outside of this script.
|
||||
var umbraBehaviorFinished = function() {
|
||||
if (umbraState.idleSince != null) {
|
||||
var idleTime = Date.now() - umbraState.idleSince;
|
||||
if (idleTime > UMBRA_FINISH_AFTER_IDLE_TIME) {
|
||||
var idleTimeMs = Date.now() - umbraState.idleSince;
|
||||
if (idleTimeMs / 1000 > UMBRA_USER_ACTION_IDLE_TIMEOUT_SEC) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue