-
Notifications
You must be signed in to change notification settings - Fork 0
/
magiccards-preview.user.js
85 lines (69 loc) · 2.86 KB
/
magiccards-preview.user.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
// ==UserScript==
// @name Magiccards.info checklist preview of images
// @description enter something useful
// @namespace http://magiccards.info/
// @version 1.0
// @grant none
// @author Petter
// @namespace https://github.com/petterm/Magiccards.info-checklist-image-preview
// @repository https://github.com/petterm/Magiccards.info-checklist-image-preview.git
// @license MIT
// @require https://ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js
//
// @include http://magiccards.info/*.html
//
// @updateURL https://github.com/petterm/Magiccards.info-checklist-image-preview/blob/master/magiccards-preview.user.js
// @downloadURL https://github.com/petterm/Magiccards.info-checklist-image-preview/blob/master/magiccards-preview.user.js
// @homepage https://github.com/petterm/Magiccards.info-checklist-image-preview
// ==/UserScript==
jQuery('head').append('<link rel="stylesheet" href="https://cdn.rawgit.com/jninnes/mtgicons/v1.2.1/dist/mtgicons.css" />');
jQuery(function($) {
var preview = $('<div id="__test" style="position: fixed; top: 20px; right: 20px;"></div>').appendTo('body');
var pImage = $('<img src="" />').appendTo(preview);
preview.on('mouseenter', function() {
preview.hide();
});
var replaceManaSymbols = function(html) {
var reg = /(\d*)([XYZWUBRG]*)/.exec(html);
var parts = reg[2].split('');
var result = '<i class="mtg mana-' + reg[1] + '"></i>';
$.each(parts, function(key, value){
result += '<i class="mtg mana-' + value.toLowerCase() + '"></i>';
});
return result;
};
var activePreview = undefined;
var showPreview = function(link) {
var cardUrl = link.attr('href');
activeTooltip = cardUrl;
$.get(cardUrl, function(document) {
if (activeTooltip == cardUrl) {
var image = /"(http:\/\/magiccards.info\/scans.+\.jpg)"/.exec(document);
pImage.attr('src', image[1]);
preview.show();
//preview.appendTo(link.parent());
}
});
};
var hidePreview = function() {
//preview.detach().hide();
};
// Mana symbols
$('table tr[class="even"] td:nth-child(4), table tr[class="odd"] td:nth-child(4)').each(function(){
var $this = $(this);
var html = $this.html();
if (/^\d*[XYZWUBRG]*$/.test(html) && html != '') {
$this.html(replaceManaSymbols(html));
}
});
// Cardname tooltip
$('table tr[class="even"] td:nth-child(2) a, table tr[class="odd"] td:nth-child(2) a').each(function(){
var $this = $(this);
$this.on('mouseenter', function(){
showPreview($this);
});
$this.on('mouseleave', function(){
hidePreview();
});
});
});