gpt4 book ai didi

javascript - 通过 Chrome 扩展解码 URL

转载 作者:行者123 更新时间:2023-12-03 06:54:20 27 4
gpt4 key购买 nike

我正在尝试为 Google Chrome 编写一个小扩展程序来解码网站上显示的编码 URL。我前段时间用Java写了核心方法,并尝试将其转换为JavaScript

function decodeURL(Encoded) {
var Length = Encoded.length;
var Counter = 0;
var Character;
var Decoded = "";
for (Counter = 0; Counter < Length; Counter++) {
Character = Encoded.charAt(Counter);
if (Character === 37 && Encoded.charAt(Counter + 1) === 50 && Encoded.charAt(Counter + 2) === 70) {
Counter += 2;
Decoded += "/";
} else if (Character === 37 && Encoded.charAt(Counter + 1) === 51 && Encoded.charAt(Counter + 2) === 65) {
Counter += 2;
Decoded += ":";
} else if (Character === 37 && Encoded.charAt(Counter + 1) === 50 && Encoded.charAt(Counter + 2) === 49) {
Counter += 2;
Decoded += "!";
} else if (Character === 37 && Encoded.charAt(Counter + 1) === 50 && Encoded.charAt(Counter + 2) === 50) {
Counter += 2;
Decoded += "\"";
} else if (Character === 37 && Encoded.charAt(Counter + 1) === 50 && Encoded.charAt(Counter + 2) === 51) {
Counter += 2;
Decoded += "#";
} else if (Character === 37 && Encoded.charAt(Counter + 1) === 50 && Encoded.charAt(Counter + 2) === 52) {
Counter += 2;
Decoded += "$";
} else if (Character === 37 && Encoded.charAt(Counter + 1) === 50 && Encoded.charAt(Counter + 2) === 53) {
Counter += 2;
Decoded += "%";
} else if (Character === 37 && Encoded.charAt(Counter + 1) === 51 && Encoded.charAt(Counter + 2) === 68) {
Counter += 2;
Decoded += "=";
} else if (Character === 37 && Encoded.charAt(Counter + 1) === 51 && Encoded.charAt(Counter + 2) === 70) {
Counter += 2;
Decoded += "?";
} else {
Decoded += Character;
}
return Decoded;

} }

它不返回任何内容,而不是解码后的 URL(没有错误,也没有字符串)如果有人知道错误可能出在哪里,我将不胜感激。

最佳答案

我会使用 JS 的内置函数。
encodeURI()decodeURI()

decodeURI("https://developer.mozilla.org/ru/docs/JavaScript_%D1%88%D0%B5%D0%BB%D0%BB%D1%8B");

返回“https://developer.mozilla.org/ru/docs/JavaScript_шеллы

因此无需创建自己的函数。

关于javascript - 通过 Chrome 扩展解码 URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37348828/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com