Ahto Library

My library used my other scripts.

当前为 2015-07-12 提交的版本,查看 最新版本

此脚本不应直接安装。它是供其他脚本使用的外部库,要使用该库请加入元指令 // @require https://update.cn-greasyfork.org/scripts/10922/61499/Ahto%20Library.js

  1. // Generated by CoffeeScript 1.9.3
  2. (function() {
  3. var findMatches, safeInterval, safeParseInt;
  4.  
  5. findMatches = function(selector, min, max) {
  6. var matches, ref;
  7. if (min == null) {
  8. min = 1;
  9. }
  10. if (max == null) {
  11. max = Infinity;
  12. }
  13. matches = $(selector);
  14. if ((min <= (ref = matches.length) && ref <= max)) {
  15. return matches;
  16. } else {
  17. throw Error(matches.length + " matches (expected " + min + "-" + max + ") found for selector: " + selector);
  18. }
  19. };
  20.  
  21. safeParseInt = function(s) {
  22. var n;
  23. n = parseInt(s);
  24. if (isNaN(s)) {
  25. throw new Error("Unable to parse int from \"" + s + "\"");
  26. } else {
  27. return n;
  28. }
  29. };
  30.  
  31. safeInterval = function(func, wait, times) {
  32. var interv;
  33. interv = (function(w, t) {
  34. return (function() {
  35. var e;
  36. if ((t == null) || t-- > 0) {
  37. setTimeout(interv, w);
  38. try {
  39. return func.call(null);
  40. } catch (_error) {
  41. e = _error;
  42. t = 0;
  43. throw e.toString();
  44. }
  45. }
  46. });
  47. })(wait, times);
  48. return setTimeout(interv, wait);
  49. };
  50.  
  51. }).call(this);