Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save roryokane/3701499 to your computer and use it in GitHub Desktop.
Save roryokane/3701499 to your computer and use it in GitHub Desktop.
UserScript: Hide GitHub Project Page Latest Commit
// ==UserScript==
// @name Hide GitHub Project Page Latest Commit
// @namespace roryokane
// @include /^https?://github\.com/[^/]+/[^/]+/?$/
// @require https://ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min.js
// ==/UserScript==
// GreaseMonkey doesn't fire on pushState and popState right now,
// so the box is reshown and not rehidden when going forward and back to the page again
// TODO work around – at least make toggle link recognize when it’s been thwarted
var commit_tease_box = $('.commit-tease')
var commit_label = $('.last-commit')
var page_items_exist = (commit_tease_box.size !== 0 && commit_label.size !== 0)
if (! page_items_exist) {
return
// TODO encapsulate this error check. How to return from within a function?
// Try http://stackoverflow.com/q/4651452/578288
}
var saveLabelMarginBottom = function() {
commit_label.data('original margin-bottom', commit_label.css('margin-bottom'))
}
var hideLatestCommit = function() {
commit_tease_box.hide()
commit_label.css({'margin-bottom': commit_tease_box.css('margin-bottom') })
}
var showLatestCommit = function() {
commit_tease_box.show()
commit_label.css({'margin-bottom': commit_label.data('original margin-bottom') })
}
var addTimeOfCommitToLabel = function() {
// copy time of latest commit to the small label
var commit_times = commit_tease_box.find('.authorship time')
// if GitHub shows both author and commit times (because they’re different), copy just the author time
// because that’s the time GitHub emphasizes in its interface
// the author time is before the commit time in the DOM
var commit_time = commit_times.first()
commit_label.append(" (", commit_time.clone(), ")")
}
var doAfterGitHubSubstitutesTimes = function(callback) {
setTimeout(callback, 0.2 * 1000)
}
var addCommitShowHideLinkToCommitLabel = function() {
var toggle_link = $('<a class="toggle_commit_tease_box_visibility" href="javascript:"></a>')
// TODO hide underline for that link (but keep link color and pointer)
// TODO require Underscore library so a part of the below will work
// TODO finish this section: generic state-changer-linker
// linkStates = {
// 'show': {
// 'text': '▼'
// 'action': hideLatestCommit
// },
// 'hide': {
// 'text': '▲'
// 'action': showLatestCommit
// }
// }
// var linkStateSetterFunction = function(stateName) {
// return function() {
// toggle_link.text(linkStates[stateName]['text'])
// toggle_link.data('action', stateName)
// var clickFunction = linkStates[stateName]['action']
// }
// }
// var linkStateFunctions = {};
// _(linkStates).each(function(key, value) {
// linkStateFunctions[key] = linkStateSetterFunction(value)
// })
var makeLinkShow = function() {
toggle_link.text('▼')
toggle_link.data('action', 'show')
}
var makeLinkHide = function() {
toggle_link.text('▲')
toggle_link.data('action', 'hide')
}
makeLinkShow()
toggle_link.bind('click', function(event) {
if (toggle_link.data('action') === 'show') {
showLatestCommit()
makeLinkHide()
} else {
hideLatestCommit()
makeLinkShow()
}
event.preventDefault()
})
commit_label.append(" ", toggle_link)
}
saveLabelMarginBottom()
hideLatestCommit()
addTimeOfCommitToLabel()
doAfterGitHubSubstitutesTimes(
addCommitShowHideLinkToCommitLabel
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment