By tkirby
Has 4 other scripts.
// ==UserScript==
// @name redtoo/b/
// @summary Add Redtube thumbs and links to 4chan posts. Less work, more fap.
// @description Takes most of the work out of the Redtube game. Adds thumbnails and links to the Redtube videos in the 4chan thread posts. It defaults to using the last four numbers of the 4chan post id. You can change this by appending and 'rt' param to your query string. To use the last five numbers of your 4chan post add '?rt=5' to the url in the location bar like this: http://img.4chan.org/b/res/66488689.html?rt=5
// @include http://*.4chan.org/b/res/*
// ==/UserScript==
// TODO: Add active/deactivate button instead of the 'redtube' scan
// TODO: Add redtube thumb to OP
(function() { // vim won't indent correctly without this -> )
function handle_missing_image()
{
// disable all events
this.removeEventListener('error', handle_missing_image, true);
this.removeEventListener('mouseover', handle_mouseover, true);
this.removeEventListener('mouseout', handle_mouseout, true);
// set default image
this.src = "http://tbn0.google.com/images?q=tbn:JUT4bdl4R0FCEM:http://media.codedchaos.com/images/funny/no%2520u.jpg";
return true;
}
function handle_mouseover()
{
this.removeEventListener('error', handle_missing_image, true);
// temporarily set id so the redtube scripts will animate. We can't
// leave it set because the thumbnail may appear several times in a
// thread. Redtube doesn't have the same thumb show multiple times in
// a page I guess.
this.id = this.name;
this.style.border = 'solid 2px #CC0D12';
rt_thumb_url = this.getAttribute('rt_thumb_url');
unsafeWindow.startm(this.id, rt_thumb_url, ".jpg");
}
function handle_mouseout()
{
rt_thumb_url = this.getAttribute('rt_thumb_url');
this.src = rt_thumb_url + '010.jpg'
this.style.border = 'solid 2px #A0A0A0';
unsafeWindow.endm(this.id);
this.removeAttribute('id');
}
function start_tubing() {
// dont try to run on 404'd pages
if (!document.getElementById("navtop")) {
return;
}
// no 'rt' specified in url so check for redtube
if (!get_query_param('rt')) {
var OP_blockquote =
xpath_get_first_node("/html/body/form[@name='delform']//blockquote");
// if OP doesn't contain 'redtube'
if (OP_blockquote && OP_blockquote.textContent.search(/redtube/i) < 0) {
return;
}
}
/* import redtube thumbchange script to do slideshow on hover */
var rt_script = document.createElement('script');
rt_script.src = 'http://www.redtube.com/thumbchange.js';
xpath_get_first_node('/html/head').appendChild(rt_script);
body = xpath_get_first_node('/html/body');
var num_digits = get_query_param('rt') || 4;
var replies = xpath_get("/html/body/form[@name='delform']//td[@class='reply' or @class='replyhl']");
for (var i = 0; i < replies.snapshotLength; i++) {
reply = replies.snapshotItem(i);
mid = reply.id.toString().substr(-num_digits);
rt_id = pad(mid, 7);
rt_bin = pad(parseInt(rt_id / 1000), 7);
rt_thumb_url = 'http://thumbs.redtube.com/_thumbs/'+rt_bin+'/'+rt_id+'/'+ rt_id+'_';
img = document.createElement('img');
img.src = rt_thumb_url + '010.jpg';
img.setAttribute('name', rt_id);
img.setAttribute('rt_thumb_url', rt_thumb_url);
img.setAttribute('style',
'border:solid 2px #A0A0A0; width: 160px; height: 120px;');
img.addEventListener('mouseover', handle_mouseover, true);
img.addEventListener('mouseout', handle_mouseout, true);
img.addEventListener('error', handle_missing_image, true);
img_link = document.createElement('a');
img_link.href = 'http://www.redtube.com/' +mid;
img_link.target = '_blank';
img_link.appendChild(img);
reply.appendChild(img_link);
reply.vAlign = 'top';
reply.setAttribute('style', 'width: 100%');
rt_cell = document.createElement('td');
rt_cell.name = 'redtoob_thumbnail';
rt_cell.vAlign = 'middle';
rt_cell.appendChild(img_link);
reply.parentNode.appendChild(rt_cell);
img_script = document.createElement('script');
img_script.text = 'stat["'+rt_id+'"]=0; pic["'+rt_id+'"]=[]; pics["'+rt_id+'"]=[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1];';
body.appendChild(img_script);
}
}
function pad(number,length)
{
var str = '' + number;
while (str.length < length) {
str = '0' + str;
}
return str;
}
function get_query_param(key)
{
var re = new RegExp("[?&]" + key + "=([^&$]*)", "i");
var offset = location.search.search(re);
if (offset == -1) {
return null;
}
return RegExp.$1;
}
function xpath_get(query) {
return document.evaluate(query, document, null,
XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
}
function xpath_get_first_node(query) {
return document.evaluate(query, document, null,
XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
}
window.addEventListener("load", function() { start_tubing(); }, false);
})();