新增了一个 review PR 时方便跳转到英文原文的 user script #377
Replies: 9 comments 10 replies
-
挺酷的功能,已添加。 我是使用的三屏,可能多开一个 vscode 无碍。 |
Beta Was this translation helpful? Give feedback.
-
我前阵子有一个想法,但酝酿的不太成熟,借助这次讨论稍微说下,后续有成熟的 demo 再放出来
|
Beta Was this translation helpful? Give feedback.
-
@Justineo good news~ 😎 已解决前面谈及的比较难的环节,就是
如果这个愿望向好的方向发展的话,后续再换回
|
Beta Was this translation helpful? Give feedback.
-
@Justineo 成功发起 PR, 可以针对 单行(纯 文本),更复杂的需要拉取原内容(还没有开发完)。 😄 post 的内容: {
"owner":"veaba",
"repo":"vuepress-plugin-editable",
"path":"/docs/README.md",
"content":"它还会自. 这是纯文本( plain text)","line":10
} 录制了个视频,目前看来达到预期目标了。 3.mp4 |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
@Justineo 恭喜发财,哈哈,赶了一天的代码,踩了一堆坑 终于能够用了,后续再完善细节和文档。可以到 |
Beta Was this translation helpful? Give feedback.
-
@Justineo 时隔半年,重新拾起了这项改动。 下面的改动特性,实现 fork 的用户也可以向主仓库发起 PR。 QQ.20210901000030.mp4当然,发现插件还有些 bug,后续需要优化。 期待通过后续的优化,迟早有一天,也可以中文文档里能够使用这个工具。 如果有兴趣的话,我重新使用 Node,js 重构应用,以方便后续展开协作,现在是用 Go 写的。 未来的预期的特性:
|
Beta Was this translation helpful? Give feedback.
-
很棒的 user script!感谢。 我发现将 |
Beta Was this translation helpful? Give feedback.
-
稍微修改了一下,现在可以支持异步跳转了,无需刷新。 // ==UserScript==
// @name Link to English version
// @namespace https://cn.vuejs.org/
// @version 0.1
// @description Add a link back to English version
// @author Justineo
// @match https://github.com/vuejs/docs-next-zh-cn/pull/*
// @grant none
// ==/UserScript==
async function sleep() {
return new Promise(resolve => {
setTimeout(resolve, 1000);
});
}
(async function() {
const URL_PATTERN = /^https:\/\/github\.com\/[^/]+\/[^/]+\/blob\/[^/]+\/(.+)$/;
do {
const selectedTab = document.querySelector('.tabnav-tab.selected')
const href = selectedTab.getAttribute('href');
// console.log('looking', href);
if (href.endsWith('/files')) {
break;
}
await sleep()
} while (1)
function inject() {
const menus = [
...document.querySelectorAll("details-menu.show-more-popover"),
];
menus.forEach((menu) => {
const links = [...menu.querySelectorAll("a")];
const fileLink = links.find(
({ textContent }) => textContent.trim() === "View file"
);
const href = fileLink.href;
const newHref = href.replace(
URL_PATTERN,
(_, path) => `https://github.com/vuejs/docs-next/blame/master/${path}`
);
const newLink = document.createElement("a");
newLink.href = newHref;
newLink.className = fileLink.className;
newLink.target = "_blank";
newLink.setAttribute("role", fileLink.getAttribute("role"));
newLink.setAttribute("rel", fileLink.getAttribute("rel"));
newLink.textContent = "View upstream";
fileLink.parentNode.insertBefore(newLink, fileLink.nextSibling);
});
}
inject();
})(); |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
启用 Tampermonkey 以后把上面这段代码添加为一个新的 user script 即可。效果如下:
在 diff 视图下,新增了一个 View upstream 的链接,点击可以在新窗口打开原文对应文件。
Ps. GitHub 从 PR 再点到 Files tab 走的是异步跳转,可能会匹配不上,随手写的所以也没支持这种逻辑,如果没效果可以刷新一下。
@Jinjiang @veaba
Beta Was this translation helpful? Give feedback.
All reactions