Skip to content

Instantly share code, notes, and snippets.

@titaniumbones
Created January 26, 2017 13:44
Show Gist options
  • Save titaniumbones/34594a187f191addd517fae12942550a to your computer and use it in GitHub Desktop.
Save titaniumbones/34594a187f191addd517fae12942550a to your computer and use it in GitHub Desktop.
does some munging on the versionista UI to simplify click-through process
/ How far back to go, in milliseconds (7 days = 604800000 ms).
var threshold = new Date() - 604800000;
$('#siteView tbody tr').filter(function () {
// Only add click handlers on the links to pages that have previous versions and that have changed recently.
return parseInt($('td:eq(6)', this).text()) > 1 && new Date($('td:eq(8)', this).text()) >= threshold;
}).find('td:eq(3)').css('background-color', '#ff0').end().each(function () {
// Change the behavior of the link in the "URL" column.
var a = $('a:eq(1)', this);
a.click(function (event) {
// Stop the original link from opening.
event.preventDefault();
// Download the page at the original link.
var url = 'https://versionista.com' + a.attr('href');
$.get(url, function (data) {
// The timestamps and version IDs are stored in the HTML.
var timestamp_regex = /"fst":"(\d+)"/g;
var version_regex = /"cid":"(\d+)"/g;
var timestamps = [];
while ((match = timestamp_regex.exec(data)) !== null) {
timestamps.push(parseInt(match[1]) * 1000);
}
var versions = [];
while ((match = version_regex.exec(data)) !== null) {
versions.push(match[1]);
}
var compare_to_version = '0';
timestamps.slice(1).forEach(function (timestamp, i) {
if (timestamp >= threshold) {
compare_to_version = versions[i + 1];
}
});
window.open(url + versions[0] + ':' + compare_to_version + '/', '_blank').focus();
})
});
});
@jpmckinney
Copy link

@titaniumbones Missing / at start of first line :)

@jpmckinney
Copy link

jpmckinney commented Jan 26, 2017

For reference, the spreadsheet that people are filling in has the columns: Index,Who found this,Date/Time,Agency,Page Name,URL,Page View URL,Comparison URL,Description of Change,Similar Changes,IA Corroboration,PageFreeze Corroboration,Marks as Example of Significant Change,Mark as example of Exemplary Change

Consider adding code to add a button to the comparison page that would fill in (Who found this would need to be configured by a bookmarklet generator): Who found this,Date/Time,Agency,Page Name,URL,Page View URL,Comparison URL

@jpmckinney
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment