Last active
December 16, 2015 06:10
-
-
Save bluelovers/5389966 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Github Tool SC | |
// @namespace bluelovers | |
// @include https://gist.github.com/* | |
// @include https://github.com/* | |
// @version 1 | |
// @author bluelovers | |
// @exclude *.js* | |
// @exclude *.css* | |
// @grant none | |
// @require http://code.jquery.com/jquery-latest.js?KU201 | |
// @require https://gist.github.com/bluelovers/5046969/raw/UserScript%20Framework.js?KU207 | |
// ==/UserScript== | |
(function($){$(function(){ | |
var unsafeWindow = unsafeWindow || window; | |
var _url = window.location.href; | |
var _url_obj = parse_url(_url); | |
var _url_host = _url_obj.host; | |
if (_url_host.match(/gist\.github\.com/)) | |
{ | |
var _github = function(){ | |
_uf_log('_github'); | |
var _files = $('.gist.container .files > .bubble'); | |
if (_files.size()) | |
{ | |
var _newbutton = function(){ | |
var _li = $('<li/>'); | |
var _li_a = $('<a/>').addClass('file-actions-button tooltipped downwards').appendTo(_li); | |
var _li_s = $('<span>').addClass('mini-icon').appendTo(_li_a); | |
return [_li, _li_a, _li_s]; | |
}; | |
_files | |
.each(function(){ | |
var _this = $(this); | |
var _action_group = $('.file-actions .button-group', _this); | |
if (!_action_group.size()) return; | |
var _filename = $('.file-name', _this).text(); | |
var _id = $('.raw-url', _action_group).attr('href').split('/')[2]; | |
var _idname = $('.raw-url', _action_group).attr('href').split('/')[1]; | |
// _uf_log(_id); | |
var _new = [], _newi; | |
_newi = _newbutton(); | |
_newi[2].text('R1'); | |
_newi[1].attr({ | |
'href': 'https://raw.github.com/gist/' + _id + '/' + _filename, | |
'original-title': 'Hidden Username', | |
'title': 'Hidden Username', | |
'data-skip-pjax': '', | |
}); | |
_new.push(_newi); | |
_newi = _newbutton(); | |
_newi[2].text('R2'); | |
_newi[1].attr({ | |
'href': 'https://gist.github.com/'+ _idname + '/' + _id + '/raw/' + _filename, | |
'original-title': 'Show Username', | |
'title': 'Show Username', | |
'data-skip-pjax': '', | |
}); | |
_new.push(_newi); | |
$.map($.makeArray(_new), function(val, i) { | |
// _uf_log(val, i); | |
val[0].appendTo(_action_group); | |
}); | |
}) | |
; | |
} | |
}; | |
_github(); | |
var _do = true; | |
_uf_history_event(); | |
// unsafeWindow.onpopstate = unsafeWindow.history.onpushstate = function(event) { | |
// _uf_log('pushstate', event); | |
// }; | |
unsafeWindow.onpopstate = unsafeWindow.history.onreplacestate = function(event) | |
{ | |
if (_do) | |
{ | |
_do = false; | |
// _uf_log('replacestate', event); | |
setTimeout(function(){ | |
_github(); | |
_do = true; | |
}, 2500); | |
} | |
}; | |
var _li = $('.gist .root-pane .export-references li:eq(1)'); | |
if (_li.size()) | |
{ | |
var _m = _li.find('> input:first').attr('data-cptoggle-display').split('/'); | |
var _id = _m[2]; | |
var _idname = _m[1]; | |
var _clone = _li.clone(); | |
_clone | |
.find('input:first') | |
.val('git://gist.github.com/' + _id + '.git') | |
.attr('name', 'url-field1') | |
.removeAttr('data-cptoggle-display') | |
.removeClass(' js-url-field js-cptoggle') | |
.parent() | |
.find('> label:first') | |
.removeAttr('for') | |
; | |
_li.after(_clone); | |
var _clone = _li.clone(); | |
_clone | |
.find('input:first') | |
.val('[email protected]:' + _id + '.git') | |
.attr('name', 'url-field1') | |
.removeAttr('data-cptoggle-display') | |
.removeClass(' js-url-field js-cptoggle') | |
.parent() | |
.find('> label:first') | |
.removeAttr('for') | |
; | |
_li.after(_clone); | |
} | |
} | |
else if (_url_host.match(/github\.com/)) | |
{ | |
var _home = $('a.js-repo-home-link'); | |
if (_home.size()) | |
{ | |
var _d = _home.attr('href').split('/'); | |
var _gh_pages = $('.select-menu-list .select-menu-item a[data-name="gh-pages"]').size(); | |
//_uf_log('gh-pages: ' + _gh_pages); | |
if (_gh_pages) | |
{ | |
var _a = $('<a>gh-pages</a>').css('color' ,'#999').attr('target', '_blank').attr('href', 'http://' + _d[1] + '.github.io/' + _d[2] + '/'); | |
//$('.repository-meta').append($('<div/>').append(_a); | |
_home.parent('strong').after(_a).after('<span class="path-divider">/</span>'); | |
} | |
} | |
} | |
function _uf_log(object) | |
{ | |
var args = Array.prototype.slice.call(arguments, 0) || []; | |
// throw new Error(args.toString()); | |
if (typeof console != "undefined") | |
{ | |
return console.log.apply(console, args); | |
} | |
} | |
function _uf_history_event() | |
{ | |
(function(history){ | |
var pushState = history.pushState; | |
history.pushState = function() { | |
if (typeof history.onpushstate == "function") { | |
// history.onpushstate({state: state}); | |
history.onpushstate(arguments); | |
} | |
// $(window).trigger('pushstate', arguments); | |
// ... whatever else you want to do | |
// maybe call onhashchange e.handler | |
return pushState.apply(history, arguments); | |
}; | |
var replaceState = history.replaceState; | |
history.replaceState = function() { | |
if (typeof history.onreplacestate == "function") { | |
// history.onpushstate({state: state}); | |
history.onreplacestate(arguments); | |
} | |
// $(window).trigger('replacestate', arguments); | |
// ... whatever else you want to do | |
// maybe call onhashchange e.handler | |
return replaceState.apply(history, arguments); | |
}; | |
})(unsafeWindow.history); | |
} | |
})})(jQuery.noConflict()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment