/b/ackwash
By tkirby
—
Last update Jul 1, 2008
—
Installed
2,460 times.
// ==UserScript==
// @name /b/ackwash
// @description Add tooltips to 4chan quotes (>>).
// @include http://*.4chan.org/*/res/*.html*
// ==/UserScript==
const TIP_X_OFFSET = 45, TIP_Y_OFFSET = 120;
var d = document;
var op = window.location.pathname.match(/.*[\/\\]([^\/\\]+)\.\w+$/)[1];
if (!d.getElementById('navtop')) return;
tr = d.createElement('tr');
tr.id ='bw_cont';
tb = d.createElement('table');
div = d.createElement('div');
div.id ='bw_tt';
div.setAttribute('style', 'visibility: hidden; position:absolute; border:1px solid #AAA; background-color:#FFF');
tb.appendChild(tr);
div.appendChild(tb)
d.body.appendChild(div);
qts = d.evaluate("//a[@class='quotelink']", d, null,
XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
for (i = 0; i < qts.snapshotLength; i++) {
qt = qts.snapshotItem(i);
id = qt.hash.split('#')[1];
if (id == op) {
qt.innerHTML += ' (OP)';
} else if (!d.getElementById(id)) {
qt.innerHTML += ' (Duckroll?)';
continue;
}
qt.setAttribute('onmouseover', 'show(this, event)');
qt.setAttribute('onmouseout', 'hide()');
qt.setAttribute('onmousedown', 'hide()');
qt.setAttribute('onmousemove', 'track(event)');
}
unsafeWindow.hide = function() {
d.getElementById('bw_cont').innerHTML = '';
d.getElementById('bw_tt').style.visibility = 'hidden';
}
unsafeWindow.show = function(me, e) {
var td, id = me.hash.split('#')[1];
if (id == op) {
td = d.createElement('td');
td.innerHTML = d.getElementsByName('delform')[0].innerHTML.split(
'</blockquote>')[0].replace(/<input.*?>/i, '') + '</blockquote>';
} else {
td = d.getElementById(id).cloneNode(1);
td.className = 'replyhl';
td.removeChild(td.getElementsByTagName('input')[0]);
}
td.style.padding = '10px';
d.getElementById('bw_cont').appendChild(td);
unsafeWindow.track(e);
d.getElementById('bw_tt').style.visibility = "visible";
}
unsafeWindow.track = function(e) {
tip = d.getElementById('bw_tt');
tip_height = parseInt(
d.defaultView.getComputedStyle(tip, '').getPropertyValue("height"));
cursor_rel_y = e.pageY - window.scrollY;
tip_abs_bottom = e.pageY - TIP_Y_OFFSET + tip_height;
vp_height = window.innerHeight;
vp_bottom = window.scrollY + vp_height;
if (cursor_rel_y < TIP_Y_OFFSET || tip_height > vp_height) {
tip_y_offset = e.pageY - cursor_rel_y;
} else if (tip_abs_bottom > vp_bottom) {
tip_y_offset = e.pageY - TIP_Y_OFFSET -(tip_abs_bottom - vp_bottom);
} else {
tip_y_offset = e.pageY - TIP_Y_OFFSET;
}
tip.style.top = tip_y_offset + 'px';
tip.style.left = e.pageX + TIP_X_OFFSET + 'px';
}