Skip to content

Instantly share code, notes, and snippets.

@kaelig
Last active August 29, 2015 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kaelig/9838774 to your computer and use it in GitHub Desktop.
Save kaelig/9838774 to your computer and use it in GitHub Desktop.
Wraith enhancer for Tamper Monkey (http://tampermonkey.net/)
// ==UserScript==
// @name Wraith enhancer
// @match Your Wraith URL, eg: http://www.domain.tld/wraith/*
// @version 0.1
// @require http://code.jquery.com/jquery-latest.js
// @copyright 2014+, Kaelig Deloumeau-Prigent (@kaelig)
// ==/UserScript==
$(document).ready(function() {
var thereWasADiff = false,
bytes,
diff,
prod;
// Wrap screenshots and path name in different containers
$('h2').each(function() {
$(this).parent().addClass('new-row');
});
$('.new-row').each(function() {
$(this).nextUntil('.new-row').andSelf().wrapAll('<div class="diff-set"></div>');
});
$('.diff-set').addClass('no-diff').each(function() {
$(this).find('h2').prepend('<small><span class="label label-success">Success</span></small> ');
});
// Loop through all the screenshots and spot failed tests
$('.text-center.text-muted').each(function() {
if ($(this).text().trim().replace("\n", "") != "0 bytes") {
thereWasADiff = true;
$(this).parents('.diff-set').addClass('has-diff').removeClass('no-diff').find('.label').removeClass('label-success').addClass('label-danger').text('Difference spotted');
$(this).parent().find('a img').css({'border-color': 'rgb(217, 83, 79)', 'border-width': 2});
}
});
// If a test has failed, show only failed tests
if (thereWasADiff) {
$('.no-diff').hide();
$('<button class="btn btn-primary btn-xs">Toggle</button> <span class="text-muted"><span class="hide-show">Showing failed tests only</span> <span class="hide-show hide-show--hide">Showing all tests</span></span>')
.appendTo('.page-header')
.css('cursor', 'pointer')
.on('click', function() {
$('.no-diff').toggle();
$('.hide-show').toggle();
});
$('.hide-show--hide').hide();
} else {
$('<div class="alert alert-success"><strong>Well done!</strong> Wraith could not spot any visual regressions in this build.</div>').appendTo('.page-header');
}
// Layouts fixes
$('.page-header').wrapInner('<div class="col-lg-12" />');
$('.col-lg-2').removeClass().addClass('col-lg-3');
$('.col-lg-10').removeClass().addClass('col-lg-9');
$('.diff-set > .row > .col-lg-3').css({width: 240});
// Put the diff in the middle between code and prod
$('.diff-set > .row').each(function() {
diff = $(this).find('.col-lg-3').eq(1);
prod = $(this).find('.col-lg-3').eq(2);
prod.after(diff.clone());
diff.remove();
});
$('.diff-set > .row > .col-lg-1, h2 small').css({float: 'left', width: 150});
// Style "difference spotted" and "success" labels
$('h2 small').css({'margin-right': 15, 'margin-top': 8});
// Open screenshots in a new window
$('.diff-set a').on('click', function() {
$(this).attr('target', '_blank');
});
// Make sidebar links easier to click
$('.list-group-item a').css({display: 'block'});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment