-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPokec_Preview.user.js
234 lines (208 loc) · 11.7 KB
/
Pokec_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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
// ==UserScript==
// @name Pokec Preview
// @namespace marki
// @description Preview profile images on Pokec/AZet
// @include http://*.azet.sk/*
// @include http://*.aktuality.sk/*
// @include http://*.zive.sk/*
// @icon http://www.azet.sk/favicon.ico
// @grant GM_setValue
// @grant GM_getValue
// @grant GM_xmlhttpRequest
// @version 1.2
// ==/UserScript==
// Code based on FFixer http://userscripts.org/scripts/show/8861
// v0.2 - preview also for photo albums, also profile pic in comments
// v0.3 - 2011-03-09 - fixed images URL due to change on azet, change in photoalbum big picture filename
// v0.4 - 2011-06-14 - show popup on left if thumbnail is on right
// v0.5 - 2012-01-23 - added support for new image urls, added icon, added search URL aktuality.sk
// v0.6 - 2012-04-05 - again new URL (m1.aimg.sk instead of m.aimg.sk)
// v1.1 - 2015-04-17 - all profile pics are now protected; need to fetch user profile to get URL of full size pic
// v1.2 - 2015-05-03 - on profile page, show date of last visit
// 2015-05-09 - show date of last visit also on list of users page
// *** WARNING: ***
// This version won't work without changing URL http://XXXX/azet_prof_img.php to your copy of PHP script
(function() {
var showPopupPicTimeout;
var hidePopupPicTimeout;
//
// Add styles used by script
//
addStyle(
'.fbfPopup { padding:10px; background:#f6f6f6; border:3px double #666666; -moz-border-radius:5px; -webkit-border-radius:5px; -khtml-border-radius:5px; border-radius:5px; }'+
'#qq-popup-div { display:none; background:white; border:1px solid #333; position:fixed !important; top:3px !important; padding:4px; min-width:130px; z-index:99999 !important; -moz-border-radius:3px; -webkit-border-radius:3px; -khtml-border-radius:3px; border-radius:3px; }'+
'.qq-popup-div { right:3px !important; left:auto !important; -moz-box-shadow:-5px 5px 5px rgba(0,0,0,0.6); -webkit-box-shadow:-5px 5px 5px rgba(0,0,0,0.6); -khtml-box-shadow:-5px 5px 5px rgba(0,0,0,0.6); box-shadow:-5px 5px 5px rgba(0,0,0,0.6); }'+
'.qq-popup-div-left { left: 3px !important; right:auto !important; -moz-box-shadow:5px 5px 5px rgba(0,0,0,0.6); -webkit-box-shadow:5px 5px 5px rgba(0,0,0,0.6); -khtml-box-shadow:5px 5px 5px rgba(0,0,0,0.6); box-shadow:5px 5px 5px rgba(0,0,0,0.6); }'+
'.qq-popup-div-right { right:3px !important; left:auto !important; -moz-box-shadow:-5px 5px 5px rgba(0,0,0,0.6); -webkit-box-shadow:-5px 5px 5px rgba(0,0,0,0.6); -khtml-box-shadow:-5px 5px 5px rgba(0,0,0,0.6); box-shadow:-5px 5px 5px rgba(0,0,0,0.6); }'+
'#qq-pic-close { display:none; position:absolute; top:4px; right:10px; color:#ff9999; cursor:pointer; font-weight:bold; font-size:14px; }'+
'#qq-popup-div:hover #ff-popup-pic-close { display:block; }'+
'#qq-pic-close:hover { color:#aa6666; }'+
'#ff-popup-pic-image { text-align:center; }'+
'#ff-popup-pic-image img { color:#999999; display:block; }'+
'#visitDiv { text-align: center; }'
);
// profile page visits
function insertAfter(newNode, referenceNode) { referenceNode.parentNode.insertBefore( newNode, referenceNode.nextSibling );}
var last, Nick, text;
if (/http:\/\/pokec\.azet\.sk\/[^/]+\/?\?i9/.test(location)) {
Nick = location.toString().replace(/\/?\?.*$/, "");
Nick = Nick.replace(/http:\/\/pokec\.azet\.sk\//, "");
console.log("Profile page for "+Nick);
last = GM_getValue("lastProf-"+Nick,"");
if (!last) text="<b>Profil este nebol pozrety</b>"; else text="Posledna navsteva: <b>"+last+"</b>";
var metaViz = document.evaluate("//div[@class='metaVizitka']", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
var visitDiv = document.createElement('div');
visitDiv.id = 'visitDiv';
visitDiv.innerHTML = '<div>'+text+'</div>';
insertAfter(visitDiv, metaViz);
last = new Date();
text = last.getDate() +"."+ (last.getMonth()+1) +"."+ last.getFullYear();
GM_setValue("lastProf-"+Nick, text);
}
// list of users (add profile visits)
var allLinks, thisLink, i;
if (/http:\/\/pokec\.azet\.sk\/sluzby\/pouzivatelia\//.test(location)) {
allLinks = document.evaluate('//div[@class="userContainer"]//h3//a', document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
for (var i = 0; i < allLinks.snapshotLength; i++) {
thisLink = allLinks.snapshotItem(i);
Nick = thisLink.href.toString().replace(/\/?\?.*$/, "");
Nick = Nick.replace(/http:\/\/pokec\.azet\.sk\//, "");
//console.log("Profile link found for "+Nick);
last = GM_getValue("lastProf-"+Nick,"");
if (last) {
visitDiv = document.createElement('div');
visitDiv.innerHTML = '<div style="padding-left:10px;font-weight:bold;font-size:80%;color:#3878C0">'+last+'</div>';
insertAfter(visitDiv, thisLink);
}
}
}
//
// Add div for showing big profile pics
//
var popupPicDiv = document.createElement('div');
popupPicDiv.id = 'qq-popup-div';
popupPicDiv.className = 'fbfPopup qq-popup-div';
popupPicDiv.innerHTML = '<div id="qq-pic-close" title="Close">x</div><div id="ff-popup-pic-image"><span></span></div>';
try {
document.body.insertBefore(popupPicDiv, document.body.lastChild.nextSibling);
document.getElementById('qq-pic-close').addEventListener('click', function() { document.getElementById('qq-popup-div').style.display='none'; }, false);
} catch(x) {
var fbppdivAdder = setInterval(function() {
try {
document.body.insertBefore(popupPicDiv, document.body.lastChild.nextSibling);
document.getElementById('qq-pic-close').addEventListener('click', function() { document.getElementById('qq-popup-div').style.display='none'; }, false);
if ($('#qq-popup-div')) { clearInterval(fbppdivAdder); }
} catch(x) {}
}, 250);
}
// Listeners are added by the code for showing the popups
//
// Listen for image mouseovers/mouseouts to show/hide popups
//
// http://213.215.107.127/fotky/1272/79/n_12727989.jpg?v=4
// http://213.215.107.125/fotky/1518/42/n_15184211.jpg?v=5 -- thumb
// http://213.215.107.125/fotky/1171/72/n_11717223.jpg?v=5 -- profil
// http://213.215.107.127/fotky/ 622/47/s_6224758 .jpg?v=2 -- zoznam priatelov
// http://213.215.107.127/fotky/ 622/47/m_6224758 .jpg?v=2 -- komentare v profile
// http://213.215.107.125/fotky/ 542/71/ 5427111 .jpg?v=3 -- big
// http://213.215.107.78/fotoalbumy/356/357/nf_356357110_be87b7135c37a25cb494877aa5bd4480.jpg - thumb
// http://213.215.107.78/fotoalbumy/356/357/ f_356357110_be87b7135c37a25cb494877aa5bd4480.jpg - big photo
// http://213.215.107.78/fotoalbumy/356/357/mf_356357110_be87b7135c37a25cb494877aa5bd4480.jpg - 2011-03-09 big photo
// http://213.215.107.77/fotoalbumy/356/357/ f_356357907_fe56924742d842826c03c551811c0dbc.jpg
// found 2012-01-23
// http://m.aimg.sk/profil/m_15702354.jpg?v=5
// http://m.aimg.sk/profil/s_15702354.jpg?v=5
// http://m.aimg.sk/profil/ 15702354.jpg?v=5
picRegex = /http:\/\/(u\.aimg\.sk|213\.215\.107\.[0-9]+)\/fotky\/[0-9]+\/[0-9]{2}\/[nsm]_([0-9]+\.jpg)/;
albRegex = /http:\/\/(u\.aimg\.sk|213\.215\.107\.[0-9]+)\/fotoalbumy\/[0-9]+\/[0-9]+\/nf_[0-9]+_[0-9a-f]+\.jpg/;
newRegex = /http:\/\/m[0-9]*\.aimg\.sk\/profil\/[nsm]_([0-9]+\.jpg)/;
proRegex = /http:\/\/t[0-9]*\.aimg\.sk\/pokec\/fotoalbumy\/[0-9]+\/[0-9a-f_]+\.jpg/;
function showPopupPic(e) {
try {
var t = e.target;
var oldSrc;
var newSrc;
if (t.tagName == 'IMG' && picRegex.test(t.src)) { newSrc = t.src.replace(/[nsm]_/, ""); }
if (t.tagName == 'IMG' && albRegex.test(t.src)) { newSrc = t.src.replace(/nf_/ , "mf_"); }
if (t.tagName == 'IMG' && newRegex.test(t.src)) { newSrc = t.src.replace(/[nsm]_/, ""); }
if (t.tagName == 'IMG' && proRegex.test(t.src)) { newSrc = GM_getValue(t.src, ""); if (newSrc) console.log("From cache: "+newSrc); } // fetch URL from local storage
if (oldSrc || newSrc) {
clearTimeout(hidePopupPicTimeout);
t.removeEventListener('mouseout', hidePopupPic, false);
t.addEventListener('mouseout', hidePopupPic, false);
showPopupPicTimeout = setTimeout(function(){
$('#ff-popup-pic-image').innerHTML = '<img src="' + newSrc + '" alt="PokecPreview - Nacitavam..." style="max-height:' + (window.innerHeight-35) + 'px;"/>';
$('#qq-popup-div').style.display = 'block';
$('#qq-popup-div').className = 'fbfPopup qq-popup-div-' + (e.pageX>document.body.clientWidth/2 ? 'left' : 'right');
}, 250);
}
/* 2015-04-17: all profile photos are now fotoalbum protected images; 1st fetch users profile */
// on List of users, there is parent DIV, then A
if (!newSrc && t.tagName == 'IMG' && proRegex.test(t.src) && ((t.parentNode.tagName=='A') || (t.parentNode.parentNode.tagName=='A'))) {
var nick;
if (t.parentNode.tagName=='A') nick = t.parentNode.href; else nick = t.parentNode.parentNode.href;
if (!/http:\/\/pokec\.azet\.sk\/[^/]+\/?\?i9/.test(nick)) { console.log("No profile: "+nick); return; }
nick = nick.replace(/\/\?.*$/, "");
nick = nick.replace(/http:\/\/pokec\.azet\.sk\//, "");
clearTimeout(hidePopupPicTimeout);
t.removeEventListener('mouseout', hidePopupPic, false);
t.addEventListener('mouseout', hidePopupPic, false);
showPopupPicTimeout = setTimeout(function(){
newSrc = "";
$('#ff-popup-pic-image').innerHTML = '<img src="' + newSrc + '" alt="PokecPreview - Nacitavam..." style="max-height:' + (window.innerHeight-35) + 'px;"/>';
$('#qq-popup-div').style.display = 'block';
$('#qq-popup-div').className = 'fbfPopup qq-popup-div-' + (e.pageX>document.body.clientWidth/2 ? 'left' : 'right');
GM_xmlhttpRequest({ method: "GET", url: "http://XXXX/azet_prof_img.php?nick="+nick, timeout: 5000, onload: function(resp) {
var r = resp.responseText;
$('#ff-popup-pic-image').innerHTML = '<img src="' +r+ '" alt="Foto '+nick+'" style="max-height:'+(window.innerHeight-35)+'px;"/>';
//console.log("Image big: "+r);
if (/jpg/.test(r)) GM_setValue(t.src, r);
//var match;
//if (match = /property="og:image" content="(.*)"/.exec(resp.responseText)) { $('#ff-popup-pic-image').innerHTML = '<img src="' + match[1] + '" style="max-height:'+(window.innerHeight-35)+'px;"/>'; console.log("Image big: "+match[1]); }
} });
}, 250);
}
} catch(x) { logError('Popup Pic', x); }
}
$('#qq-popup-div').addEventListener('mouseover', function(e) { clearTimeout(hidePopupPicTimeout); }, false);
$('#qq-popup-div').addEventListener('mouseout', function(e) {
var r = e.relatedTarget;
if (!e.shiftKey && !e.ctrlKey && !e.altKey) {
while (r.parentNode && r.id!='qq-popup-div') { r = r.parentNode; }
if (r.id!='qq-popup-div') { document.getElementById('qq-popup-div').style.display = 'none'; }
}
}, false);
window.addEventListener('mouseover', function(e) {
if (!e.shiftKey && !e.ctrlKey && !e.altKey) { showPopupPic(e); }
}, false);
function hidePopupPic(e) {
clearTimeout(showPopupPicTimeout);
if (!e.shiftKey && !e.ctrlKey && !e.altKey) {
hidePopupPicTimeout = setTimeout(function() { document.getElementById('qq-popup-div').style.display = 'none'; }, 30);
}
}
function logError(category, x) {
msg = "PokecPreview Error (" + category + ") - " + x.name + ' - ' + x.message + ' in file <' + x.fileName + '> on line ' + x.lineNumber;
console.log(msg);
}
function $(q, root, single) {
root = root || document;
if (q[0]=='#') { return root.getElementById(q.substr(1)); }
else if (q[0]=='/' || (q[0]=='.' && q[1]=='/')) {
if (single) { return document.evaluate(q, root, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue; }
return document.evaluate(q, root, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
}
else if (q[0]=='.') { return root.getElementsByClassName(q.substr(1)); }
return root.getElementsByTagName(q);
}
function addStyle(css) {
if (typeof GM_addStyle !== 'undefined') { return GM_addStyle(css); }
else if (heads = document.getElementsByTagName('head')) {
var style = document.createElement('style');
try { style.innerHTML = css; }
catch(x) { style.innerText = css; }
style.type = 'text/css';
heads[0].appendChild(style);
}
}
}) ();