idan / gistio

A gist-backed pretty display for markdown.
https://gist.io
MIT License
488 stars 41 forks source link

Bookmarklet leads to 404 page #60

Closed quchen closed 7 years ago

quchen commented 11 years ago

Hey, when I use the bookmarklet to convert e.g. https://gist.github.com/quchen/5284753 I'm redirected to http://gist.io/quchen/5284753, which does not exist. Deleting my username manually then yields the correct URL http://gist.io/5284753.

(Could be that my Firefox 16 has some JS bug though.)

idan commented 11 years ago

Known issue, fix is in the works—apologies!

On Saturday, October 12, 2013 at 8:02 PM, David Luposchainsky wrote:

Hey, when I use the bookmarklet to convert e.g. https://gist.github.com/quchen/5284753 I'm redirected to http://gist.io/quchen/5284753, which does not exist. Deleting my username manually then yields the correct URL http://gist.io/5284753.

— Reply to this email directly or view it on GitHub (https://github.com/idan/gistio/issues/60).

zigomir commented 11 years ago

I've just modified bookmarklet so that it works for me.

I will share it here since I'm not sure that covers all the edge cases and is good enough for PR

javascript: (function (e, a, g, h, f, c, b, d) {
    if (!(f = e.jQuery) || g > f.fn.jquery || h(f)) {
        c = a.createElement('script');
        c.type = 'text/javascript';
        c.src = 'http://ajax.googleapis.com/ajax/libs/jquery/' + g + '/jquery.min.js';
        c.onload = c.onreadystatechange = function () {
            if (!b && (!(d = this.readyState) || d == 'loaded' || d == 'complete')) {
                h((f = e.jQuery).noConflict(1), b = 1);
                f(c).remove()
            }
        };
        a.documentElement.childNodes[0].appendChild(c)
    }
})(window, document, '1.4.2', function ($, L) {
    var gist_re = /^https?\:\/\/gist\.github\.com\/(\d*)/i,
        rel_re = /^\/?(\d+)$/,
        on_gist = gist_re.test(location.href);
    if (on_gist) {
        var path_array = location.pathname.split('/');
        var gist_id_index = path_array.length - 1;
        var gist_id = path_array[gist_id_index].replace('/', '');
        location.href = 'http://gist.io/' + gist_id;
    } else {
        $('a').each(function () {
            var b = $(this).attr('href') || '',
                a = b.match(gist_re);
            if (on_gist && !(a && a[1])) {
                a = b.match(rel_re)
            }
            if (a && a[1]) {
                $(this).after(' <a href="http://gist.io/' + a[1] + '">[gist.io]</a>')
            }
        });
    }
});