Skip to content

Instantly share code, notes, and snippets.

@noromanba
Last active September 2, 2023 13:03

Revisions

  1. noromanba revised this gist Dec 20, 2014. 3 changed files with 83 additions and 113 deletions.
    33 changes: 23 additions & 10 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,7 @@
    # gist raw perm HEAD [userscripts.org #130781](https://userscripts.org/scripts/show/130781 "https://userscripts.org/scripts/show/130781")
    # gist raw perm HEAD

    ## Install
    When you install user.js _**strongly recommends**_ on [**userscripts.org**](https://userscripts.org/scripts/show/130781 "https://userscripts.org/scripts/show/130781"). **NOT HERE**.
    - https://gist.github.com/noromanba/2370972/raw/gist-raw-perm-HEAD.user.js

    ## About
    Visit Gist and see 'raw' link, It's including **SHA-1 long hash name** like this.
    @@ -14,11 +14,11 @@ This user.js provide 'HEAD' links. It's takes **shrinked permanent raw link** a

    ### HEAD
    _**True Permalink**_: This is **absolutery permanent link** but it's _always filetype: txt_.
    <pre>https://raw.github.com/gist/2370972/</pre>
    <pre>https://gist.github.com/raw/2370972/</pre>

    ### HEAD(named)
    _**Almost Permalink**_: This is almost permanent link. It's _strict filetype_ by extension. **This link broken when filename changed**.
    <pre>https://raw.github.com/gist/2370972/gist-raw-perm-HEAD.user.js</pre>
    <pre>https://gist.github.com/raw/2370972/gist-raw-perm-HEAD.user.js</pre>
    This link most useful for install user.js from Gist.

    ## Known Problems
    @@ -29,29 +29,42 @@ _**HEAD**_ can accessible 1st file only. That is Gist API constraints.
    ### Binary 1st file
    e.g. [https://gist.github.com/890279/](https://gist.github.com/890279/)

    Access to raw: https://raw.github.com/gist/890279/. Expected https://raw.github.com/gist/890279/simple320_320.png, but actual API return [2nd text file data]("https://raw.github.com/gist/890279/gistfile1.txt").
    prob SOLVED, sort alphabetic? and text file order are top
    <s>
    access to raw
    https://gist.github.com/raw/890279/
    expected
    https://raw.github.com/gist/890279/simple320_320.png
    but actual API return [2nd text file data]("https://raw.github.com/gist/890279/gistfile1.txt").
    </s>

    ### Gist API
    Multifiles Gist has problem. Gist API is not provide true permalink(called _**HEAD**_) for 2nd or more files.

    #### [Gist API v3](http://developer.github.com/v3/gists/)
    Include content and history. it's too long too much than v1(closed).

    + [https://api.github.com/gists/2370972](https://api.github.com/gists/2370972)
    - [https://api.github.com/gists/2370972](https://api.github.com/gists/2370972)

    ## See also

    ### Gist HTTP
    e.g. [https://gist.github.com/2370972](https://gist.github.com/2370972)

    + GET 'raw' => HTTP 302
    OBSOLETE
    <s>
    - GET 'raw' => HTTP 302

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

    + => HTTP 200 OK
    - => HTTP 200 OK

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

    ### Bookmarklet
    Base code is small Bookmarklet, you can see [based rev.](http://let.hatelabo.jp/noromanba/let/gYC-ydWE_JP1JQ/rev/gYC-ydWE_JP9Jg "http://let.hatelabo.jp/noromanba/let/gYC-ydWE_JP1JQ/rev/gYC-ydWE_JP9Jg").
    Latest rev. permalink is [gist raw perm HEAD - Hatena::Let](http://let.hatelabo.jp/noromanba/let/gYC-ydWE_JP1JQ).
    base code is small Bookmarklet, you can see based rev below
    - http://let.hatelabo.jp/noromanba/let/gYC-ydWE_JP1JQ/rev/gYC-ydWE_JP9Jg
    latest permalink
    - http://let.hatelabo.jp/noromanba/let/gYC-ydWE_JP1JQ

    144 changes: 60 additions & 84 deletions gist-raw-perm-HEAD.user.js
    Original file line number Diff line number Diff line change
    @@ -1,109 +1,85 @@
    // ==UserScript==
    // @name gist raw perm HEAD
    // @namespace https://www.hatena.ne.jp/noromanba/
    // @description Add permanently HEAD links on Gist for UserScript
    // @namespace http://www.hatena.ne.jp/noromanba/
    // @description add permanently HEAD link on Gist for UserScript
    // @include https://gist.github.com/*
    // @version 2012.12.24.0
    // @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
    // @exclude https://gist.github.com/*/*/revisions
    // @grant none
    // @version 2014.12.20.0
    // @homepage https://gist.github.com/2370972
    // @downloadURL https://gist.github.com/noromanba/2370972/raw/gist-raw-perm-HEAD.user.js
    // @license MIT License http://nrm.mit-license.org/2012
    // @copyright (c) 2012 noromanba https://www.hatena.ne.jp/noromanba/
    // @author noromanba
    // @author noromanba http://noromanba.flavors.me
    // @icon https://upload.wikimedia.org/wikipedia/commons/thumb/9/9b/Color_icon_orange_v2.svg/32px-Color_icon_orange_v2.svg.png
    // @icon64 https://upload.wikimedia.org/wikipedia/commons/thumb/9/9b/Color_icon_orange_v2.svg/64px-Color_icon_orange_v2.svg.png
    // ==/UserScript==
    // Icon (Public Domain by Mizunoryu, Badseed, Jacobolus)

    // Icon (PD by Mizunoryu, Badseed, Jacobolus)
    // https://commons.wikimedia.org/wiki/File:Color_icon_orange_v2.svg

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

    (function () {
    var executeBrowserContext = (function () {
    var parent = document.head || document.documentElement || document.body;

    var container = document.createElement('script');
    container.type = 'text/javascript';
    container.charset = 'utf-8';
    parent.appendChild(container);

    return function (funcOrString) {
    container.appendChild(document.createTextNode('(' + funcOrString.toString() + ')();\n'));
    };
    })();
    // WIP
    // - [x] works well onload/DOMContentLoaded
    // - [ ] pjax:success/end handling
    // - can not use executeBrowserContext() (aka contentEval et al.)
    // - due to CSP, too much strict
    // - so can not touch page-context jQuery

    var appendButton = function code() {
    if (!(/^https:\/\/gist\.github\.com\/[\w-]+/.test(location.href)) ||
    document.querySelector('.gist-perm-button')) {
    var links;
    if (!/^https:\/\/gist\.github\.com\/[\w-]+\/\w+/.test(location.href) ||
    !(links = document.body.querySelectorAll('.files .raw-url:not(.head-url)'))) {
    return;
    }

    // TODO refactor to Gist{}
    var gistfile = function (rawNode) {
    var raw = rawNode,
    meta = raw.pathname.match(/\/raw\/([\w-]+)\/[\w-]+\/(.*)/),
    baseurl = 'https://raw.github.com/gist/',
    id = meta[1],
    basename = meta[2];

    return {
    raw: raw,
    id: id,
    name: basename,
    data: {
    name: basename.slice(basename.lastIndexOf('/') + 1),
    type: basename.split('.').length > 1 ? basename.split('.').pop() : 'N/D'
    },
    permalink: baseurl + id + '/'
    };
    };

    var gist = []; // more smart, into a gist{}
    Array.prototype.forEach.call(document.querySelectorAll('.actions .raw-url'), function (raw) {
    var namedHead = raw.cloneNode(true);
    var file = gistfile(raw);
    gist.push(file);

    // TODO remove redundant attr
    namedHead.href = file.permalink + file.name;
    namedHead.textContent = 'HEAD(named)';
    namedHead.title = file.name;
    namedHead.className += ' ' + 'gist-perm-button';
    // Firefox must be needs 2nd args c.f. https://developer.mozilla.org/en/DOM/element.insertBefore
    raw.parentNode.insertBefore(namedHead, null);
    });

    // https://raw.github.com/gist/ID/ => return 1st non-binary file. Gist API v3 protocol
    gist.some(function (file) {
    // TODO xhr to Gist API and get filetype, parse json or see response header
    if (/(?:png|bmp|jpe?g|gif)$/i.test(file.data.type)) return;

    var head = file.raw.cloneNode(true);
    head.href = file.permalink;
    head.textContent = 'HEAD';
    head.title = file.id + '.txt';
    file.raw.parentNode.insertBefore(head, file.raw.nextSibling);
    return true;
    Array.prototype.forEach.call(links, function (hashlink) {
    // <a aria-label="View Raw" href="/noromanba/2370972/raw/431c256a6a929a15867112d93bc82238a2723a47/README.md" data-skip-pjax="" class="minibutton raw-url js-view-raw">Raw</a>
    var perm = document.createElement('a');
    perm.textContent = 'HEAD';
    perm.ariaLabel = 'View HEAD';
    perm.dataset.skipPjax = '';
    perm.classList.add('minibutton', 'head-url');

    var pathnames = hashlink.href.split('/');
    var filename = pathnames.pop();
    var base = pathnames.slice(0, -1).join('/');
    perm.title = filename;
    //perm.textContent = filename;
    perm.href = base + '/' + filename;

    hashlink.parentNode.appendChild(perm);
    });
    };
    appendButton();

    // TODO independent of jQuery; replace to addEventListener/MutationObserver
    // c.f. https://github.com/defunkt/jquery-pjax#events
    jQuery('#js-pjax-container').on('load', function (evt) {
    code();
    });
    jQuery('#js-pjax-container').on('pjax:end', function (evt) {
    code();
    });
    }; // /appendButton

    executeBrowserContext(appendButton);
    // FIXME faild due to CSP, work w/ executeBrowserContext()
    /*/
    // TODO independent of jQuery; replace to MutationObserver
    // c.f. https://github.com/defunkt/jquery-pjax#events
    jQuery('#js-pjax-container').on('pjax:end', function () {
    appendButton();
    });
    //*/

    // FIXME 100% cpu usage
    /*/
    // c.f. MutationObserver
    // https://developer.mozilla.org/en-US/docs/Web/API/MutationObserver
    // http://caniuse.com/#feat=mutationobserver
    new MutationObserver(function (records) {
    //records.forEach(function (record) {
    appendButton();
    //});
    }).observe(document.body, { childList: true, subtree: true });
    //*/

    ////////////////////////////////////////////////////////////////////////////
    // DBG pjax handling
    // <at>require https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js
    // <at>require https://raw.github.com/defunkt/jquery-pjax/master/jquery.pjax.js
    // - https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js
    // - https://raw.github.com/defunkt/jquery-pjax/master/jquery.pjax.js
    /*/
    window.addEventListener('load', function (evt) {
    console.info(evt.type, evt);
    @@ -213,4 +189,4 @@
    console.log(evt.type, evt);
    });
    //*/
    })(); // /anonwrap
    })(); // /anonwrap
    19 changes: 0 additions & 19 deletions uso.html
    Original file line number Diff line number Diff line change
    @@ -1,19 +0,0 @@
    <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>:-)</h3>
    <p>Enjoy Gist and Coding!</p>

    Regards,<br />
    noromanba
  2. noromanba renamed this gist Dec 24, 2012. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  3. noromanba renamed this gist Dec 24, 2012. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  4. noromanba revised this gist Dec 24, 2012. 1 changed file with 216 additions and 147 deletions.
    363 changes: 216 additions & 147 deletions gist-raw-perm-HEAD.user.js
    Original file line number Diff line number Diff line change
    @@ -1,147 +1,216 @@
    // ==UserScript==
    // @name gist raw perm HEAD
    // @namespace https://www.hatena.ne.jp/noromanba/
    // @description Add permanently HEAD links on Gist for UserScript
    // @include https://gist.github.com/*
    // @version 2012.12.23.3
    // @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 https://www.hatena.ne.jp/noromanba/
    // @author noromanba
    // @icon https://upload.wikimedia.org/wikipedia/commons/thumb/9/9b/Color_icon_orange_v2.svg/32px-Color_icon_orange_v2.svg.png
    // @icon64 https://upload.wikimedia.org/wikipedia/commons/thumb/9/9b/Color_icon_orange_v2.svg/64px-Color_icon_orange_v2.svg.png
    // ==/UserScript==
    // <at>require https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js
    // <at>require https://raw.github.com/defunkt/jquery-pjax/master/jquery.pjax.js

    // Icon (Public Domain by Mizunoryu, Badseed, Jacobolus)
    // https://commons.wikimedia.org/wiki/File:Color_icon_orange_v2.svg

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

    // TODO smart pjax handling
    (function() {
    var appendButton = function () {
    if (!(/^https:\/\/gist\.github\.com\/[\w-]+/.test(location.href))) return;

    // TODO refactor to Gist{}
    var gistfile = function (rawNode) {
    var raw = rawNode,
    meta = raw.pathname.match(/\/raw\/([\w-]+)\/[\w-]+\/(.*)/),
    baseurl = 'https://raw.github.com/gist/',
    id = meta[1],
    basename = meta[2];

    return {
    raw: raw,
    id: id,
    name: basename,
    data: {
    name: basename.slice(basename.lastIndexOf('/') + 1),
    type: basename.split('.').length > 1 ? basename.split('.').pop() : 'N/D'
    },
    permalink: baseurl + id + '/'
    };
    };

    var gist = []; // more smart, into a gist{}
    Array.prototype.forEach.call(document.querySelectorAll('.actions .raw-url'), function (raw) {
    var namedHead = raw.cloneNode(true);
    var file = gistfile(raw);
    gist.push(file);

    // TODO remove redundant attr
    namedHead.href = file.permalink + file.name;
    namedHead.textContent = 'HEAD(named)';
    namedHead.title = file.name;
    // Firefox must be needs 2nd args c.f. https://developer.mozilla.org/en/DOM/element.insertBefore
    raw.parentNode.insertBefore(namedHead, null);
    });

    // https://raw.github.com/gist/ID/ => return 1st non-binary file. Gist API v3 protocol
    gist.some(function (file) {
    // TODO xhr to Gist API and get filetype, parse json or response header
    if (/(?:png|bmp|jpe?g|gif)$/i.test(file.data.type)) return;

    var head = file.raw.cloneNode(true);
    head.href = file.permalink;
    head.textContent = 'HEAD';
    head.title = file.id + '.txt';
    file.raw.parentNode.insertBefore(head, file.raw.nextSibling);
    return true;
    });
    };
    appendButton();

    ////////// pjax handling //////////
    /*/
    window.addEventListener('load', function (evt) {
    console.info(evt.type, evt);
    appendButton();
    }, false);
    // c.f. https://github.com/defunkt/jquery-pjax#events
    window.addEventListener('pjax:end', function (evt) {
    console.info(evt.type, evt);
    appendButton();
    }, false);
    window.addEventListener('pjax:success', function (evt) {
    console.info(evt.type, evt);
    appendButton();
    }, false);
    window.addEventListener('popstate', function(evt) {
    console.info(evt.type, evt);
    appendButton();
    },false );
    ////////// jQuery .on //////////
    // c.f. https://github.com/defunkt/jquery-pjax#events
    $(document).on('pjax:start', function(evt) {
    console.log(evt.type, evt);
    });
    $(document).on('pjax:end', function(evt) {
    console.log(evt.type, evt);
    });
    $(document).on('pjax:beforeSend', function(evt) {
    console.log(evt.type, evt);
    });
    $(document).on('pjax:send', function(evt) {
    console.log(evt.type, evt);
    });
    $(document).on('pjax:complete', function(evt) {
    console.log(evt.type, evt);
    });
    $(document).on('pjax:success', function(evt) {
    console.log(evt.type, evt);
    });
    $(document).on('pjax:error', function(evt) {
    console.log(evt.type, evt);
    });
    $(document).on('pjax:timeout', function(evt) {
    console.log(evt.type, evt);
    });
    $(document).on('pjax:send', function(evt) {
    console.log(evt.type, evt);
    });
    // $.pjax.submit only use of Gist c.f. https://github.com/defunkt/jquery-pjax#pjaxsubmit
    $(document).on('submit', function(evt) {
    console.log(evt.type, evt);
    });
    //*/


    /*/ // or .site-content
    Array.prototype.forEach.call(document.querySelectorAll('a[class="js-current-repository"], .gist-item .creator a'), function (trigger) {
    trigger.addEventListener('click', function () {
    appendButton();
    }, false);
    });
    //*/
    })();
    // ==UserScript==
    // @name gist raw perm HEAD
    // @namespace https://www.hatena.ne.jp/noromanba/
    // @description Add permanently HEAD links on Gist for UserScript
    // @include https://gist.github.com/*
    // @version 2012.12.24.0
    // @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 https://www.hatena.ne.jp/noromanba/
    // @author noromanba
    // @icon https://upload.wikimedia.org/wikipedia/commons/thumb/9/9b/Color_icon_orange_v2.svg/32px-Color_icon_orange_v2.svg.png
    // @icon64 https://upload.wikimedia.org/wikipedia/commons/thumb/9/9b/Color_icon_orange_v2.svg/64px-Color_icon_orange_v2.svg.png
    // ==/UserScript==
    // Icon (Public Domain by Mizunoryu, Badseed, Jacobolus)
    // https://commons.wikimedia.org/wiki/File:Color_icon_orange_v2.svg

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

    (function () {
    var executeBrowserContext = (function () {
    var parent = document.head || document.documentElement || document.body;

    var container = document.createElement('script');
    container.type = 'text/javascript';
    container.charset = 'utf-8';
    parent.appendChild(container);

    return function (funcOrString) {
    container.appendChild(document.createTextNode('(' + funcOrString.toString() + ')();\n'));
    };
    })();

    var appendButton = function code() {
    if (!(/^https:\/\/gist\.github\.com\/[\w-]+/.test(location.href)) ||
    document.querySelector('.gist-perm-button')) {
    return;
    }

    // TODO refactor to Gist{}
    var gistfile = function (rawNode) {
    var raw = rawNode,
    meta = raw.pathname.match(/\/raw\/([\w-]+)\/[\w-]+\/(.*)/),
    baseurl = 'https://raw.github.com/gist/',
    id = meta[1],
    basename = meta[2];

    return {
    raw: raw,
    id: id,
    name: basename,
    data: {
    name: basename.slice(basename.lastIndexOf('/') + 1),
    type: basename.split('.').length > 1 ? basename.split('.').pop() : 'N/D'
    },
    permalink: baseurl + id + '/'
    };
    };

    var gist = []; // more smart, into a gist{}
    Array.prototype.forEach.call(document.querySelectorAll('.actions .raw-url'), function (raw) {
    var namedHead = raw.cloneNode(true);
    var file = gistfile(raw);
    gist.push(file);

    // TODO remove redundant attr
    namedHead.href = file.permalink + file.name;
    namedHead.textContent = 'HEAD(named)';
    namedHead.title = file.name;
    namedHead.className += ' ' + 'gist-perm-button';
    // Firefox must be needs 2nd args c.f. https://developer.mozilla.org/en/DOM/element.insertBefore
    raw.parentNode.insertBefore(namedHead, null);
    });

    // https://raw.github.com/gist/ID/ => return 1st non-binary file. Gist API v3 protocol
    gist.some(function (file) {
    // TODO xhr to Gist API and get filetype, parse json or see response header
    if (/(?:png|bmp|jpe?g|gif)$/i.test(file.data.type)) return;

    var head = file.raw.cloneNode(true);
    head.href = file.permalink;
    head.textContent = 'HEAD';
    head.title = file.id + '.txt';
    file.raw.parentNode.insertBefore(head, file.raw.nextSibling);
    return true;
    });

    // TODO independent of jQuery; replace to addEventListener/MutationObserver
    // c.f. https://github.com/defunkt/jquery-pjax#events
    jQuery('#js-pjax-container').on('load', function (evt) {
    code();
    });
    jQuery('#js-pjax-container').on('pjax:end', function (evt) {
    code();
    });
    }; // /appendButton

    executeBrowserContext(appendButton);


    // DBG pjax handling
    // <at>require https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js
    // <at>require https://raw.github.com/defunkt/jquery-pjax/master/jquery.pjax.js
    /*/
    window.addEventListener('load', function (evt) {
    console.info(evt.type, evt);
    }, false);
    window.addEventListener('popstate', function (evt) {
    console.info(evt.type, evt);
    }, false);
    // c.f. https://github.com/defunkt/jquery-pjax#events
    window.addEventListener('pjax:start', function (evt) {
    console.log(evt.type, evt);
    }, false);
    window.addEventListener('pjax:end', function (evt) {
    console.log(evt.type, evt);
    }, false);
    window.addEventListener('pjax:beforeSend', function (evt) {
    console.log(evt.type, evt);
    }, false);
    window.addEventListener('pjax:send', function (evt) {
    console.log(evt.type, evt);
    }, false);
    window.addEventListener('pjax:complete', function (evt) {
    console.log(evt.type, evt);
    }, false);
    window.addEventListener('pjax:success', function (evt) {
    console.log(evt.type, evt);
    }, false);
    window.addEventListener('pjax:error', function (evt) {
    console.log(evt.type, evt);
    }, false);
    window.addEventListener('pjax:timeout', function (evt) {
    console.log(evt.type, evt);
    }, false);
    window.addEventListener('pjax:send', function (evt) {
    console.log(evt.type, evt);
    }, false);
    // $.pjax.submit only use of Gist c.f. https://github.com/defunkt/jquery-pjax#pjaxsubmit
    window.addEventListener('submit', function (evt) {
    console.log(evt.type, evt);
    }, false);
    ////////// jQuery .on //////////
    // c.f. https://github.com/defunkt/jquery-pjax#events
    $(document).on('pjax:start', function (evt) {
    console.log(evt.type, evt);
    });
    $(document).on('pjax:end', function (evt) {
    console.log(evt.type, evt);
    });
    $(document).on('pjax:beforeSend', function (evt) {
    console.log(evt.type, evt);
    });
    $(document).on('pjax:send', function (evt) {
    console.log(evt.type, evt);
    });
    $(document).on('pjax:complete', function (evt) {
    console.log(evt.type, evt);
    });
    $(document).on('pjax:success', function (evt) {
    console.log(evt.type, evt);
    });
    $(document).on('pjax:error', function (evt) {
    console.log(evt.type, evt);
    });
    $(document).on('pjax:timeout', function (evt) {
    console.log(evt.type, evt);
    });
    $(document).on('pjax:send', function (evt) {
    console.log(evt.type, evt);
    });
    $(document).on('submit', function (evt) {
    console.log(evt.type, evt);
    });
    // #js-pjax-container
    $('#js-pjax-container').on('submit', function (evt) {
    console.log(evt.type, evt);
    });
    $('#js-pjax-container').on('pjax:start', function (evt) {
    console.log(evt.type, evt);
    });
    $('#js-pjax-container').on('pjax:end', function (evt) {
    console.log(evt.type, evt);
    });
    $('#js-pjax-container').on('pjax:beforeSend', function (evt) {
    console.log(evt.type, evt);
    });
    $('#js-pjax-container').on('pjax:send', function (evt) {
    console.log(evt.type, evt);
    });
    $('#js-pjax-container').on('pjax:complete', function (evt) {
    console.log(evt.type, evt);
    });
    $('#js-pjax-container').on('pjax:success', function (evt) {
    console.log(evt.type, evt);
    });
    $('#js-pjax-container').on('pjax:error', function (evt) {
    console.log(evt.type, evt);
    });
    $('#js-pjax-container').on('pjax:timeout', function (evt) {
    console.log(evt.type, evt);
    });
    $('#js-pjax-container').on('pjax:send', function (evt) {
    console.log(evt.type, evt);
    });
    $('#js-pjax-container').on('submit', function (evt) {
    console.log(evt.type, evt);
    });
    //*/
    })(); // /anonwrap
  5. noromanba revised this gist Dec 23, 2012. 1 changed file with 146 additions and 85 deletions.
    231 changes: 146 additions & 85 deletions gist-raw-perm-HEAD.user.js
    Original file line number Diff line number Diff line change
    @@ -1,86 +1,147 @@
    // ==UserScript==
    // @name gist raw perm HEAD
    // @namespace https://www.hatena.ne.jp/noromanba/
    // @description Add permanently HEAD links on Gist for UserScript
    // @include https://gist.github.com/*
    // @version 2012.12.23.3
    // @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 https://www.hatena.ne.jp/noromanba/
    // @author noromanba
    // @icon https://upload.wikimedia.org/wikipedia/commons/thumb/9/9b/Color_icon_orange_v2.svg/32px-Color_icon_orange_v2.svg.png
    // @icon64 https://upload.wikimedia.org/wikipedia/commons/thumb/9/9b/Color_icon_orange_v2.svg/64px-Color_icon_orange_v2.svg.png
    // ==/UserScript==

    // Icon (Public Domain by Mizunoryu, Badseed, Jacobolus)
    // https://commons.wikimedia.org/wiki/File:Color_icon_orange_v2.svg

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

    // TODO smart pjax handling
    (function() {
    var appendButton = function () {
    if (!(/^https:\/\/gist\.github\.com\/[\w-]+/.test(location.href))) return;

    // TODO refactor to Gist{}
    var gistfile = function (rawNode) {
    var raw = rawNode,
    meta = raw.pathname.match(/\/raw\/([\w-]+)\/[\w-]+\/(.*)/),
    baseurl = 'https://raw.github.com/gist/',
    id = meta[1],
    basename = meta[2];

    return {
    raw: raw,
    id: id,
    name: basename,
    data: {
    name: basename.slice(basename.lastIndexOf('/') + 1),
    type: basename.split('.').length > 1 ? basename.split('.').pop() : 'N/D'
    },
    permalink: baseurl + id + '/'
    };
    };

    var gist = []; // more smart, into a gist{}
    Array.prototype.forEach.call(document.querySelectorAll('.actions .raw-url'), function (raw) {
    var namedHead = raw.cloneNode(true);
    var file = gistfile(raw);
    gist.push(file);

    // TODO remove redundant attr
    namedHead.href = file.permalink + file.name;
    namedHead.textContent = 'HEAD(named)';
    namedHead.title = file.name;
    // Firefox must be needs 2nd args c.f. https://developer.mozilla.org/en/DOM/element.insertBefore
    raw.parentNode.insertBefore(namedHead, null);
    });

    // https://raw.github.com/gist/ID/ => return 1st non-binary file. Gist API v3 protocol
    gist.some(function (file) {
    // TODO xhr to Gist API and get filetype, parse json or response header
    if (/(?:png|bmp|jpe?g|gif)$/i.test(file.data.type)) return;

    var head = file.raw.cloneNode(true);
    head.href = file.permalink;
    head.textContent = 'HEAD';
    head.title = file.id + '.txt';
    file.raw.parentNode.insertBefore(head, file.raw.nextSibling);
    return true;
    });
    };
    appendButton();

    // or .site-content
    /*/
    Array.prototype.forEach.call(document.querySelectorAll('a[class="js-current-repository"], .gist-item .creator a'), function (trigger) {
    trigger.addEventListener('click', function () {
    appendButton();
    }, false);
    });
    //*/
    // ==UserScript==
    // @name gist raw perm HEAD
    // @namespace https://www.hatena.ne.jp/noromanba/
    // @description Add permanently HEAD links on Gist for UserScript
    // @include https://gist.github.com/*
    // @version 2012.12.23.3
    // @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 https://www.hatena.ne.jp/noromanba/
    // @author noromanba
    // @icon https://upload.wikimedia.org/wikipedia/commons/thumb/9/9b/Color_icon_orange_v2.svg/32px-Color_icon_orange_v2.svg.png
    // @icon64 https://upload.wikimedia.org/wikipedia/commons/thumb/9/9b/Color_icon_orange_v2.svg/64px-Color_icon_orange_v2.svg.png
    // ==/UserScript==
    // <at>require https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js
    // <at>require https://raw.github.com/defunkt/jquery-pjax/master/jquery.pjax.js

    // Icon (Public Domain by Mizunoryu, Badseed, Jacobolus)
    // https://commons.wikimedia.org/wiki/File:Color_icon_orange_v2.svg

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

    // TODO smart pjax handling
    (function() {
    var appendButton = function () {
    if (!(/^https:\/\/gist\.github\.com\/[\w-]+/.test(location.href))) return;

    // TODO refactor to Gist{}
    var gistfile = function (rawNode) {
    var raw = rawNode,
    meta = raw.pathname.match(/\/raw\/([\w-]+)\/[\w-]+\/(.*)/),
    baseurl = 'https://raw.github.com/gist/',
    id = meta[1],
    basename = meta[2];

    return {
    raw: raw,
    id: id,
    name: basename,
    data: {
    name: basename.slice(basename.lastIndexOf('/') + 1),
    type: basename.split('.').length > 1 ? basename.split('.').pop() : 'N/D'
    },
    permalink: baseurl + id + '/'
    };
    };

    var gist = []; // more smart, into a gist{}
    Array.prototype.forEach.call(document.querySelectorAll('.actions .raw-url'), function (raw) {
    var namedHead = raw.cloneNode(true);
    var file = gistfile(raw);
    gist.push(file);

    // TODO remove redundant attr
    namedHead.href = file.permalink + file.name;
    namedHead.textContent = 'HEAD(named)';
    namedHead.title = file.name;
    // Firefox must be needs 2nd args c.f. https://developer.mozilla.org/en/DOM/element.insertBefore
    raw.parentNode.insertBefore(namedHead, null);
    });

    // https://raw.github.com/gist/ID/ => return 1st non-binary file. Gist API v3 protocol
    gist.some(function (file) {
    // TODO xhr to Gist API and get filetype, parse json or response header
    if (/(?:png|bmp|jpe?g|gif)$/i.test(file.data.type)) return;

    var head = file.raw.cloneNode(true);
    head.href = file.permalink;
    head.textContent = 'HEAD';
    head.title = file.id + '.txt';
    file.raw.parentNode.insertBefore(head, file.raw.nextSibling);
    return true;
    });
    };
    appendButton();

    ////////// pjax handling //////////
    /*/
    window.addEventListener('load', function (evt) {
    console.info(evt.type, evt);
    appendButton();
    }, false);
    // c.f. https://github.com/defunkt/jquery-pjax#events
    window.addEventListener('pjax:end', function (evt) {
    console.info(evt.type, evt);
    appendButton();
    }, false);
    window.addEventListener('pjax:success', function (evt) {
    console.info(evt.type, evt);
    appendButton();
    }, false);
    window.addEventListener('popstate', function(evt) {
    console.info(evt.type, evt);
    appendButton();
    },false );
    ////////// jQuery .on //////////
    // c.f. https://github.com/defunkt/jquery-pjax#events
    $(document).on('pjax:start', function(evt) {
    console.log(evt.type, evt);
    });
    $(document).on('pjax:end', function(evt) {
    console.log(evt.type, evt);
    });
    $(document).on('pjax:beforeSend', function(evt) {
    console.log(evt.type, evt);
    });
    $(document).on('pjax:send', function(evt) {
    console.log(evt.type, evt);
    });
    $(document).on('pjax:complete', function(evt) {
    console.log(evt.type, evt);
    });
    $(document).on('pjax:success', function(evt) {
    console.log(evt.type, evt);
    });
    $(document).on('pjax:error', function(evt) {
    console.log(evt.type, evt);
    });
    $(document).on('pjax:timeout', function(evt) {
    console.log(evt.type, evt);
    });
    $(document).on('pjax:send', function(evt) {
    console.log(evt.type, evt);
    });
    // $.pjax.submit only use of Gist c.f. https://github.com/defunkt/jquery-pjax#pjaxsubmit
    $(document).on('submit', function(evt) {
    console.log(evt.type, evt);
    });
    //*/


    /*/ // or .site-content
    Array.prototype.forEach.call(document.querySelectorAll('a[class="js-current-repository"], .gist-item .creator a'), function (trigger) {
    trigger.addEventListener('click', function () {
    appendButton();
    }, false);
    });
    //*/
    })();
  6. noromanba revised this gist Dec 23, 2012. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions gist-raw-perm-HEAD.user.js
    Original file line number Diff line number Diff line change
    @@ -3,7 +3,7 @@
    // @namespace https://www.hatena.ne.jp/noromanba/
    // @description Add permanently HEAD links on Gist for UserScript
    // @include https://gist.github.com/*
    // @version 2012.12.23.2
    // @version 2012.12.23.3
    // @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
    @@ -53,9 +53,9 @@
    gist.push(file);

    // TODO remove redundant attr
    namedHead.href = gist.permalink + gist.name;
    namedHead.href = file.permalink + file.name;
    namedHead.textContent = 'HEAD(named)';
    namedHead.title = gist.name;
    namedHead.title = file.name;
    // Firefox must be needs 2nd args c.f. https://developer.mozilla.org/en/DOM/element.insertBefore
    raw.parentNode.insertBefore(namedHead, null);
    });
  7. noromanba revised this gist Dec 23, 2012. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions gist-raw-perm-HEAD.user.js
    Original file line number Diff line number Diff line change
    @@ -3,7 +3,7 @@
    // @namespace https://www.hatena.ne.jp/noromanba/
    // @description Add permanently HEAD links on Gist for UserScript
    // @include https://gist.github.com/*
    // @version 2012.12.23.1
    // @version 2012.12.23.2
    // @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
    @@ -24,7 +24,7 @@
    // TODO smart pjax handling
    (function() {
    var appendButton = function () {
    if (!(/https:\/\/gist\.github\.com\/[\w-]+/.test(location.href))) return;
    if (!(/^https:\/\/gist\.github\.com\/[\w-]+/.test(location.href))) return;

    // TODO refactor to Gist{}
    var gistfile = function (rawNode) {
  8. noromanba revised this gist Dec 23, 2012. 1 changed file with 57 additions and 43 deletions.
    100 changes: 57 additions & 43 deletions gist-raw-perm-HEAD.user.js
    Original file line number Diff line number Diff line change
    @@ -3,7 +3,7 @@
    // @namespace https://www.hatena.ne.jp/noromanba/
    // @description Add permanently HEAD links on Gist for UserScript
    // @include https://gist.github.com/*
    // @version 2012.12.23.0
    // @version 2012.12.23.1
    // @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
    @@ -21,52 +21,66 @@
    // Devel
    // https://gist.github.com/2370972

    // TODO
    // - refactor and XHR in old rev
    // - remove redundant attr
    // - handle pjax
    // TODO smart pjax handling
    (function() {
    // FIXME refactor
    var gist = function(rawNode) {
    var raw = rawNode,
    meta = raw.pathname.match(/\/raw\/(\w+)\/\w+\/(.*)/),
    baseurl = 'https://raw.github.com/gist/',
    id = meta[1],
    basename = meta[2];
    var appendButton = function () {
    if (!(/https:\/\/gist\.github\.com\/[\w-]+/.test(location.href))) return;

    return {
    raw: raw,
    id: id,
    name: basename,
    file: {
    name: basename.slice(basename.lastIndexOf('/') + 1),
    type: basename.split('.').length > 1 ? basename.split('.').pop() : 'N/D'
    },
    permalink: baseurl + id + '/'
    // TODO refactor to Gist{}
    var gistfile = function (rawNode) {
    var raw = rawNode,
    meta = raw.pathname.match(/\/raw\/([\w-]+)\/[\w-]+\/(.*)/),
    baseurl = 'https://raw.github.com/gist/',
    id = meta[1],
    basename = meta[2];

    return {
    raw: raw,
    id: id,
    name: basename,
    data: {
    name: basename.slice(basename.lastIndexOf('/') + 1),
    type: basename.split('.').length > 1 ? basename.split('.').pop() : 'N/D'
    },
    permalink: baseurl + id + '/'
    };
    };
    };
    var files = []; // more smart, into gist{}
    Array.prototype.forEach.call(document.querySelectorAll('.actions .raw-url'), function(raw) {
    var namedHead = raw.cloneNode(true);
    var g = gist(raw);
    files.push(g);

    namedHead.href = g.permalink + g.name;
    namedHead.textContent = 'HEAD(named)';
    namedHead.title = g.name;
    // Fx must be needs 2nd args https://developer.mozilla.org/en/DOM/element.insertBefore
    raw.parentNode.insertBefore(namedHead, null);
    });
    var gist = []; // more smart, into a gist{}
    Array.prototype.forEach.call(document.querySelectorAll('.actions .raw-url'), function (raw) {
    var namedHead = raw.cloneNode(true);
    var file = gistfile(raw);
    gist.push(file);

    // TODO remove redundant attr
    namedHead.href = gist.permalink + gist.name;
    namedHead.textContent = 'HEAD(named)';
    namedHead.title = gist.name;
    // Firefox must be needs 2nd args c.f. https://developer.mozilla.org/en/DOM/element.insertBefore
    raw.parentNode.insertBefore(namedHead, null);
    });

    // FIXME refactor
    // 1st file only (Gist API constraints)
    (function(g) {
    if (!g) return;
    // https://raw.github.com/gist/ID/ => return 1st non-binary file. Gist API v3 protocol
    gist.some(function (file) {
    // TODO xhr to Gist API and get filetype, parse json or response header
    if (/(?:png|bmp|jpe?g|gif)$/i.test(file.data.type)) return;

    var head = g.raw.cloneNode(true);
    head.href = g.permalink;
    head.textContent = 'HEAD';
    head.title = g.id + '.txt';
    g.raw.parentNode.insertBefore(head, g.raw.nextSibling);
    })(files[0]);
    var head = file.raw.cloneNode(true);
    head.href = file.permalink;
    head.textContent = 'HEAD';
    head.title = file.id + '.txt';
    file.raw.parentNode.insertBefore(head, file.raw.nextSibling);
    return true;
    });
    };
    appendButton();

    // or .site-content
    /*/
    Array.prototype.forEach.call(document.querySelectorAll('a[class="js-current-repository"], .gist-item .creator a'), function (trigger) {
    trigger.addEventListener('click', function () {
    appendButton();
    }, false);
    });
    //*/
    })();
  9. noromanba renamed this gist Dec 23, 2012. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  10. noromanba revised this gist Dec 22, 2012. 1 changed file with 23 additions and 20 deletions.
    43 changes: 23 additions & 20 deletions gist-raw-perm-HEAD.user.js
    Original file line number Diff line number Diff line change
    @@ -3,33 +3,37 @@
    // @namespace https://www.hatena.ne.jp/noromanba/
    // @description Add permanently HEAD links on Gist for UserScript
    // @include https://gist.github.com/*
    // @version 2012.7.24.539
    // @version 2012.12.23.0
    // @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 (https://www.hatena.ne.jp/noromanba/)
    // @copyright (c) 2012 noromanba https://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
    // @icon https://upload.wikimedia.org/wikipedia/commons/thumb/9/9b/Color_icon_orange_v2.svg/32px-Color_icon_orange_v2.svg.png
    // @icon64 https://upload.wikimedia.org/wikipedia/commons/thumb/9/9b/Color_icon_orange_v2.svg/64px-Color_icon_orange_v2.svg.png
    // ==/UserScript==

    // Icon (Public Domain by Mizunoryu, Badseed, Jacobolus)
    // https://commons.wikimedia.org/wiki/File:Color_icon_orange_v2.svg

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

    // TODO refactor and XHR in old rev.
    // TODO
    // - refactor and XHR in old rev
    // - remove redundant attr
    // - handle pjax
    (function() {
    var raws = document.querySelectorAll('.actions > a');
    if (!raws) return;

    // FIXME refactor
    var gist = function(rawNode) {
    var raw = rawNode,
    meta = raw.pathname.match(/\/raw\/(\d+)\/\w+\/(.*)/),
    meta = raw.pathname.match(/\/raw\/(\w+)\/\w+\/(.*)/),
    baseurl = 'https://raw.github.com/gist/',
    id = meta[1],
    basename = meta[2];

    return {
    raw: raw,
    id: id,
    @@ -41,29 +45,28 @@
    permalink: baseurl + id + '/'
    };
    };

    var files = []; // more smart, into gist{}
    Array.prototype.forEach.call(raws, function(raw) {
    Array.prototype.forEach.call(document.querySelectorAll('.actions .raw-url'), function(raw) {
    var namedHead = raw.cloneNode(true);
    var g = gist(raw);
    files.push(g);

    namedHead.href = g.permalink + g.name;
    namedHead.textContent = 'HEAD(named)';
    namedHead.title = g.name;
    // Fx must be needs 2nd args https://developer.mozilla.org/en/DOM/element.insertBefore
    raw.parentNode.insertBefore(namedHead, null);
    });

    // FIXME refactor
    // 1st file only (Gist API constraints)
    (function(g) {
    if (g) {
    var head = g.raw.cloneNode(true);
    head.href = g.permalink;
    head.textContent = 'HEAD';
    head.title = g.id + '.txt';
    g.raw.parentNode.insertBefore(head, g.raw.nextSibling);
    }
    if (!g) return;

    var head = g.raw.cloneNode(true);
    head.href = g.permalink;
    head.textContent = 'HEAD';
    head.title = g.id + '.txt';
    g.raw.parentNode.insertBefore(head, g.raw.nextSibling);
    })(files[0]);
    })();
  11. noromanba revised this gist Jul 23, 2012. 3 changed files with 26 additions and 29 deletions.
    37 changes: 16 additions & 21 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -6,7 +6,7 @@ When you install user.js _**strongly recommends**_ on [**userscripts.org**](http
    ## About
    Visit Gist and see 'raw' link, It's including **SHA-1 long hash name** like this.

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

    ![gist-raw-HEAD](http://cdn-ak.f.st-hatena.com/images/fotolife/n/noromanba/20120413/20120413072715.png)

    @@ -21,42 +21,37 @@ _**Almost Permalink**_: This is almost permanent link. It's _strict filetype_ by
    <pre>https://raw.github.com/gist/2370972/gist-raw-perm-HEAD.user.js</pre>
    This link most useful for install user.js from Gist.

    ## Known Ploblems
    ## Known Problems

    ### Multifiles Gist
    _**HEAD**_ can accessible 1st file only. That is Gist API constraints.

    ### Binary 1st file
    cf. [https://gist.github.com/890279/](https://gist.github.com/890279/)
    e.g. [https://gist.github.com/890279/](https://gist.github.com/890279/)

    See raw data in https://raw.github.com/gist/890279/. Expected https://raw.github.com/gist/890279/simple320_320.png but actual API return 2nd file data. It's same as https://raw.github.com/gist/890279/gistfile1.txt.
    Access to raw: https://raw.github.com/gist/890279/. Expected https://raw.github.com/gist/890279/simple320_320.png, but actual API return [2nd text file data]("https://raw.github.com/gist/890279/gistfile1.txt").

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

    #### [Gist API v1(deprecated)](http://develop.github.com/p/gist.html)
    Very simple.

    + [https://gist.github.com/api/v1/json/2370972](https://gist.github.com/api/v1/json/2370972)
    Multifiles Gist has problem. Gist API is not provide true permalink(called _**HEAD**_) for 2nd or more files.

    #### [Gist API v3](http://developer.github.com/v3/gists/)
    Include content and history. It's too long too much.
    Include content and history. it's too long too much than v1(closed).

    + [https://api.github.com/gists/2370972](https://api.github.com/gists/2370972)

    ## Jot
    ## See also

    ### Gist raw HTTP
    This behavior on [HERE](https://gist.github.com/2370972).
    ### Gist HTTP
    e.g. [https://gist.github.com/2370972](https://gist.github.com/2370972)

    + GET 'raw' return HTTP 302
    + GET 'raw' => HTTP 302

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

    + HTTP 200 OK
    + => HTTP 200 OK

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

    ### Based on
    Base code is small Bookmarklet, you can see based rev. [HERE](http://let.hatelabo.jp/noromanba/let/gYC-ydWE_JP1JQ/rev/gYC-ydWE_JP9Jg "http://let.hatelabo.jp/noromanba/let/gYC-ydWE_JP1JQ/rev/gYC-ydWE_JP9Jg") on [Hatena::Let](http://let.hatelabo.jp/).
    Lateset rev. Permalink is [gist raw perm HEAD - Hatena::Let](http://let.hatelabo.jp/noromanba/let/gYC-ydWE_JP1JQ).
    ### Bookmarklet
    Base code is small Bookmarklet, you can see [based rev.](http://let.hatelabo.jp/noromanba/let/gYC-ydWE_JP1JQ/rev/gYC-ydWE_JP9Jg "http://let.hatelabo.jp/noromanba/let/gYC-ydWE_JP1JQ/rev/gYC-ydWE_JP9Jg").
    Latest rev. permalink is [gist raw perm HEAD - Hatena::Let](http://let.hatelabo.jp/noromanba/let/gYC-ydWE_JP1JQ).
    13 changes: 8 additions & 5 deletions gist-raw-perm-HEAD.user.js
    Original file line number Diff line number Diff line change
    @@ -1,27 +1,29 @@
    // ==UserScript==
    // @name gist raw perm HEAD
    // @namespace https://www.hatena.ne.jp/noromanba/
    // @description Add permanently HEAD links on Gist. Use for install user.js, (at)require xxx.js etc.
    // @description Add permanently HEAD links on Gist for UserScript
    // @include https://gist.github.com/*
    // @version 2012.5.1.0.31
    // @version 2012.7.24.539
    // @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 (https://www.hatena.ne.jp/noromanba/)
    // @license MIT License http://nrm.mit-license.org/2012
    // @copyright (c) 2012 noromanba (https://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]
    // Devel
    // https://gist.github.com/2370972

    // TODO refactor and XHR in old rev.
    (function() {
    var raws = document.querySelectorAll('.actions > a');
    if (!raws) return;

    // FIXME refactor
    var gist = function(rawNode) {
    var raw = rawNode,
    meta = raw.pathname.match(/\/raw\/(\d+)\/\w+\/(.*)/),
    @@ -53,6 +55,7 @@
    raw.parentNode.insertBefore(namedHead, null);
    });

    // FIXME refactor
    // 1st file only (Gist API constraints)
    (function(g) {
    if (g) {
    5 changes: 2 additions & 3 deletions userscripts.org.html
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,6 @@
    <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>
    <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>
    @@ -13,7 +12,7 @@ <h3>About</h3>
    <h3>Detail</h3>
    <p>Show technical details on <a href="https://gist.github.com/2370972" target="_blank">Gist: 2370972</a>.</p>

    <h3>:EOF</h3>
    <h3>:-)</h3>
    <p>Enjoy Gist and Coding!</p>

    Regards,<br />
  12. noromanba revised this gist May 2, 2012. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions gist-raw-perm-HEAD.user.js
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,7 @@
    // ==UserScript==
    // @name gist raw perm HEAD
    // @namespace https://www.hatena.ne.jp/noromanba/
    // @description Add permanently HEAD links on Gist. Use for install user.js or load xxx.js with (at)require etc.
    // @description Add permanently HEAD links on Gist. Use for install user.js, (at)require xxx.js etc.
    // @include https://gist.github.com/*
    // @version 2012.5.1.0.31
    // @homepage https://userscripts.org/scripts/show/130781
    @@ -53,7 +53,7 @@
    raw.parentNode.insertBefore(namedHead, null);
    });

    // 1st file only (Gist API constrains)
    // 1st file only (Gist API constraints)
    (function(g) {
    if (g) {
    var head = g.raw.cloneNode(true);
  13. noromanba revised this gist May 2, 2012. 1 changed file with 6 additions and 3 deletions.
    9 changes: 6 additions & 3 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,7 @@
    # gist raw perm HEAD [userscripts.org #130781](https://userscripts.org/scripts/show/130781 "https://userscripts.org/scripts/show/130781")

    ## Install
    When you install user.js _**strongly recommended**_ on [**userscripts.org**](https://userscripts.org/scripts/show/130781 "https://userscripts.org/scripts/show/130781"). **Not here**.
    When you install user.js _**strongly recommends**_ on [**userscripts.org**](https://userscripts.org/scripts/show/130781 "https://userscripts.org/scripts/show/130781"). **NOT HERE**.

    ## About
    Visit Gist and see 'raw' link, It's including **SHA-1 long hash name** like this.
    @@ -24,9 +24,12 @@ 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.
    _**HEAD**_ can accessible 1st file only. That is Gist API constraints.

    + ex. https://gist.github.com/2370972
    ### Binary 1st file
    cf. [https://gist.github.com/890279/](https://gist.github.com/890279/)

    See raw data in https://raw.github.com/gist/890279/. Expected https://raw.github.com/gist/890279/simple320_320.png but actual API return 2nd file data. It's same as https://raw.github.com/gist/890279/gistfile1.txt.

    ### Gist API
    Multifiles Gist has ploblem. Gist API not provide true permlink(bee called _**HEAD**_) for 2nd or more files.
  14. noromanba revised this gist Apr 30, 2012. 1 changed file with 6 additions and 5 deletions.
    11 changes: 6 additions & 5 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -1,10 +1,10 @@
    # gist raw perm HEAD [userscripts.org #130781](https://userscripts.org/scripts/show/130781 "https://userscripts.org/scripts/show/130781")

    ## Install
    When you install user.js _**strongly recommended**_ on [**Userscripts.org**](https://userscripts.org/scripts/show/130781 "https://userscripts.org/scripts/show/130781"). **Not here**.
    When you install user.js _**strongly recommended**_ on [**userscripts.org**](https://userscripts.org/scripts/show/130781 "https://userscripts.org/scripts/show/130781"). **Not here**.

    ## Behavior
    Visit Gist and see 'raw' link, It's including **long Hash name** like this.
    ## About
    Visit Gist and see 'raw' link, It's including **SHA-1 long hash name** like this.

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

    @@ -44,7 +44,7 @@ Include content and history. It's too long too much.
    ## Jot

    ### Gist raw HTTP
    cf. https://gist.github.com/2370972
    This behavior on [HERE](https://gist.github.com/2370972).

    + GET 'raw' return HTTP 302

    @@ -55,4 +55,5 @@ cf. https://gist.github.com/2370972
    <pre>https://raw.github.com/gist/2370972/2370972/47150711fedb7375d19d761ab122485b8105678d/gist-raw-perm-HEAD.user.js</pre>

    ### Based on
    [This Bookmarklet rev.](http://let.hatelabo.jp/noromanba/let/gYC-ydWE_JP1JQ/rev/gYC-ydWE_JP9Jg "http://let.hatelabo.jp/noromanba/let/gYC-ydWE_JP1JQ/rev/gYC-ydWE_JP9Jg") on [Hatena::Let](http://let.hatelabo.jp/).
    Base code is small Bookmarklet, you can see based rev. [HERE](http://let.hatelabo.jp/noromanba/let/gYC-ydWE_JP1JQ/rev/gYC-ydWE_JP9Jg "http://let.hatelabo.jp/noromanba/let/gYC-ydWE_JP1JQ/rev/gYC-ydWE_JP9Jg") on [Hatena::Let](http://let.hatelabo.jp/).
    Lateset rev. Permalink is [gist raw perm HEAD - Hatena::Let](http://let.hatelabo.jp/noromanba/let/gYC-ydWE_JP1JQ).
  15. noromanba revised this gist Apr 30, 2012. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion gist-raw-perm-HEAD.user.js
    Original file line number Diff line number Diff line change
    @@ -3,7 +3,7 @@
    // @namespace https://www.hatena.ne.jp/noromanba/
    // @description Add permanently HEAD links on Gist. Use for install user.js or load xxx.js with (at)require etc.
    // @include https://gist.github.com/*
    // @version 2012.4.30.2.58
    // @version 2012.5.1.0.31
    // @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
  16. noromanba revised this gist Apr 30, 2012. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions gist-raw-perm-HEAD.user.js
    Original file line number Diff line number Diff line change
    @@ -40,11 +40,11 @@
    };
    };

    var gists = []; // more smart, into gist{}
    var files = []; // more smart, into gist{}
    Array.prototype.forEach.call(raws, function(raw) {
    var namedHead = raw.cloneNode(true);
    var g = gist(raw);
    gists.push(g);
    files.push(g);

    namedHead.href = g.permalink + g.name;
    namedHead.textContent = 'HEAD(named)';
    @@ -62,5 +62,5 @@
    head.title = g.id + '.txt';
    g.raw.parentNode.insertBefore(head, g.raw.nextSibling);
    }
    })(gists[0]);
    })(files[0]);
    })();
  17. noromanba revised this gist Apr 30, 2012. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion gist-raw-perm-HEAD.user.js
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,7 @@
    // ==UserScript==
    // @name gist raw perm HEAD
    // @namespace https://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.
    // @description Add permanently HEAD links on Gist. Use for install user.js or load xxx.js with (at)require etc.
    // @include https://gist.github.com/*
    // @version 2012.4.30.2.58
    // @homepage https://userscripts.org/scripts/show/130781
  18. noromanba revised this gist Apr 29, 2012. 1 changed file with 4 additions and 4 deletions.
    8 changes: 4 additions & 4 deletions gist-raw-perm-HEAD.user.js
    Original file line number Diff line number Diff line change
    @@ -3,7 +3,7 @@
    // @namespace https://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.23.5.56
    // @version 2012.4.30.2.58
    // @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
    @@ -19,7 +19,7 @@
    // https://gist.github.com/2370972

    (function() {
    var raws = document.querySelectorAll('#gist-embed + a');
    var raws = document.querySelectorAll('.actions > a');
    if (!raws) return;

    var gist = function(rawNode) {
    @@ -49,11 +49,11 @@
    namedHead.href = g.permalink + g.name;
    namedHead.textContent = 'HEAD(named)';
    namedHead.title = g.name;
    // Fx must be needs 2nd args. cf. https://developer.mozilla.org/en/DOM/element.insertBefore
    // Fx must be needs 2nd args https://developer.mozilla.org/en/DOM/element.insertBefore
    raw.parentNode.insertBefore(namedHead, null);
    });

    // 1st file only (Gist API constrain)
    // 1st file only (Gist API constrains)
    (function(g) {
    if (g) {
    var head = g.raw.cloneNode(true);
  19. noromanba revised this gist Apr 22, 2012. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion gist-raw-perm-HEAD.user.js
    Original file line number Diff line number Diff line change
    @@ -3,7 +3,7 @@
    // @namespace https://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.23.5.41
    // @version 2012.4.23.5.56
    // @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
  20. noromanba revised this gist Apr 22, 2012. 1 changed file with 9 additions and 9 deletions.
    18 changes: 9 additions & 9 deletions gist-raw-perm-HEAD.user.js
    Original file line number Diff line number Diff line change
    @@ -1,15 +1,15 @@
    // ==UserScript==
    // @name gist raw perm HEAD
    // @namespace http://www.hatena.ne.jp/noromanba/
    // @namespace https://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.23.5.35
    // @version 2012.4.23.5.41
    // @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/)
    // @copyright (c) 2012+, noromanba (https://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
    @@ -23,11 +23,11 @@
    if (!raws) return;

    var gist = function(rawNode) {
    var raw = rawNode;
    var meta = raw.pathname.match(/\/raw\/(\d+)\/\w+\/(.*)/);
    var baseurl = 'https://raw.github.com/gist/';
    var id = meta[1];
    var basename = meta[2];
    var raw = rawNode,
    meta = raw.pathname.match(/\/raw\/(\d+)\/\w+\/(.*)/),
    baseurl = 'https://raw.github.com/gist/',
    id = meta[1],
    basename = meta[2];
    return {
    raw: raw,
    id: id,
    @@ -40,7 +40,7 @@
    };
    };

    var gists = []; // into gist{}..
    var gists = []; // more smart, into gist{}
    Array.prototype.forEach.call(raws, function(raw) {
    var namedHead = raw.cloneNode(true);
    var g = gist(raw);
  21. noromanba revised this gist Apr 22, 2012. 1 changed file with 4 additions and 4 deletions.
    8 changes: 4 additions & 4 deletions gist-raw-perm-HEAD.user.js
    Original file line number Diff line number Diff line change
    @@ -3,7 +3,7 @@
    // @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.23.4.33
    // @version 2012.4.23.5.35
    // @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
    @@ -40,8 +40,8 @@
    };
    };

    var gists = [];
    Array.forEach(raws, function(raw) {
    var gists = []; // into gist{}..
    Array.prototype.forEach.call(raws, function(raw) {
    var namedHead = raw.cloneNode(true);
    var g = gist(raw);
    gists.push(g);
    @@ -53,7 +53,7 @@
    raw.parentNode.insertBefore(namedHead, null);
    });

    // nonamed HEAD is 1st file only (Gist API constrain)
    // 1st file only (Gist API constrain)
    (function(g) {
    if (g) {
    var head = g.raw.cloneNode(true);
  22. noromanba revised this gist Apr 22, 2012. 1 changed file with 23 additions and 19 deletions.
    42 changes: 23 additions & 19 deletions gist-raw-perm-HEAD.user.js
    Original file line number Diff line number Diff line change
    @@ -3,7 +3,7 @@
    // @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
    // @version 2012.4.23.4.33
    // @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
    @@ -22,41 +22,45 @@
    var raws = document.querySelectorAll('#gist-embed + a');
    if (!raws) return;

    var gist = function(refNode) {
    var meta = refNode.pathname.match(/\/raw\/(\d+)\/\w+\/(.*)/);
    var gist = function(rawNode) {
    var raw = rawNode;
    var meta = raw.pathname.match(/\/raw\/(\d+)\/\w+\/(.*)/);
    var baseurl = 'https://raw.github.com/gist/';
    var id = meta[1];
    var basename = meta[2];
    return {
    raw: raw,
    id: id,
    // include directory -> 'foo/bar.txt' cf. https://gist.github.com/662233
    name: basename,
    // without directory -> 'bar.txt'
    file: {
    name: basename.slice(basename.lastIndexOf('/') + 1),
    type: basename.split('.').length > 1 ? basename.split('.').pop() : 'N/D'
    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 gists = [];
    Array.forEach(raws, function(raw) {
    var namedHead = raw.cloneNode(true);

    var g = gist(raw);
    gists.push(g);

    if (i === 0) {
    var head = raw.cloneNode(true);
    head.href = g.permalink;
    head.textContent = 'HEAD';
    head.title = 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 = g.name;
    // Fx must be needs 2nd args. cf. https://developer.mozilla.org/en/DOM/element.insertBefore
    raw.parentNode.insertBefore(namedHead, null);
    }
    });

    // nonamed HEAD is 1st file only (Gist API constrain)
    (function(g) {
    if (g) {
    var head = g.raw.cloneNode(true);
    head.href = g.permalink;
    head.textContent = 'HEAD';
    head.title = g.id + '.txt';
    g.raw.parentNode.insertBefore(head, g.raw.nextSibling);
    }
    })(gists[0]);
    })();
  23. noromanba revised this gist Apr 22, 2012. 1 changed file with 6 additions and 4 deletions.
    10 changes: 6 additions & 4 deletions gist-raw-perm-HEAD.user.js
    Original file line number Diff line number Diff line change
    @@ -29,8 +29,10 @@
    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'
    // include directory -> 'foo/bar.txt' cf. https://gist.github.com/662233
    name: basename,
    // without directory -> 'bar.txt'
    file: {
    name: basename.slice(basename.lastIndexOf('/') + 1),
    type: basename.split('.').length > 1 ? basename.split('.').pop() : 'N/D'
    },
    @@ -48,13 +50,13 @@
    var head = raw.cloneNode(true);
    head.href = g.permalink;
    head.textContent = 'HEAD';
    head.title = 'HEAD(' + g.id + '.txt)';
    head.title = 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 + ')';
    namedHead.title = g.name;
    raw.parentNode.insertBefore(namedHead, null);
    }
    })();
  24. noromanba revised this gist Apr 22, 2012. 1 changed file with 10 additions and 18 deletions.
    28 changes: 10 additions & 18 deletions gist-raw-perm-HEAD.user.js
    Original file line number Diff line number Diff line change
    @@ -22,27 +22,19 @@
    var raws = document.querySelectorAll('#gist-embed + a');
    if (!raws) return;

    var gist = function(rawnode) { // encapsulation
    var meta = rawnode.pathname.match(/\/raw\/(\d+)\/\w+\/(.*)/);
    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: function() {
    return id;
    },
    name: function() { // include directory -> 'foo/bar.txt' cf. https://gist.github.com/662233
    return basename;
    },
    file: function() { // without directory -> 'bar.txt'
    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: function() {
    return baseurl + id + '/';
    }
    permalink: baseurl + id + '/'
    };
    };

    @@ -54,15 +46,15 @@

    if (i === 0) {
    var head = raw.cloneNode(true);
    head.href = g.permalink();
    head.href = g.permalink;
    head.textContent = 'HEAD';
    head.title = 'HEAD(' + g.id() + '.txt)';
    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.href = g.permalink + g.name;
    namedHead.textContent = 'HEAD(named)';
    namedHead.title = 'HEAD(' + g.name() + ')';
    namedHead.title = 'HEAD(' + g.name + ')';
    raw.parentNode.insertBefore(namedHead, null);
    }
    })();
  25. noromanba renamed this gist Apr 22, 2012. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  26. noromanba revised this gist Apr 22, 2012. 1 changed file with 20 additions and 0 deletions.
    20 changes: 20 additions & 0 deletions gist-raw-perm-HEAD.html
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,20 @@
    <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
  27. noromanba revised this gist Apr 22, 2012. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions gist-raw-perm-HEAD.user.js
    Original file line number Diff line number Diff line change
    @@ -31,10 +31,10 @@
    id: function() {
    return id;
    },
    name: function() { // directory included -> 'foo/bar.txt' cf. https://gist.github.com/662233
    name: function() { // include directory -> 'foo/bar.txt' cf. https://gist.github.com/662233
    return basename;
    },
    file: function() { // without path -> 'bar.txt'
    file: function() { // without directory -> 'bar.txt'
    return {
    name: basename.slice(basename.lastIndexOf('/') + 1),
    type: basename.split('.').length > 1 ? basename.split('.').pop() : 'N/D'
  28. noromanba revised this gist Apr 20, 2012. 1 changed file with 27 additions and 26 deletions.
    53 changes: 27 additions & 26 deletions gist-raw-perm-HEAD.user.js
    Original file line number Diff line number Diff line change
    @@ -3,7 +3,7 @@
    // @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.19.4.41
    // @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
    @@ -21,35 +21,36 @@
    (function() {
    var raws = document.querySelectorAll('#gist-embed + a');
    if (!raws) return;


    var gist = function(rawnode) { // encapsulation
    var meta = rawnode.pathname.match(/\/raw\/(\d+)\/\w+\/(.*)/);
    var baseurl = 'https://raw.github.com/gist/';
    var id = meta[1];
    var basename = meta[2];
    return {
    id: function() {
    return id;
    },
    name: function() { // directory included -> 'foo/bar.txt' cf. https://gist.github.com/662233
    return basename;
    },
    file: function() { // without path -> 'bar.txt'
    return {
    name: basename.slice(basename.lastIndexOf('/') + 1),
    type: basename.split('.').length > 1 ? basename.split('.').pop() : 'N/D'
    };
    },
    permalink: function() {
    return baseurl + id + '/';
    }
    };
    };

    for (var i = 0; i < raws.length; i++) {
    var raw = raws[i];
    var namedHead = raw.cloneNode(true);

    var gist = function() { // encapsulation
    var meta = raw.pathname.match(/\/raw\/(\d+)\/\w+\/(.*)/);
    var baseurl = 'https://raw.github.com/gist/';
    var id = meta[1];
    var basename = meta[2];
    return {
    id: function() {
    return id;
    },
    name: function() { // directory included -> 'foo/bar.txt' cf. https://gist.github.com/662233
    return basename;
    },
    file: function() { // without path -> 'bar.txt'
    return {
    name: basename.slice(basename.lastIndexOf('/') + 1),
    type: basename.split('.').length > 1 ? basename.split('.').pop() : 'N/D'
    };
    },
    permalink: function() {
    return baseurl + id + '/';
    }
    };
    };
    var g = gist();
    var g = gist(raw);

    if (i === 0) {
    var head = raw.cloneNode(true);
  29. noromanba revised this gist Apr 18, 2012. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion gist-raw-perm-HEAD.html
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    <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>.
    <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
  30. noromanba revised this gist Apr 18, 2012. 1 changed file with 1 addition and 7 deletions.
    8 changes: 1 addition & 7 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -22,15 +22,9 @@ _**Almost Permalink**_: This is almost permanent link. It's _strict filetype_ by
    This link most useful for install user.js from Gist.

    ## Known Ploblems
    ### Directoried Gist

    _**HEAD(named)**_ do not detect directories.

    + ex. https://gist.github.com/662233
    Strict filename parsing or Use Gist API.

    ### Multifiles Gist
    _**HEAD**_ can accessible 1st file only. That is probably Gist API constraining.
    _**HEAD**_ can accessible 1st file only. That is Gist API constraining.

    + ex. https://gist.github.com/2370972