-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathwindowShopping.user.js
66 lines (52 loc) · 2.48 KB
/
windowShopping.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
// ==UserScript==
// @name PouetWindowShopping
// @version 0.0.1
// @description Small screenshots on prodlists views
// @match http://pouet.net/groups.php?which*
// @match http://pouet.net/party.php?which*
// @match http://*.pouet.net/groups.php?which*
// @match http://*.pouet.net/party.php?which*
// @copyright 2013+, [email protected]
// ==/UserScript==
var MAX_IMG_HEIGHT = 48,
IMG_BACKGROUND = '',//'#000',
TYPES = ['jpg', 'gif', 'png'];
var isPartyPage = !!document.querySelector("#pouetbox_partyheader");
//prod rows
var p = document.querySelectorAll('.prod a[href^="prod"]');
//group prod listing | fix header table (groupname/..) | bottom one as well
if(document.querySelectorAll("th[colspan='9']").length > 0) {
document.querySelectorAll("th[colspan='9']")[0].setAttribute("colspan", "10");
document.querySelectorAll("td[colspan='9']")[0].setAttribute("colspan", "10");
}
//sortable header need another TH in the beginning
var sortableRowList = document.querySelectorAll("tr.sortable");
for(var a = 0; a < sortableRowList.length; a++){
sortableRowList[a].insertBefore(document.createElement('th'), sortableRowList[a].firstElementChild);
}
function handleImg404(e){
var currentURL = e.target.getAttribute('src').split('.'),
typeIndex = TYPES.indexOf(currentURL[1]);
if((++typeIndex) < TYPES.length)
e.target.setAttribute('src', currentURL[0] + '.' + TYPES[typeIndex]);
}
for(var i = 0; i < p.length; i++){
//ignore the links on the type images
if(p[i].getElementsByTagName('img').length === 0) {
var prodURL = p[i].getAttribute("href"),
prodScreenshotURL = 'screenshots/' + prodURL.split('=')[1] + '.' + TYPES[0],
img = document.createElement('img');
td = document.createElement('td'),
link = document.createElement('a'),
prodLinkCell = isPartyPage ? p[i].parentNode : p[i].parentNode.parentNode;
td.style.cssText = "padding:0;text-align:center;background:" + IMG_BACKGROUND+";";
link.setAttribute("href", prodURL);
img.setAttribute("height", MAX_IMG_HEIGHT + 'px');
img.style.cssText = "display:block;margin:0 auto;";
img.onerror = handleImg404;
img.setAttribute("src", prodScreenshotURL);
link.appendChild(img);
td.appendChild(link);
prodLinkCell.parentNode.insertBefore(td, prodLinkCell);
}
}