Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save BrockA/5761948 to your computer and use it in GitHub Desktop.
Save BrockA/5761948 to your computer and use it in GitHub Desktop.
Adds a link to the timeline view to questions. This is a userscript for Stack Exchange sites.
// ==UserScript==
// @name Stack Exchange: Add Timeline and Revisions links to posts
// @description Adds links to posts to always show history and links to questions to show the Timeline".
// @namespace StackExchange
// @match *://*.askubuntu.com/questions/*
// @match *://*.mathoverflow.net/questions/*
// @match *://*.serverfault.com/questions/*
// @match *://*.stackapps.com/questions/*
// @match *://*.stackexchange.com/questions/*
// @match *://*.stackoverflow.com/questions/*
// @match *://*.superuser.com/questions/*
// @noframes
// @version 1.5
// @history 1.5 Updated Metadata and Lint config for Tampermonkey changes and performance.
// @history 1.4 SE renamed `short-link` to `js-share-link`.
// @history 1.3 SE changed Timelines. Answers were separated out from the question timeline.
// @history 1.2 Updated match list
// @history 1.1 Added revisions link
// @grant none
// @author Brock Adams, pascalhein, PeterJ
// @homepage https://stackapps.com/a/4150/7653
// @updateURL https://gist.github.com/BrockA/5761948/raw/Add_Timeline_Button_to_Stack_Exchange_questions.user.js
// ==/UserScript==
/* global $ */
/* eslint-disable no-multi-spaces */
$(".post-menu").each ( function (J) {
var jThis = $(this);
var href = jThis.find ('a[class="js-share-link"]').attr ("href");
var idMtch = href.split (/[qa]\/(\d+)/);
if (idMtch.length > 2) {
var id = idMtch[1];
jThis.append (
'<span class="lsep">|</span><a href="/posts/' + id + '/revisions">revisions</a>'
);
jThis.append (
'<span class="lsep">|</span><a href="/posts/' + id + '/timeline">timeline</a>'
);
}
} );
$(".revcell3.vm>div").each (function () {
var guid = $(this).find ("a").attr ("href").match (/\w{8} (?:-\w{4} ){3}-\w{12}/)[0];
$(this).prepend ('<a href="#rev' + guid + '">link</a><span class="lsep">|</span>');
} );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment