Skip to content

Commit

Permalink
feat(docs): github ids css update
Browse files Browse the repository at this point in the history
  • Loading branch information
dogodo-cc committed Apr 18, 2024
1 parent 9065a0e commit 3a09ab7
Show file tree
Hide file tree
Showing 8 changed files with 199 additions and 214 deletions.
2 changes: 1 addition & 1 deletion packages-demos/others/download/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ app.get('/download', (req, res) => {
const fileName = path.basename(zipFilePath);
res.setHeader('Content-Disposition', `attachment; filename=${fileName}`);
res.setHeader('Content-Type', 'application/zip');
res.setHeader('Content-Length', 1000000000000);
// res.setHeader('Content-Length', 1000000000000);

// 创建可读流,读取 ZIP 文件
const readStream = fs.createReadStream(zipFilePath);
Expand Down
2 changes: 1 addition & 1 deletion projects/document/docs/core/github-ids/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## 使用

点击 [@cocos-fe/github-ids](https://chrome.google.com/webstore/detail/cocos-fegithub-ids/eidodebdpdgnbcphggoimbpohochfpoj/related?hl=zh-CN) 安装即可。
点击 [@cocos-fe/github-ids](https://chromewebstore.google.com/detail/cocos-fegithub-ids/eidodebdpdgnbcphggoimbpohochfpoj?hl=zh-CN&authuser=0) 安装即可。

大家记得去给插件一个好评,这样我们后期的更新评审会更容易通过。

Expand Down
86 changes: 36 additions & 50 deletions projects/github-ids/manifest.json
Original file line number Diff line number Diff line change
@@ -1,51 +1,37 @@
{
"name": "@cocos-fe/github-ids",
"version": "1.0.5",
"description": "cocos 开发人员的 github 中文名映射表",
"homepage_url": "http://cocos.90s.co",
"manifest_version": 3,
"permissions": [
"storage"
],
"content_scripts": [
{
"matches": [
"https://github.com/cocos/*",
"https://github.com/cocos-creator/*"
],
"css": [
"./styles/content.css"
],
"js": [
"./scripts/content.js"
],
"run_at": "document_end"
}
],
"action": {
"default_popup": "popup.html",
"default_icon": {
"16": "images/logo.png",
"32": "images/logo.png",
"48": "images/logo.png",
"128": "images/logo.png"
}
},
"icons": {
"16": "images/logo.png",
"32": "images/logo.png",
"48": "images/logo.png",
"128": "images/logo.png"
},
"web_accessible_resources": [
{
"resources": [
"images/*.png",
"styles/*.css"
],
"matches": [
"<all_urls>"
]
}
]
}
"name": "@cocos-fe/github-ids",
"version": "1.0.6",
"description": "cocos 开发人员的 github 中文名映射表",
"homepage_url": "http://cocos.90s.co",
"manifest_version": 3,
"permissions": ["storage"],
"content_scripts": [
{
"matches": ["https://github.com/cocos/*", "https://github.com/cocos-creator/*"],
"css": ["./styles/content.css"],
"js": ["./scripts/content.js"],
"run_at": "document_end"
}
],
"action": {
"default_popup": "popup.html",
"default_icon": {
"16": "images/logo.png",
"32": "images/logo.png",
"48": "images/logo.png",
"128": "images/logo.png"
}
},
"icons": {
"16": "images/logo.png",
"32": "images/logo.png",
"48": "images/logo.png",
"128": "images/logo.png"
},
"web_accessible_resources": [
{
"resources": ["images/*.png", "styles/*.css"],
"matches": ["<all_urls>"]
}
]
}
29 changes: 14 additions & 15 deletions projects/github-ids/popup.html
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<style>
body {
width: 120px;
text-align: center;
}
</style>
</head>

<head>
<meta charset="UTF-8">
<style>
body {
width: 120px;
text-align: center;
}
</style>
</head>

<body>
cocos FE 开发<br /> <a target="_blank" href="http://cocos.90s.co/">进入主页</a>
</body>

</html>
<body>
cocos FE 开发<br />
<a target="_blank" href="https://cocos.90s.co/">进入主页</a>
</body>
</html>
3 changes: 1 addition & 2 deletions projects/github-ids/scripts/background.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
chrome.runtime.onInstalled.addListener(function() {
chrome.runtime.onInstalled.addListener(function () {
console.log('@cocos-fe/githubs-ids background.js active');
});

45 changes: 25 additions & 20 deletions projects/github-ids/scripts/content.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,13 @@ function createPanel() {
</div>
`;

$panel.querySelector('.icon').addEventListener('click', () => {
$panel.classList.toggle('show');
}, false);
$panel.querySelector('.icon').addEventListener(
'click',
() => {
$panel.classList.toggle('show');
},
false
);

$panel.querySelector('input').addEventListener('input', (e) => {
search(e.target.value);
Expand All @@ -47,7 +51,7 @@ function createPanel() {
update();
});

$panel.addEventListener('click', e => {
$panel.addEventListener('click', (e) => {
e.stopPropagation();
});
document.body.addEventListener('click', () => {
Expand Down Expand Up @@ -97,13 +101,15 @@ function createList(list) {
function fetchList() {
const url = `https://90s.oss-cn-hangzhou.aliyuncs.com/github-ids/github-ids.json?v=${Date.now()}`;
console.log('fetch', url);
return fetch(url).then(res => res.json()).then(data => {
idsMap = data;
chrome.storage.sync.set({ [storageKey]: data }, () => {
console.log('storage.set:', data);
return fetch(url)
.then((res) => res.json())
.then((data) => {
idsMap = data;
chrome.storage.sync.set({ [storageKey]: data }, () => {
console.log('storage.set:', data);
});
return data;
});
return data;
});
}

// 替换页面id
Expand All @@ -117,20 +123,19 @@ function replaceIds() {
'a[rel="contributor"]',
'.opened-by a.Link--muted',
].join();
Array.from(document.querySelectorAll(selector))
.forEach(ele => {
const text = ele.innerText;
const textZH = idsMap[text];
if (textZH) {
ele.innerText = textZH;
}
});
Array.from(document.querySelectorAll(selector)).forEach((ele) => {
const text = ele.innerText;
const textZH = idsMap[text];
if (textZH) {
ele.innerText = textZH;
}
});
}

// 通过监听 github 的页面切换进度条来判断是否完成路由切换
function observerProgress() {
const $progress = document.querySelector('.Progress-item');
const callback = function(mutationsList) {
const callback = function (mutationsList) {
for (const mutation of mutationsList) {
if (mutation.type === 'attributes') {
const press = parseInt($progress.style.width, 10);
Expand Down Expand Up @@ -190,7 +195,7 @@ function message() {
}

// 监听路由等事件
['hashchange', 'popstate', 'load'].forEach(ev => {
['hashchange', 'popstate', 'load'].forEach((ev) => {
window.addEventListener(ev, async () => {
if (!idsMap || Object.keys(idsMap).length === 0) {
await fetchList();
Expand Down
34 changes: 15 additions & 19 deletions projects/github-ids/scripts/hot-reload.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,29 @@
const filesInDirectory = dir => new Promise (resolve =>
dir.createReader().readEntries(entries =>
Promise.all(entries.filter(e => e.name[0] !== '.').map(e =>
e.isDirectory
? filesInDirectory(e)
: new Promise(resolve => e.file(resolve)),
))
.then(files => [].concat(...files))
.then(resolve),
),
);
const filesInDirectory = (dir) =>
new Promise((resolve) =>
dir.createReader().readEntries((entries) =>
Promise.all(entries.filter((e) => e.name[0] !== '.').map((e) => (e.isDirectory ? filesInDirectory(e) : new Promise((resolve) => e.file(resolve)))))
.then((files) => [].concat(...files))
.then(resolve)
)
);

const timestampForFilesInDirectory = dir =>
filesInDirectory(dir).then(files =>
files.map(f => f.name + f.lastModifiedDate).join());
const timestampForFilesInDirectory = (dir) => filesInDirectory(dir).then((files) => files.map((f) => f.name + f.lastModifiedDate).join());

const watchChanges = (dir, lastTimestamp) => {
timestampForFilesInDirectory(dir).then(timestamp => {
if (!lastTimestamp || (lastTimestamp === timestamp)) {
timestampForFilesInDirectory(dir).then((timestamp) => {
if (!lastTimestamp || lastTimestamp === timestamp) {
setTimeout(() => watchChanges(dir, timestamp), 1000); // retry after 1s
} else {
chrome.runtime.reload();
}
});
};

chrome.management.getSelf (self => {
chrome.management.getSelf((self) => {
if (self.installType === 'development') {
chrome.runtime.getPackageDirectoryEntry(dir => watchChanges(dir));
chrome.tabs.query({ active: true, lastFocusedWindow: true }, tabs => { // NB: see https://github.com/xpl/crx-hotreload/issues/5
chrome.runtime.getPackageDirectoryEntry((dir) => watchChanges(dir));
chrome.tabs.query({ active: true, lastFocusedWindow: true }, (tabs) => {
// NB: see https://github.com/xpl/crx-hotreload/issues/5
if (tabs[0]) {
chrome.tabs.reload(tabs[0].id);
}
Expand Down
Loading

0 comments on commit 3a09ab7

Please sign in to comment.