【问题标题】:How to fork my own gist on GitHub ?如何在 GitHub 上分叉我自己的要点?
【发布时间】:2013-02-05 22:41:05
【问题描述】:

如何分叉我自己的 GitHub 要点?

一种可能性:在 gist 上发布了一个脚本,但我不知道如何在我的 gitHub 上安装它。在这种情况下,解释如何使用脚本以及它在做什么。

(Re)Fork any gist, including your own

<!-- 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 展示了如何创建自己的 GitHub repository

【问题讨论】:

    标签: javascript github gist


    【解决方案1】:

    试试Fork your own Gist 书签。

    它为您自己的 Gist 添加了一个功能齐全的 Fork 按钮。

    如果页面中已经存在 Fork 按钮,则此小书签会将焦点设置在该按钮上,而不是添加另一个按钮。

    更改是暂时的,一旦您离开该 Gist,按钮就会消失(单击 Fork 按钮也会为您完成此操作)。

    【讨论】:

    • 我复制了你的这个版本,做了 2 个修复,并编辑了自述文件,向 Firefox 用户解释如何做到这一点。 Located here - Gist Fork。我还用它制作了一个 Firefox 插件 (located here - ghForkable)
    • 我现在从答案中的书签中收到错误 Uncaught TypeError: $ is not a function
    猜你喜欢
    • 1970-01-01
    • 2012-03-28
    • 2018-07-01
    • 2021-05-26
    • 2015-06-05
    • 1970-01-01
    • 2013-08-20
    • 2014-09-23
    • 2018-01-13
    相关资源
    最近更新 更多