Skip to content

Commit 8d6b217

Browse files
committed
domain name change
1 parent 5d6051c commit 8d6b217

File tree

9 files changed

+47
-21
lines changed

9 files changed

+47
-21
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
- [Custom Code](https://github.com/shuzijun/leetcode-editor/blob/master/doc/CustomCode.md) ([demo](https://github.com/shuzijun/leetcode-question))
99

1010
## Introduction
11-
Do Leetcode exercises in IDE, support `leetcode.com` and `leetcode-cn.com`, to meet the basic needs of doing exercises.
11+
Do Leetcode exercises in IDE, support `leetcode.com` and `leetcode.cn`, to meet the basic needs of doing exercises.
1212
Support theoretically: IntelliJ IDEA PhpStorm WebStorm PyCharm RubyMine AppCode CLion GoLand DataGrip Rider MPS Android Studio.
1313
<a href="http://shuzijun.cn/leetcode-editor/monitor.html" target="_blank">be with you!</a>
1414

@@ -35,7 +35,7 @@
3535
</p>
3636

3737
- **Configuration path**: `File` -> `settings`->`tools`->`leetcode plugin`
38-
- **`URL options`**: `leetcode.com`OR`leetcode-cn.com`
38+
- **`URL options`**: `leetcode.com`OR`leetcode.cn`
3939
- **`Code Type`**: `Java`,`Python`,`C++`,`Python3`,`C`,`C#`,`JavaScript`,`Ruby`,`Swift`,`Go` ,`Scala`,`Kotlin`,`Rust`,`PHP`,`Bash`,`SQL`
4040
- **`LoginName`**: Login Username
4141
- **`Password`**: Login password

README_ZH.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
- [自定义代码生成](https://github.com/shuzijun/leetcode-editor/blob/master/doc/CustomCode_ZH.md) ([示例](https://github.com/shuzijun/leetcode-question))
99

1010
## 简介
11-
在IDE中解决LeetCode问题,支持`leetcode.com``leetcode-cn.com`,满足基本的做题需求。
11+
在IDE中解决LeetCode问题,支持`leetcode.com``leetcode.cn`,满足基本的做题需求。
1212
理论上支持: IntelliJ IDEA PhpStorm WebStorm PyCharm RubyMine AppCode CLion GoLand DataGrip Rider MPS Android Studio。
1313
[be with you!](http://shuzijun.cn/leetcode-editor/monitor.html)
1414

@@ -35,7 +35,7 @@
3535
</p>
3636

3737
- **配置路径**: `File` -> `settings`->`tools`->`leetcode plugin`
38-
- **`URL可选项`**: `leetcode.com``leetcode-cn.com`
38+
- **`URL可选项`**: `leetcode.com``leetcode.cn`
3939
- **`Code Type`**: `Java`,`Python`,`C++`,`Python3`,`C`,`C#`,`JavaScript`,`Ruby`,`Swift`,`Go` ,`Scala`,`Kotlin`,`Rust`,`PHP`,`Bash`,`SQL`
4040
- **`LoginName`**: 登录用户名
4141
- **`Password`**: 登录密码

doc/LoginHelp_ZH.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
- [中文文档](#登录配置)
44
登录方式:配置用户名密码登录,cookie登录,浏览器登录
55
## 用户名密码登录
6-
在leetcode插件配置页配置用户名密码,如登录失败将加载下面两种登录方式,此方式仅支持leetcode-cn.com
6+
在leetcode插件配置页配置用户名密码,如登录失败将加载下面两种登录方式,此方式仅支持leetcode.cn
77
## cookie登录
88
首先在浏览器中登录leetcode,打开浏览器控制台,复制cookie到登录弹出框,点击login.[参考](https://developers.google.com/web/tools/chrome-devtools/network?hl=zh_cn)
99
<p align="center">

src/main/java/com/shuzijun/leetcode/plugin/actions/editor/AbstractEditAction.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public void actionPerformed(AnActionEvent anActionEvent, Config config) {
3434
MessageUtils.getInstance(anActionEvent.getProject()).showInfoMsg("info", PropertiesUtils.getInfo("tree.null"));
3535
return;
3636
}
37-
if(!URLUtils.getLeetcodeHost().equals(leetcodeEditor.getHost())){
37+
if(!URLUtils.equalsHost(leetcodeEditor.getHost())){
3838
MessageUtils.getInstance(anActionEvent.getProject()).showInfoMsg("info", PropertiesUtils.getInfo("tree.host"));
3939
return;
4040
}

src/main/java/com/shuzijun/leetcode/plugin/actions/editor/OpenSolutionAction.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public void update(@NotNull AnActionEvent anActionEvent) {
3232
return;
3333
}
3434
LeetcodeEditor leetcodeEditor = ProjectConfig.getInstance(anActionEvent.getProject()).getEditor(vf.getPath());
35-
if (leetcodeEditor == null || StringUtils.isBlank(leetcodeEditor.getTitleSlug()) || !URLUtils.getLeetcodeHost().equals(leetcodeEditor.getHost())) {
35+
if (leetcodeEditor == null || StringUtils.isBlank(leetcodeEditor.getTitleSlug()) || !URLUtils.equalsHost(leetcodeEditor.getHost())) {
3636
anActionEvent.getPresentation().setEnabled(false);
3737
return;
3838
}

src/main/java/com/shuzijun/leetcode/plugin/setting/ProjectConfig.java

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,26 @@
11
package com.shuzijun.leetcode.plugin.setting;
22

3-
import com.intellij.openapi.components.*;
3+
import com.intellij.openapi.components.PersistentStateComponent;
4+
import com.intellij.openapi.components.State;
5+
import com.intellij.openapi.components.Storage;
46
import com.intellij.openapi.project.Project;
57
import com.intellij.util.xmlb.annotations.MapAnnotation;
68
import com.shuzijun.leetcode.plugin.model.LeetcodeEditor;
79
import com.shuzijun.leetcode.plugin.model.PluginConstant;
10+
import com.shuzijun.leetcode.plugin.utils.URLUtils;
811
import org.apache.commons.lang3.StringUtils;
912
import org.jetbrains.annotations.NotNull;
1013
import org.jetbrains.annotations.Nullable;
1114

1215
import java.util.HashMap;
16+
import java.util.Iterator;
1317
import java.util.Map;
1418

1519
/**
1620
* @author shuzijun
1721
*/
18-
@State(name = "LeetcodeEditor" + PluginConstant.ACTION_SUFFIX, storages = {@Storage(value = PluginConstant.ACTION_PREFIX+"/editor.xml")})
19-
public class ProjectConfig implements PersistentStateComponent<ProjectConfig.InnerState> {
22+
@State(name = "LeetcodeEditor" + PluginConstant.ACTION_SUFFIX, storages = {@Storage(value = PluginConstant.ACTION_PREFIX + "/editor.xml")})
23+
public class ProjectConfig implements PersistentStateComponent<ProjectConfig.InnerState> {
2024

2125
public Map<String, LeetcodeEditor> idProjectConfig = new HashMap<>();
2226

@@ -37,24 +41,34 @@ public ProjectConfig.InnerState getState() {
3741
public void loadState(@NotNull ProjectConfig.InnerState innerState) {
3842
this.innerState = innerState;
3943
idProjectConfig.clear();
40-
this.innerState.projectConfig.forEach((s, leetcodeEditor) -> {
41-
idProjectConfig.put(leetcodeEditor.getFrontendQuestionId(),leetcodeEditor);
42-
});
44+
Iterator<String> iter = this.innerState.projectConfig.keySet().iterator();
45+
while (iter.hasNext()) {
46+
String key = iter.next();
47+
LeetcodeEditor leetcodeEditor = this.innerState.projectConfig.get(key);
48+
if (StringUtils.isBlank(leetcodeEditor.getFrontendQuestionId())) {
49+
iter.remove();
50+
continue;
51+
} else if (leetcodeEditor.getFrontendQuestionId().startsWith(URLUtils.leetcodecnOld)) {
52+
leetcodeEditor.setHost(URLUtils.leetcodecn);
53+
leetcodeEditor.setFrontendQuestionId(leetcodeEditor.getFrontendQuestionId().replace(URLUtils.leetcodecnOld, URLUtils.leetcodecn));
54+
}
55+
idProjectConfig.put(leetcodeEditor.getFrontendQuestionId(), leetcodeEditor);
56+
}
4357
}
4458

4559

4660
public LeetcodeEditor getDefEditor(String frontendQuestionId) {
4761
LeetcodeEditor leetcodeEditor = idProjectConfig.get(frontendQuestionId);
4862
if (leetcodeEditor == null) {
4963
leetcodeEditor = new LeetcodeEditor();
50-
idProjectConfig.put(frontendQuestionId,leetcodeEditor);
64+
idProjectConfig.put(frontendQuestionId, leetcodeEditor);
5165
}
5266
return leetcodeEditor;
5367
}
5468

5569
public void addLeetcodeEditor(LeetcodeEditor leetcodeEditor) {
5670
idProjectConfig.put(leetcodeEditor.getFrontendQuestionId(), leetcodeEditor);
57-
if(StringUtils.isNotBlank(leetcodeEditor.getPath())) {
71+
if (StringUtils.isNotBlank(leetcodeEditor.getPath())) {
5872
innerState.projectConfig.put(leetcodeEditor.getPath(), leetcodeEditor);
5973
}
6074
}

src/main/java/com/shuzijun/leetcode/plugin/utils/URLUtils.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
public class URLUtils {
1010

1111
public static final String leetcode = "leetcode.com";
12-
public static final String leetcodecn = "leetcode-cn.com";
12+
public static final String leetcodecn = "leetcode.cn";
13+
public static final String leetcodecnOld = "leetcode-cn.com";
1314

1415
private static String leetcodeUrl = "https://";
1516
private static String leetcodeLogin = "/accounts/login/";
@@ -35,6 +36,17 @@ public static String getLeetcodeHost() {
3536
return host;
3637
}
3738

39+
public static boolean equalsHost(String host) {
40+
String thisHost = getLeetcodeHost();
41+
if(thisHost.equals(host)){
42+
return true;
43+
}else if(thisHost.equals(leetcodecn) && leetcodecnOld.equals(host)){
44+
return true;
45+
}else {
46+
return false;
47+
}
48+
}
49+
3850
public static String getLeetcodeUrl() {
3951
return leetcodeUrl + getLeetcodeHost();
4052
}

src/main/java/com/shuzijun/leetcode/plugin/window/HttpLogin.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
public class HttpLogin {
2929
public static boolean ajaxLogin(Config config, NavigatorTable navigatorTable, Project project) {
3030

31-
if (URLUtils.leetcode.equals(URLUtils.getLeetcodeHost())) {
31+
if (!URLUtils.isCn()) {
3232
return Boolean.FALSE;
3333
}
3434

src/main/resources/META-INF/plugin.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,18 @@
66

77
<description><![CDATA[
88
<div>
9-
<p>Support for leetcode.com and leetcode-cn.com, can test and submit questions.
9+
<p>Support for leetcode.com and leetcode.cn, can test and submit questions.
1010
More tutorial please visit: <a href="https://github.com/shuzijun/leetcode-editor">here</a></p>
1111
</div>
1212
<div>
1313
<h2>Introduction</h2>
1414
<br>
1515
<ul>
16-
<li>Support for leetcode.com and leetcode-cn.com, can test and submit questions</li>
16+
<li>Support for leetcode.com and leetcode.cn, can test and submit questions</li>
1717
<li>More tutorial please visit: <a href="https://github.com/shuzijun/leetcode-editor">here</a></li>
1818
</ul>
1919
<ul>
20-
<li>支持leetcode.com和leetcode-cn.com,可测试与提交问题</li>
20+
<li>支持leetcode.com和leetcode.cn,可测试与提交问题</li>
2121
<li>更多的插件使用教程: <a href="https://github.com/shuzijun/leetcode-editor">插件使用介绍</a></li>
2222
</ul>
2323
</div>
@@ -47,7 +47,7 @@
4747
<h3>Configuration path: File -> settings->tools->leetcode plugin</h3>
4848
<br>
4949
<ul>
50-
<li>URL options: leetcode.com and leetcode-cn.com</li>
50+
<li>URL options: leetcode.com and leetcode.cn</li>
5151
<li>Code Type: Java, Python, C++, Python3, C, C#, JavaScript, Ruby, Swift, Go, Scala, Kotlin, Rust, PHP</li>
5252
<li> Login Name: Login Username</li>
5353
<li> Password: Login password</li>

0 commit comments

Comments
 (0)