Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

new search function #117

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README-zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ Github 全球/中国用户排名,全球仓库 Star 最多排名,通过 Githu

更新时间:<!--GAMFC-->2022-11-05 09:15:32<!--GAMFC-END-->


## 插件使用

```bash
Expand Down
5 changes: 0 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,6 @@ Now it can be updated automatically every day, using [GitHub Actions Workflows](

Update date: <!--GAMFC-->2024-04-18 05:58:49<!--GAMFC-END-->

## Plug-in Usage

```bash
npm install @wcj/github-rank --save-dev
```

Users can obtain ranking data by importing data, or directly access the [user leaderboard](https://unpkg.com/@wcj/github-rank/web/index.html) through [UNPKG](https://unpkg.com/@wcj/github-rank/dist/users.json).

Expand Down
2 changes: 1 addition & 1 deletion src/getRepos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { sleep, getReposData } from './utils/index.js';
import { RepoData } from './common/props.js';
import { saveData } from './utils/saveData.js';

;(async() => {
; (async () => {
let repos: RepoData[] = [];

let data = (await getReposData(1)) || [];
Expand Down
1 change: 1 addition & 0 deletions src/getUserInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { type UsersData } from './common/props.js';
import { updateUsersData } from './utils/saveUsersData.js';

; (async () => {
console.log('进来获取用户信息1')
try {
// 获取【全球】用户数据排行榜
const users: UsersData[] = await updateUsersData('./dist/users.json', './.cache/users.json', '');
Expand Down
2 changes: 1 addition & 1 deletion src/utils/saveUsersData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ async function getInfo(arr: UsersDataBase[], type: string = '', globalUsers: Use
return;
}
}

findUser && users.push(findUser);
await saveUserData([...users], type);
// 获取成功删除第一条
Expand Down
108 changes: 108 additions & 0 deletions template/_partial/form_filtering.ejs
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
<header>
<style>
.form_filtering {
padding: 5px 20px 2px 20px;
color: #adadad;
font-size: 12px;
}
.form_filtering .form {
display: flex;
align-items: center;
}
.form_filtering .form form-item:not(:first-child) {
margin-left: 12px;
}
.form_filtering .form input[type="submit"] {
margin-left: 5px;
cursor: pointer;
}
.form_filtering .reset-button {
margin-left: 5px;
}
.hidden {
display: none !important;
}
.show {
display: block !important;
}
.show-table {
display: table !important;
}
</style>
<script>
/** 查询功能 */
function validateForm(event) {
event?.preventDefault(); // 阻止默认的表单提交行为

/** Users 的搜索*/
const name = document.forms["myForm"]["githubName"]?.value.toLowerCase();
const trDoms = document.querySelectorAll(".tr-item");
trDoms?.forEach(function (element) {
if (
element
.querySelector(".github-name")
.textContent.trim()
.toLowerCase()
.indexOf(name) === -1
) {
element.classList.add("hidden"); // 添加隐藏样式
} else {
element.classList.remove("hidden");
}
});

/** Repos、Trending 的搜索*/
const language =
document.forms["myForm"]["language"]?.value.toLowerCase();
const liDoms = document.querySelectorAll(".info");
liDoms?.forEach(function (element) {
if (
element
.querySelector(".language")
.textContent.trim()
.toLowerCase()
.indexOf(language) === -1
) {
element.parentNode.classList.add("hidden");
} else {
element.parentNode.classList.remove("hidden");
}
});
}

function resetForm() {
// 获取表单元素
var form = document.forms["myForm"];
// 重置表单
form.reset();
validateForm();
}
</script>
</header>
<div class="form_filtering">
<form
name="myForm"
class="form"
onsubmit="return validateForm(event)"
method="post"
>
<% if(tabCls !== 'users') {%>
<div class="form-item">
<label for="language">language:</label>
<input type="text" id="language" name="language" />
</div>
<% } %> <% if(tabCls === 'users') {%>
<div class="form-item">
<label for="githubName">name:</label>
<input type="text" id="githubName" name="githubName" />
</div>
<% } %>
<input type="submit" value="Search" />
<input
type="reset"
value="Reset"
class="reset-button"
onclick="resetForm()"
/>
</form>
</div>
Loading