function Compress (data, level) {
const mapChars = "DGi0YA7BemWnQjCl4+bR3f8SKIF9tUz/xhr2oEOgPpac=61ZqwTudLkM5vHyNXsVJ";
if (data === null) return "";
let dictionary = {},
newSequence = {},
currentSequence = "",
dictSize = 2,
bitsUsed = 3,
codeWidth = 2,
output = [],
bitBuffer = 0,
bitCount = 0;
const pushBits = (charCode, length) => {
for (let j = 0; j < length; j++) {
bitBuffer = (bitBuffer << 1) | (1 & charCode);
if (bitCount === level - 1) {
output.push (mapChars.charAt (bitBuffer));
bitBuffer = 0;
bitCount = 0;
} else {
bitCount++;
}
charCode >>= 1;
}
};
for (let i = 0; i < data.length; i++) {
const currentChar = data.charAt (i);
if (!dictionary.hasOwnProperty (currentChar)) {
dictionary[currentChar] = bitsUsed++;
newSequence[currentChar] = true;
}
const combined = currentSequence + currentChar;
if (dictionary.hasOwnProperty (combined)) {
currentSequence = combined;
} else {
if (newSequence.hasOwnProperty (currentSequence)) {
if (currentSequence.charCodeAt (0) < 256) {
pushBits (0, codeWidth);
pushBits (currentSequence.charCodeAt (0), 8);
} else {
pushBits (1, codeWidth);
pushBits (currentSequence.charCodeAt (0), 16);
}
dictSize--;
if (dictSize === 0) {
dictSize = 1 << codeWidth++;
}
delete newSequence[currentSequence];
} else {
pushBits (dictionary[currentSequence], codeWidth);
}
dictSize--;
if (dictSize === 0) {
dictSize = 1 << codeWidth++;
}
dictionary[combined] = bitsUsed++;
currentSequence = currentChar;
}
}
if (currentSequence !== "") {
if (newSequence.hasOwnProperty (currentSequence)) {
if (currentSequence.charCodeAt (0) < 256) {
pushBits (0, codeWidth);
pushBits (currentSequence.charCodeAt (0), 8);
} else {
pushBits (1, codeWidth);
pushBits (currentSequence.charCodeAt (0), 16);
}
dictSize--;
if (dictSize === 0) {
dictSize = 1 << codeWidth++;
}
delete newSequence[currentSequence];
} else {
pushBits (dictionary[currentSequence], codeWidth);
}
dictSize--;
if (dictSize === 0) {
dictSize = 1 << codeWidth++;
}
}
pushBits (2, codeWidth);
while (true) {
bitBuffer <<= 1;
if (bitCount === level - 1) {
output.push (mapChars.charAt (bitBuffer));
break;
}
bitCount++;
}
return output.join ("");
}
function get_sig (data) {
data = encodeURIComponent (data);
for (var chars = 0, i = 0; i < data.length; i++) {
chars = (chars << 7) - chars + 398 + data.charCodeAt (i);
chars |= 0;
}
return chars;
}
function get_ua (data, noPad) {
if (null == data) {
return "";
}
var res = Compress (data, 6);
if (noPad) {
return res;
}
switch (res.length % 4) {
default:
case 0:
return res;
case 1:
return res + "===";
case 2:
return res + "==";
case 3:
return res + "=";
}
}
function parseUrl (url) {
const urlPattern = /^ (https?:\/\/)? ([^\/? #] +) ([^? #] *) (\?[^ #] *)? ( # .*)?$/;
const matches = url.match (urlPattern);
if (!matches) {
throw new Error ( }
const searchParams = {};
if (matches[4]) {
matches[4].substring (1).split ( const [key, value] = param.split ( searchParams[key] = value;
});
}
matches[1] = matches[1].replace ( return {
protocol: matches[1] || host: matches[2] || pathname: matches[3] || search: matches[4] || searchParams: searchParams,
hash: matches[5] || toString: function () {
return `${this.protocol}//${this.host}${this.pathname}${this.search}${this.hash}`;
}
};
}
function get_cdn_seaech (url, Data) {
let Obj = parseUrl (url);
let search = if (Obj.search) {
let queryData = Obj.search.replace ("?", "").split ("&");
search =
queryData
.filter ( (v) => {
return !v.startsWith ("refer__1972");
})
.join ("&") || "";
if (Obj.search !== "") Obj.search = "?" + search;
}
let signText = Obj.toString ();
Data && (signText += JSON.stringify (Data));
signText = get_sig (signText) + "|0|" + new Date ().getTime () + "|1";
let keyName = (function () {
const keyNames = ["type__", "refer__", "ipcity__", "md5__", "decode__", "encode__", "time__", "timestamp__", "type__"];
let codes = 0;
for (let i = 0; i < Obj.host.length; i++) {
codes += Obj.host[i].charCodeAt ();
}
return keyNames[codes % keyNames.length] + (codes % 10000);
}) ();
if (!Obj.search) {
Obj.search = `?${keyName}=` + encodeURIComponent (get_ua (signText, !0));
} else {
Obj.search += `&${keyName}=` + get_ua (signText, !0);
}
let result = Obj.toString ();
return result;
}[/i]