Created
March 11, 2025 14:03
-
-
Save tizee/4c51f9bba03c5c0904f3d6f5d7fc6adf to your computer and use it in GitHub Desktop.
python packaing docs - view source code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Python Packaging Docs - View Source Code | |
// @namespace http://tampermonkey.net/ | |
// @version 2025-03-11 | |
// @description Read source code of docs | |
// @author You | |
// @match https://packaging.python.org/en/latest/guides/writing-pyproject-toml/ | |
// @icon https://www.google.com/s2/favicons?sz=64&domain=python.org | |
// @grant none | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
// <a class="muted-link" href="https://github.com/pypa/packaging.python.org/edit/main/source/guides/writing-pyproject-toml.rst" title="Edit this page"> | |
// 获取容器和需要复制的元素 | |
const container = document.querySelector(".edit-this-page"); | |
const el = container.querySelector('a[href^="https://github.com/pypa/packaging.python.org/edit"]'); | |
if (el) { | |
// 复制元素 | |
const clonedEl = el.cloneNode(true); | |
// 修改复制的元素的 href 地址 | |
const newHref = el.href.replace( | |
/https:\/\/github\.com\/pypa\/packaging.python.org\/edit\//, | |
"https://raw.githubusercontent.com/pypa/packaging.python.org/refs/heads/" | |
); | |
clonedEl.href = newHref; | |
// 修改复制的元素的文本内容 | |
clonedEl.textContent = "View Source"; | |
// 将复制的元素追加到 container 中 | |
container.prepend(clonedEl); | |
console.debug("[CF DOC]", newHref); | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment