Skip to content

Instantly share code, notes, and snippets.

@noromanba
Last active November 14, 2019 15:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save noromanba/f5bc6779c3c3005d6d106da5aa624990 to your computer and use it in GitHub Desktop.
Save noromanba/f5bc6779c3c3005d6d106da5aa624990 to your computer and use it in GitHub Desktop.
append self-fork icon on Hatena::Let for UserScript
// ==UserScript==
// @name Hatena::Let self fork
// @namespace http://noromanba.flavors.me
// @description append self-fork icon on Hatena::Let for UserScript
// @include http://let.hatelabo.jp/*
// @grant none
// @noframes
// @run-at document-end
// @version 2017.3.2.0
// @homepage https://gist.github.com/noromanba/f5bc6779c3c3005d6d106da5aa624990
// @downloadURL https://gist.github.com/noromanba/f5bc6779c3c3005d6d106da5aa624990/raw/hatenalet-selffork.user.js
// @contributor taizooo http://let.hatelabo.jp/taizooo/let/gYC-ydPttrvedg
// @contributor noromanba http://let.hatelabo.jp/noromanba/let/gYC-x6_02LnWEg (Fork of)
// @license MIT License https://nrm.mit-license.org/2017
// @author noromanba http://noromanba.flavors.me
// @icon https://upload.wikimedia.org/wikipedia/commons/thumb/b/b9/BSicon_uetABZg%2B4.svg/128px-BSicon_uetABZg%2B4.svg.png
// ==/UserScript==
// Icon (PD by YLSS)
// https://commons.wikimedia.org/wiki/File%3ABSicon_uetABZg%2B4.svg
// Devel
// https://gist.github.com/noromanba/f5bc6779c3c3005d6d106da5aa624990
// Bookmarklet
// http://let.hatelabo.jp/noromanba/let/gYC-x6_02LnWEg
(() => {
'use strict';
const edit = document.body.querySelector('a.edit-link[href*="/let.edit"]');
if (!edit) return;
// fork URL syntax
// http://let.hatelabo.jp/<USER_ID>/let.fork?code_id=<LET_ID>
// http://let.hatelabo.jp/<USER_ID>/let/<LET_ID>
// http://let.hatelabo.jp/<USER_ID>/let.fork?rev_id=<REV_ID>
// http://let.hatelabo.jp/<USER_ID>/let/<LET_ID>/rev/<REV_ID>
const fork = edit.cloneNode();
fork.pathname = edit.pathname.replace(/\.edit$/, '.fork');
fork.textContent = 'Fork';
// TBD change image
edit.parentNode.appendChild(fork);
})();
@RichardBronosky
Copy link

This no longer works because the fork link has been replaced with a form that includes a authenticity_token field. I don't think there is any way around that from the browser.
I now use https://github.com/defunkt/gist from the CLI to:

  • # Define your original gist url (I have to use the ssh url to get it to work for my credential-helper)
    original_url="git@gist.github.com:f5bc6779c3c3005d6d106da5aa624990.git"
  • # Create a new gist
    url="$(date | gist -f temp)"
  • # Clone it
    git clone $url; cd $(basename $url)
  • # Add the original gist as a remote and fetch it
    git remote add alt $original_url; git fetch alt
  • # Check out the original
    git reset --hard alt/master
  • # Push to the new gist
    git push -f origin master

Note: the # are in there so you can copy-pasta the whole block into the terminal 😉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment