Skip to content

Instantly share code, notes, and snippets.

@noromanba
Last active September 2, 2023 13:03
Show Gist options
  • Save noromanba/2370972 to your computer and use it in GitHub Desktop.
Save noromanba/2370972 to your computer and use it in GitHub Desktop.
add permanently HEAD links on Gist for UserScript

gist raw perm HEAD userscripts.org #130781

Install

When you install user.js strongly recommended on Userscripts.org. Not here.

Behavior

Visit Gist and see 'raw' link, It's including long Hash name like this.

https://gist.github.com/raw/2370972/47150711fedb7375d19d761ab122485b8105678d/gist-raw-perm-HEAD.user.js

gist-raw-HEAD

This user.js provide 'HEAD' links. It's takes shrinked permanent raw link and shrinked named raw link when you browse Gist files.

HEAD

True Permalink: This is absolutery permanent link but it's always filetype: txt.

https://raw.github.com/gist/2370972/

HEAD(named)

Almost Permalink: This is almost permanent link. It's strict filetype by extension. This link broken when filename changed.

https://raw.github.com/gist/2370972/gist-raw-perm-HEAD.user.js

This link most useful for install user.js from Gist.

Known Ploblems

Multifiles Gist

HEAD can accessible 1st file only. That is Gist API constraining.

Gist API

Multifiles Gist has ploblem. Gist API not provide true permlink(bee called HEAD) for 2nd or more files.

Very simple.

Include content and history. It's too long too much.

Jot

Gist raw HTTP

cf. https://gist.github.com/2370972

  • GET 'raw' return HTTP 302
https://gist.github.com/raw/2370972/2370972/47150711fedb7375d19d761ab122485b8105678d/gist-raw-perm-HEAD.user.js
  • HTTP 200 OK
https://raw.github.com/gist/2370972/2370972/47150711fedb7375d19d761ab122485b8105678d/gist-raw-perm-HEAD.user.js

Based on

This Bookmarklet rev. on Hatena::Let.

// ==UserScript==
// @name gist raw perm HEAD
// @namespace http://www.hatena.ne.jp/noromanba/
// @description Add permanently HEAD link on Gist for Greasemonkey. Use for install user.js or load xxx.js with (at)require etc.
// @include https://gist.github.com/*
// @version 2012.4.20.12.32
// @homepage https://userscripts.org/scripts/show/130781
// @downloadURL https://userscripts.org/scripts/source/130781.user.js
// @installURL https://userscripts.org/scripts/source/130781.user.js
// @updateURL https://userscripts.org/scripts/source/130781.meta.js
// @license MIT License; http://nrm.mit-license.org/2012
// @copyright (c) 2012+, noromanba (http://www.hatena.ne.jp/noromanba/)
// @author noromanba
// @icon https://upload.wikimedia.org/wikipedia/commons/thumb/4/46/Button_Icon_Orange.svg/32px-Button_Icon_Orange.svg.png
// @icon64 https://upload.wikimedia.org/wikipedia/commons/thumb/4/46/Button_Icon_Orange.svg/64px-Button_Icon_Orange.svg.png
// ==/UserScript==
// [Detail]
// https://gist.github.com/2370972
(function() {
var raws = document.querySelectorAll('#gist-embed + a');
if (!raws) return;
var gist = function(refNode) {
var meta = refNode.pathname.match(/\/raw\/(\d+)\/\w+\/(.*)/);
var baseurl = 'https://raw.github.com/gist/';
var id = meta[1];
var basename = meta[2];
return {
id: id,
name: basename, // include directory -> 'foo/bar.txt' cf. https://gist.github.com/662233
file: { // without directory -> 'bar.txt'
name: basename.slice(basename.lastIndexOf('/') + 1),
type: basename.split('.').length > 1 ? basename.split('.').pop() : 'N/D'
},
permalink: baseurl + id + '/'
};
};
for (var i = 0; i < raws.length; i++) {
var raw = raws[i];
var namedHead = raw.cloneNode(true);
var g = gist(raw);
if (i === 0) {
var head = raw.cloneNode(true);
head.href = g.permalink;
head.textContent = 'HEAD';
head.title = 'HEAD(' + g.id + '.txt)';
// Fx must be needs 2nd args. cf. https://developer.mozilla.org/en/DOM/element.insertBefore
raw.parentNode.insertBefore(head, null);
}
namedHead.href = g.permalink + g.name;
namedHead.textContent = 'HEAD(named)';
namedHead.title = 'HEAD(' + g.name + ')';
raw.parentNode.insertBefore(namedHead, null);
}
})();
<h3>About</h3>
<strong>Add permanently HEAD link on Gist</strong>
<p>This user.js add 'HEAD' link. It's takes <strong>shrinked permanent raw link</strong>.
Like This</p>
<pre>
https://raw.github.com/gist/2370972/gist-raw-perm-HEAD.user.js
</pre>
<p><div>
<img src="http://cdn-ak.f.st-hatena.com/images/fotolife/n/noromanba/20120413/20120413072715.png" alt="gist-raw-perm-HEAD" width="600px" />
</div></p>
<h3>Detail</h3>
<p>Show technical details on <a href="https://gist.github.com/2370972" target="_blank">Gist: 2370972</a>.</p>
<h3>:EOF</h3>
<p>Enjoy Gist and Coding!</p>
Regards,<br />
noromanba
@LouCypher
Copy link

The new Gist broke your script \( ><)シ

@noromanba
Copy link
Author

@LouCypher
thank you for your infomation :-)

broken

I know, maybe gist API changes too. but GitHub not provide information. hum..
a similar kind as shown below

feed => HTTP406

can't get gists feed

https://gist.github.com/noromanba.atom

Subscribe Gists - Hatena::Let

i.e. mulfunction open feed on flavors.me

blame UI

where is panel which put log?

too drastic.. I’m stucking X-(
I don't have much time now, a correction takes time.

FYI

didn't notification by Github, I'm late.
try @USERNAME with comments

Regards,
noromanba

@noromanba
Copy link
Author

@LouCypher
quick fix 🚑 now. but incompletly yet. pjax handling.........🐌
if unworks it, plz try reload

@LouCypher
Copy link

Thanks for the updates
       «:dancers::dancers:ヾ

@noromanba
Copy link
Author

@LouCypher
somehow handle pjax:sleepy::dizzy: thx for your patience:pray:

@jerone
Copy link

jerone commented Jan 29, 2013

Would be great if you get this to work with the new style and upload new version to USO.

@noromanba
Copy link
Author

stuck in... 💭 take away freedom by CSP 🔒

@noromanba
Copy link
Author

@jerone sry I'm late. thx. USO has gone, and fork sites not good enough. e.g. GF; extreme security

@denilsonsa
Copy link

Hey, @noromanba, I've updated the script to work on the current GitHub markup. Look at https://gist.github.com/denilsonsa/f2e5b9ee53e633e20165 and please update your version. :)

@denilsonsa
Copy link

FYI, it was broken again, and I've fixed it again: https://gist.github.com/denilsonsa/f2e5b9ee53e633e20165

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