SpeedReaderTools

Use for generating and decoding stuffs in SpeedReader.

ეს სკრიპტი არ უნდა იყოს პირდაპირ დაინსტალირებული. ეს ბიბლიოთეკაა, სხვა სკრიპტებისთვის უნდა ჩართეთ მეტა-დირექტივაში // @require https://update.greasyfork.org/scripts/456423/1128886/SpeedReaderTools.js.

  1. const SpeedReaderTools = (() => {
  2. function generateRandomString32(id) {
  3. function generateRandomString16() {
  4. let e = "";
  5. let n = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
  6. for (let i = 0; i < 16; i++) {
  7. e += n.charAt(Math.floor(Math.random() * n.length));
  8. }
  9. return e;
  10. }
  11. let n = generateRandomString16(),
  12. i = Array(Math.ceil(16 / id.length) + 1).join(id),
  13. r = i.substr(0, 16),
  14. e = i.substr(-16, 16),
  15. s = 0,
  16. h = 0,
  17. u = 0;
  18. return n.split("").map(function (t, i) {
  19. return s ^= n.charCodeAt(i),
  20. h ^= r.charCodeAt(i),
  21. u ^= e.charCodeAt(i),
  22. t + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_" [s + h + u & 63]
  23. }).join("");
  24. }
  25. function getDecryptedTable(t, i, n) { // id, randomString, table
  26. for (var r = t + ":" + i, e = 0, s = 0; s < r.length; s++)
  27. e += r.charCodeAt(s) << s % 16;
  28. 0 == (e &= 2147483647) && (e = 305419896);
  29. var h = "",
  30. u = e;
  31. for (let s = 0; s < n.length; s++) {
  32. u = u >>> 1 ^ 1210056708 & -(1 & u);
  33. var o = (n.charCodeAt(s) - 32 + u) % 94 + 32;
  34. h += String.fromCharCode(o)
  35. }
  36. try {
  37. return JSON.parse(h)
  38. } catch (t) {}
  39. return null
  40. }
  41. function getDecryptionKey(t, ctbl, ptbl) { // filename, ctbl, ptbl
  42. var i = [0, 0];
  43. if (t) {
  44. for (var n = t.lastIndexOf("/") + 1, r = t.length - n, e = 0; e < r; e++)
  45. i[e % 2] += t.charCodeAt(e + n);
  46. i[0] %= 8,
  47. i[1] %= 8
  48. }
  49. var s = ptbl[i[0]],
  50. h = ctbl[i[1]];
  51. return [h, s];
  52. }
  53. class CoordDecoder {
  54. constructor(t, i) {
  55. this.It = null;
  56. this.kt = [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 62, -1, -1, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -1, -1, -1, -1, -1, -1, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, -1, 63, -1, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, -1, -1, -1, -1, -1];
  57. var n = t.match(/^=([0-9]+)-([0-9]+)([-+])([0-9]+)-([-_0-9A-Za-z]+)$/),
  58. r = i.match(/^=([0-9]+)-([0-9]+)([-+])([0-9]+)-([-_0-9A-Za-z]+)$/);
  59. if (null !== n && null !== r && n[1] === r[1] && n[2] === r[2] && n[4] === r[4] && "+" === n[3] && "-" === r[3] && (this.T = parseInt(n[1], 10),
  60. this.j = parseInt(n[2], 10),
  61. this.xt = parseInt(n[4], 10),
  62. !(8 < this.T || 8 < this.j || 64 < this.T * this.j))) {
  63. var e = this.T + this.j + this.T * this.j;
  64. if (n[5].length === e && r[5].length === e) {
  65. var s = this.St(n[5]),
  66. h = this.St(r[5]);
  67. this.Ct = s.n,
  68. this.At = s.t,
  69. this.Tt = h.n,
  70. this.Pt = h.t,
  71. this.It = [];
  72. for (var u = 0; u < this.T * this.j; u++)
  73. this.It.push(s.p[h.p[u]])
  74. }
  75. }
  76. }
  77. St(t) {
  78. var i, n = [],
  79. r = [],
  80. e = [];
  81. for (i = 0; i < this.T; i++)
  82. n.push(this.kt[t.charCodeAt(i)]);
  83. for (i = 0; i < this.j; i++)
  84. r.push(this.kt[t.charCodeAt(this.T + i)]);
  85. for (i = 0; i < this.T * this.j; i++)
  86. e.push(this.kt[t.charCodeAt(this.T + this.j + i)]);
  87. return {
  88. t: n,
  89. n: r,
  90. p: e
  91. }
  92. }
  93. getCoords(t) {
  94. for (var i = t.width - 2 * this.T * this.xt, n = t.height - 2 * this.j * this.xt, r = Math.floor((i + this.T - 1) / this.T), e = i - (this.T - 1) * r, s = Math.floor((n + this.j - 1) / this.j), h = n - (this.j - 1) * s, u = [], o = 0; o < this.T * this.j; ++o) {
  95. var a = o % this.T,
  96. f = Math.floor(o / this.T),
  97. c = this.xt + a * (r + 2 * this.xt) + (this.Tt[f] < a ? e - r : 0),
  98. l = this.xt + f * (s + 2 * this.xt) + (this.Pt[a] < f ? h - s : 0),
  99. v = this.It[o] % this.T,
  100. d = Math.floor(this.It[o] / this.T),
  101. b = v * r + (this.Ct[d] < v ? e - r : 0),
  102. g = d * s + (this.At[v] < d ? h - s : 0),
  103. p = this.Tt[f] === a ? e : r,
  104. m = this.Pt[a] === f ? h : s;
  105. 0 < i && 0 < n && u.push({
  106. srcX: c,
  107. srcY: l,
  108. width: p,
  109. height: m,
  110. destX: b,
  111. destY: g
  112. })
  113. }
  114. return u
  115. }
  116. }
  117.  
  118. return {
  119. generateRandomString32,
  120. getDecryptedTable,
  121. getDecryptionKey,
  122. CoordDecoder
  123. }
  124. })();