如何在GitHub上Fork自己的Gist?

6

如何复刻自己的GitHub代码片段?

有一个可能性:在gist上发布了一个脚本,但我不知道如何将其安装到我的gitHub上。在这种情况下,需要解释如何使用该脚本以及它所做的事情。

(重新)fork任何gist,包括您自己的

<!-- language: lang-js -->
// ==UserScript==
// @name           (Re)fork any gist, including your own
// @namespace      https://github.com/johan
// @description    Adds a "fork" button to gists missing one at gist.github.com, so you can create multiple forks
// @match          https://gist.github.com/*
// @include        https://gist.github.com/*
// ==/UserScript==

if (/^\/\d+/.test(location.pathname) &&
    !document.querySelector('a img[alt="fork"]')) {
  var i = document.createElement('img')
    , a = document.createElement('a')
    , u = document.querySelector('img.button').src
    , p = document.querySelector('.title');

  a.title = 'Create another fork of this gist';
  a.style.cssText = 'float: right; margin: 4px 7px 0';
  a.addEventListener('click', fork);
  a.appendChild(i);

  i.alt = 'fork';
  i.src = u.replace(/[^\/]*$/, 'fork_button.png');
  i.className = 'button';

  p.appendChild(a);
}

function fork(e) {
  var f = document.body.appendChild(document.createElement('form'));
  f.method = 'POST';
  f.action = '/fork' + location.pathname;
  f.appendChild(document.querySelector('input[name=authenticity_token]'));
  f.submit();
  return false;
}

StackOverflow展示了如何fork您自己的GitHub存储库

2个回答

2

看起来这似乎不再可能。即使使用Github API,您也会得到以下响应:

https://api.github.com/gists/:gist_id/forks
{
  "message": "You cannot fork your own gist.",
  "errors": [
    {
      "resource": "Gist",
      "field": "forks",
      "code": "unprocessable"
    }
  ],
  "documentation_url": "https://docs.github.com/v3/gists/#fork-a-gist"
}

https://docs.github.com/v3/gists/#fork-a-gist


您可以点赞此建议,让我们看看是否有所进展。
https://github.com/github/feedback/discussions/14882


2
尝试使用Fork your own Gist 书签工具。
它会在您自己的Gist中添加一个完全功能的“Fork”按钮。
如果页面上已经存在一个“Fork”按钮,则此书签工具将将焦点设置为该按钮,而不是添加另一个按钮。
更改是临时的,只要您离开该Gist(单击“Fork”按钮也是如此),按钮就会消失。

3
我分叉了你的这个版本,进行了两处修复,并编辑了自述文件,以便向Firefox用户说明如何操作。位于此处 - Gist分叉。我还将其制作成了Firefox插件(位于此处 - ghForkable)。 - Noitidart
我现在从答案的书签中得到一个错误 Uncaught TypeError: $ is not a function - Bruno Bronosky

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接