版本比较
『超能』c++网址打开器
正文
增加 23 行删除 23 行
21 行未改动2223242526262728282930313215 行未改动484950515252535455565757585960612 行未改动64656667686869707171727374753 行未改动79808182838384858686878889907 行未改动989910010110210210310410510610710710810911011111111211311411510 行未改动1261271281291301301311321331348 行未改动14314414514614714714814914915015115215315315415515615744 行未改动2022032042052062062072082092102112122132142142152162172182192192202212222237 行未改动23123223323423523523623723823823924024124124224324424424524624724819 行未改动26826927027127227227327427521 行未改动
void loadConfig() { std::ifstream file(configFile); std::string line;
shortcuts.clear();
while (std::getline(file, line)) { size_t pos = line.find(' '); if (pos != std::string::npos) { std::string key = line.substr(0, pos);15 行未改动 std::string ensureUrlFormat(const std::string& url) { std::string result = url; // 移除可能的多余空格 result.erase(std::remove(result.begin(), result.end(), ' '), result.end());
// 如果没有协议头,自动添加https:// if (result.find("://") == std::string::npos) { result = "https://" + result; }
return result; }
public:2 行未改动 }
void addShortcut() { std::string shortcut, url;
std::cout << "请输入网站缩写 (例如: ds): "; std::getline(std::cin, shortcut);
// 检查缩写是否已存在 if (shortcuts.find(shortcut) != shortcuts.end()) { std::cout << "缩写 '" << shortcut << "' 已存在,对应网站: " << shortcuts[shortcut] << std::endl; std::cout << "是否覆盖? (y/n): ";3 行未改动 std::cout << "已取消添加" << std::endl; return; } }
std::cout << "请输入网站地址 (例如: chat.deepseek.com): "; std::getline(std::cin, url);
if (!shortcut.empty() && !url.empty()) { url = ensureUrlFormat(url); shortcuts[shortcut] = url; saveConfig();7 行未改动 if (shortcuts.empty()) { std::cout << "当前没有保存任何网站缩写,请先添加一些网站" << std::endl; return; }
std::cout << "可用的网站缩写:" << std::endl; for (const auto& pair : shortcuts) { std::cout << " " << pair.first << std::endl; }
std::string shortcut; std::cout << std::endl << "请输入要打开的网站缩写: "; std::getline(std::cin, shortcut);
openWebsite(shortcut); }
void openWebsite(const std::string& shortcut) {10 行未改动 if (shortcuts.empty()) { std::cout << "当前没有保存任何网站缩写" << std::endl; return; }
std::cout << "已保存的网站缩写:" << std::endl; std::cout << "-------------------" << std::endl; int count = 1; for (const auto& pair : shortcuts) {8 行未改动 if (shortcuts.empty()) { std::cout << "当前没有保存任何网站缩写" << std::endl; return; }
listShortcuts();
std::string shortcut; std::cout << std::endl << "请输入要删除的网站缩写: "; std::getline(std::cin, shortcut);
removeShortcut(shortcut); }
void removeShortcut(const std::string& shortcut) {44 行未改动 void quickOpenMode() { std::cout << std::endl; std::cout << "*** 快速打开模式 ***" << std::endl; std::cout << "直接输入缩写打开网站,输入 'back' 返回主菜单" << std::endl;
if (!shortcuts.empty()) { std::cout << "可用缩写: "; for (const auto& pair : shortcuts) { std::cout << pair.first << " "; } std::cout << std::endl; }
while (true) { std::cout << std::endl << "缩写> "; std::string input; std::getline(std::cin, input);
if (input == "back" || input == "exit" || input == "quit") { break; } else if (input == "list") { listShortcuts();7 行未改动};
int main() { WebsiteManager manager;
std::cout << "欢迎使用网站快捷打开工具!" << std::endl; std::cout << "配置文件: websites.config" << std::endl;
while (true) { manager.showMainMenu();
std::string choice; std::getline(std::cin, choice);
if (choice == "0") { std::cout << "谢谢使用,再见!" << std::endl; break; }19 行未改动 // 如果输入的不是菜单选项,尝试作为缩写直接打开 manager.openWebsite(choice); } }
return 0;}```