Greasy Fork

Ahto Library

My library used my other scripts.

目前为 2015-07-12 提交的版本。查看 最新版本

此脚本不应直接安装,它是一个供其他脚本使用的外部库。如果您需要使用该库,请在脚本元属性加入:// @require https://update.greasyfork.icu/scripts/10922/61500/Ahto%20Library.js

// Generated by CoffeeScript 1.9.3
var findMatches, safeInterval, safeParseInt;

findMatches = function(selector, min, max) {
  var matches, ref;
  if (min == null) {
    min = 1;
  }
  if (max == null) {
    max = Infinity;
  }
  matches = $(selector);
  if ((min <= (ref = matches.length) && ref <= max)) {
    return matches;
  } else {
    throw Error(matches.length + " matches (expected " + min + "-" + max + ") found for selector: " + selector);
  }
};

safeParseInt = function(s) {
  var n;
  n = parseInt(s);
  if (isNaN(s)) {
    throw new Error("Unable to parse int from \"" + s + "\"");
  } else {
    return n;
  }
};

safeInterval = function(func, wait, times) {
  var interv;
  interv = (function(w, t) {
    return (function() {
      var e;
      if ((t == null) || t-- > 0) {
        setTimeout(interv, w);
        try {
          return func.call(null);
        } catch (_error) {
          e = _error;
          t = 0;
          throw e.toString();
        }
      }
    });
  })(wait, times);
  return setTimeout(interv, wait);
};