<commit_before>'use strict';

var Request = require('../request.js');
var Settings = require('../settings.js');

function Scrobble(options) {
  if (options.type === 'show') {
    this.item = { episode: options.response };
  } else {
    this.item = { movie: options.response.movie };
  }

  this.onProgressChange();
  this.url = Settings.apiUri + '/scrobble';
  this.success = options.success;
  this.error = options.error;
  this.startProgressTimeout();
};

Scrobble.prototype = {
  startProgressTimeout: function() {
    this.progressChangeInterval = setInterval(function() {
      this.onProgressChange();
    }.bind(this), 1000);
  },

  stopProgressTimeout: function() {
    clearInterval(this.progressChangeInterval);
  },

  onProgressChange: function() {
    if (document.querySelector('.player-slider progress')) {
      this.castScrubber();
    } else {
      this.webScrubber();
    }
  },

  webScrubber: function() {
    var scrubber = document.querySelector('#scrubber-component .player-scrubber-progress-completed');
    if (scrubber) {
      this.progress = parseFloat(scrubber.style.width);
    }
  },

  castScrubber: function() {
    var progress = document.querySelector('.player-slider progress');
    if (progress) {
      this.progress = parseInt(progress.getAttribute('value')) * 100 / parseFloat(progress.getAttribute('max'));
    }
  },

  _sendScrobble: function(options) {
    var params = this.item;
    params.progress = this.progress;

    Request.send({
      method: 'POST',
      url: this.url + options.path,
      params: params,
      success: this.success,
      error: this.error
    });
  },

  start: function() {
    this._sendScrobble({ path: '/start' });
  },

  pause: function() {
    this._sendScrobble({ path: '/pause' });
  },

  stop: function() {
    this._sendScrobble({ path: '/stop' });
    this.stopProgressTimeout();
  }
};

module.exports = Scrobble;<commit_msg>Change castScrubber function to only set progress if it is greather than zero On cast mode Netflix sets the progress bar to zero before onStop is called<commit_after>'use strict';

var Request = require('../request.js');
var Settings = require('../settings.js');

function Scrobble(options) {
  if (options.type === 'show') {
    this.item = { episode: options.response };
  } else {
    this.item = { movie: options.response.movie };
  }

  this.onProgressChange();
  this.url = Settings.apiUri + '/scrobble';
  this.success = options.success;
  this.error = options.error;
  this.startProgressTimeout();
};

Scrobble.prototype = {
  startProgressTimeout: function() {
    this.progressChangeInterval = setInterval(function() {
      this.onProgressChange();
    }.bind(this), 1000);
  },

  stopProgressTimeout: function() {
    clearInterval(this.progressChangeInterval);
  },

  onProgressChange: function() {
    if (document.querySelector('.player-slider progress')) {
      this.castScrubber();
    } else {
      this.webScrubber();
    }
  },

  webScrubber: function() {
    var scrubber = document.querySelector('#scrubber-component .player-scrubber-progress-completed');
    if (scrubber) {
      this.progress = parseFloat(scrubber.style.width);
    }
  },

  castScrubber: function() {
    var progressElement = document.querySelector('.player-slider progress');
    if (progressElement) {
      var newProgress = parseInt(progressElement.getAttribute('value')) * 100 / parseFloat(progressElement.getAttribute('max'));
      if (newProgress > 0) {
        this.progress = newProgress;
      }
    }
  },

  _sendScrobble: function(options) {
    var params = this.item;
    params.progress = this.progress;

    Request.send({
      method: 'POST',
      url: this.url + options.path,
      params: params,
      success: this.success,
      error: this.error
    });
  },

  start: function() {
    this._sendScrobble({ path: '/start' });
  },

  pause: function() {
    this._sendScrobble({ path: '/pause' });
  },

  stop: function() {
    this._sendScrobble({ path: '/stop' });
    this.stopProgressTimeout();
  }
};

module.exports = Scrobble;
{'fraction_non_alphanumeric': 0.15069835824552805, 'fraction_numerical': 0.0036755697133055622, 'mean_word_length': 3.2743455497382197, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7640924', 'n_tokens_mistral': 1265, 'n_tokens_neox': 1234, 'n_words': 245}