Greasy Fork is available in English.

lib:range

adds range function to allow for i of range(0, 10, step:optional)

  1. // ==UserScript==
  2. // @name lib:range
  3. // @version 2
  4. // @description adds range function to allow for i of range(0, 10, step:optional)
  5. // @license GPLv3
  6. // @run-at document-start
  7. // @author You
  8. // @match *://*/*
  9. // @exclude /livereload.net\/files\/ffopen\/index.html$/
  10. // @icon data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEgAAABICAMAAABiM0N1AAAAAXNSR0IB2cksfwAAAAlwSFlzAAAOxAAADsQBlSsOGwAAAHJQTFRFAAAAEIijAo2yAI60BYyuF4WaFIifAY6zBI2wB4usGIaZEYigIoiZCIyrE4igG4iYD4mjEomhFoedCoqpDIqnDomlBYyvE4efEYmiDYqlA42xBoytD4mkCYqqGYSUFYidC4qoC4upAo6yCoupDYqmCYur4zowOQAAACZ0Uk5TAO////9vr////1+/D/+/L+/Pf/////+f3///////H4////////+5G91rAAACgUlEQVR4nM2Y22KjIBCGidg1264liZqDadK03X3/V2wNKHMC7MpF/xthHD5mgERAqZhWhfYqH6K+Qf2qNNf625hCoFj9/gblMUi5q5jLkXLCKudgyiRm0FMK82cWJp1fLbV5VmvJbCIc0GCYaFqqlDJgADdBjncqAXYobm1xh72aFMflbysteFfdy2Yi1XGOm5HGBzQ1dq7TzEoxjeNTjQZb7VA3e1c7+ImgasAgQ9+xusNVNZIo5xmOMgihIS2PbCQIiHEUdTvhxCcS/kPomfFI2zHy2PkWmA6aNatIJpKFJyekyy02xh5Y3DI9T4aOT6VhIUrsNTFp1pf79Z4SIIVDegl6IJO6cHiL/GimIZDhgTu/BlYWCQzHMl0zBWT/T3KAhtxOuUB9FtBrpsz0RV4xsjHmW+UCaffcSy/5viMGer0/6HdFNMZBq/vjJL38H9Dqx4Fuy0Em12DbZy+9pGtiDijbglwAehyj11n0tRD3WUBm+lwulE/8h4BuA+iWAQQnteg2Xm63WQLTpnMnpjdge0Mgu/GRPsV4xdjQ94Lfi624fabhDkfUqIKNrM64Q837v8yL0prasepCgrtvw1sJpoqanGEX7b5mQboNW8eawXaWXTMfMGxub472hzWzHSn6Sg2G9+6TAyRruE71s+zAzjWaknoyJCQzwxrghH2k5FDT4eqWunuNxyN9QCGcxVod5oADbYnIUkDTGZEf1xDJnSFteQ3KdsT8zYDMQXcHxsevcLH1TrsABzkNPyA/L7b0jg704viMMlpQI96WsHknCt/3YH0kOEo9zcGkwrFK39ck72rmoehmKqo2RKlilzSy/nJKEV45CT38myJp456fezktHjN5aeMAAAAASUVORK5CYII=
  11. // @grant none
  12. // @namespace https://greasyfork.org/users/1184528
  13. // ==/UserScript==
  14. ;(() => {
  15. const a = loadlib("allfuncs")
  16. loadlib("libloader").savelib("range", range)
  17. function range(n1, n2, step = String(n1).match(/\.(.*)/)?.[1]?.length ?? 0) {
  18. if (n2 == undefined) {
  19. n2 = n1
  20. n1 = 0
  21. }
  22. if (!(String(n1).endsWith("0") && String(n1).length > 7)) n1 = Number(n1)
  23. if (!(String(n2).endsWith("0") && String(n2).length > 7)) n2 = Number(n2)
  24. var places = step
  25. step = 1 / Math.pow(10, step)
  26. var arr = []
  27. var i = n1
  28. var namedrange = new (class range {
  29. constructor() {
  30. this.from = n1
  31. this.to = n2
  32. }
  33. })()
  34. Object.getPrototypeOf(arr).name = "asd"
  35. return new Proxy(namedrange, {
  36. get(_obj, prop) {
  37. if (prop !== Symbol.iterator) return Reflect.get(namedrange, prop)
  38. return function* () {
  39. while (true) {
  40. i += step
  41. i = Number(a(i).toplaces(undefined, places).val)
  42. yield i
  43. if (i > n2) break
  44. }
  45. }
  46. },
  47. })
  48. }
  49. })()