Jump to content
  • entries
    4
  • comments
    2
  • views
    6448

Forum Blogs - (Grease) Monkeying with Tip.it


GrandZephyr

685 views

I've noticed that there are a fair number of bugs with the Tip.it blog's teasers / summaries.

 

In an attempt to correct some of those bugs for myself I wrote the following Greasemonkey userscript.

 

If anyone decides to use this code, leave a comment to let me know how you think it works, or if there is anything else to add.

 

Thanks.

 

 

 

 

// ==UserScript==

// @name Tip.it Blog Fixer

// @namespace Tip.it Blog Fixer

// @description Tip.it Blog Fixer

// @include http://forum.tip.it/blog*

// @include http://forum.tip.it/index.php?app=blog

// @exclude http://forum.tip.it/blog/*/entry*

// @version 1

// ==/UserScript==

 

// a function that loads jQuery and calls a callback function when jQuery has finished loading

function addJQuery(callback) {

var script = document.createElement("script");

script.setAttribute("src", "http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js");

script.addEventListener('load', function() {

var script = document.createElement("script");

script.textContent = "(" + callback.toString() + ")();";

document.body.appendChild(script);

}, false);

document.body.appendChild(script);

}

 

function main() {

 

my_jQuery = $.noConflict(true);

 

// Initialize our jQuery once the page is ready

my_jQuery(document).ready(function($)

{

 

//fix background color

$(".teaser_wrap").addClass("entry");

 

//fix image resizing

forcedWidth = Math.floor($(".teaser_wrap").width() / 2 - 12);

 

//first we remove the automated resizer info

$("div.resized_img").find("span").remove();

$(".bbc_img.resized").each(function(){

$(this).removeClass("resized");

$(this).removeAttr("handled")

.removeAttr("newheight")

.removeAttr("newwidth")

.removeAttr("origheight")

.removeAttr("shrunk")

.removeAttr("origwidth")

.removeAttr("style")

.removeAttr("height")

.removeAttr("width")

$(this).css("border","0px");

$(this).unwrap();

});

 

$(".bbc_img").each(function(){

var img = $(this).get(0);

var width = img.clientWidth;

var height = img.clientHeight;

 

if(width > forcedWidth){

var ratio = forcedWidth / width;

var newHeight = height * ratio;

$(this).width(forcedWidth);

$(this).height(newHeight);

}

});

 

 

//Fix broken BBCodes (currently just removes)

$(".entry_content").each(function(){

$(this).html(function(){

var output = $(this).html()

output = output.replace("

","");

output = output.replace("","");

output = output.replace("","");

output = output.replace("","");

output = output.replace("

","");

output = output.replace(/\*\d['"\+]*\]/g, "");

return output;

});

});

});

 

}

 

// load jQuery and execute the main function

addJQuery(main);

 

 

0 Comments


Recommended Comments

There are no comments to display.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.