Wayback Machine Timeline Compressor

Trims the capture graph timeline to only the earliest and latest years

Fra 19.01.2016. Se den seneste versjonen.

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name          Wayback Machine Timeline Compressor
// @namespace     DoomTay
// @description   Trims the capture graph timeline to only the earliest and latest years
// @version       1.0.0
// @include       /http(?:s?):\/\/(web|wayback)\.archive\.org\/web\//
// @grant         none

// ==/UserScript==

var smallTimeline = document.querySelector("#sparklineImgId[width = \"525\"]");
var bigTimeline = document.querySelector("#sparklineImgId[width = \"1029\"]");

if(smallTimeline)
{
	smallTimeline.src = smallTimeline.src.replace(/(\/web\/jsp\/graph\.jsp\?graphdata=525_27)(?:_\d\d\d\d:-1:000000000000)+|(?:_\d\d\d\d:-1:000000000000)+$/g, "$1");
	
	var startYear = parseInt(smallTimeline.src.substr(smallTimeline.src.search(/\d\d\d\d:/),4));
	var lastYear = parseInt(smallTimeline.src.substr(smallTimeline.src.search(/\d\d\d\d(?!.*\d\d\d\d:)/),4));
	var yearRange = (lastYear - startYear) + 1;
	var scripts = document.scripts;
	for(var s = 0; s < scripts.length; s++)
	{
		if(scripts[s].innerHTML.indexOf("525, 27") > -1)
		{
			var newScript = document.createElement('script');
			newScript.type = "text/javascript";
			newScript.innerHTML = scripts[s].innerHTML.replace("(525, 27, 25, 2)","(525, 27, " + (525 / yearRange) + ", " + (525 - yearRange)/(12 * yearRange) + ")").replace(/firstYear = \d\d\d\d/,"firstYear = " + startYear);
			document.body.appendChild(newScript);
			__wm.bt();
			break;
		}
	}
}

if(bigTimeline)
{
	bigTimeline.src = bigTimeline.src.replace(/(\/web\/jsp\/graph.jsp\?nomonth=1&graphdata=1029_75)(?:_\d\d\d\d:-1:000000000000)+|(?:_\d\d\d\d:-1:000000000000)+$/g, "$1");
	
	var lastYear = parseInt(bigTimeline.src.substr(bigTimeline.src.search(/\d\d\d\d(?!.*\d\d\d\d:)/),4));							
	
	window.firstYear = parseInt(bigTimeline.src.substr(bigTimeline.src.search(/\d\d\d\d:/),4));
	window.startYear = parseInt(window.location.href.substr(window.location.href.indexOf("http://web.archive.org/web/") + 27,4)) - firstYear;
	var yearRange = (lastYear - firstYear) + 1;
	window.yearImgWidth = (1029 / yearRange);
	window.monthImgWidth = (1029 - yearRange)/(12 * yearRange);
	document.getElementById("wbMouseTrackYearImg").style.width = (Math.round(10*yearImgWidth)/10) + "px";
	var yearLabels = document.getElementsByClassName("year-label");
	for(var y = 0; y < yearLabels.length; y++)
	{
		while(y < yearLabels.length && (yearLabels[y].dataset.year > lastYear || yearLabels[y].dataset.year < firstYear)) yearLabels[y].parentNode.removeChild(yearLabels[y]);
		if(y >= yearLabels.length) continue;
		yearLabels[y].style.width = Math.floor(1029 /yearRange) + "px";
	}
}