473,320 Members | 2,052 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes and contribute your articles to a community of 473,320 developers and data experts.

Change bytes.com's table width using Greasemonkey

Dormilich
8,658 Expert Mod 8TB
lately, people have complained that the new layout is too narrow on most Computer/Laptop screens. Firefox users can make use of the Greasemonkey Addon to apply on-the-fly changes.

(Opera users can use Opera's UserScripts, which should work similarly)
Expand|Select|Wrap|Line Numbers
  1. // ==UserScript==
  2. // @name           widen Bytes.com
  3. // @namespace      http://bytes.com/
  4. // @description    widen bytes.com's too narrow main table
  5. // @include        http://bytes.com/*
  6. // ==/UserScript==
  7.  
  8. window.bytes_new_width = function()
  9. {
  10.     // define new size
  11.     var new_size = 1000;
  12.  
  13.     // get the main table and reset its width
  14.     var tbl = document.getElementsByTagName('table');
  15.     var l = tbl.length;
  16.     for (var i=0; i<l; i++)
  17.     {
  18.         // there is only one table with a width
  19.         // attribute of 635
  20.         if (tbl[i].getAttribute("width") == 635) 
  21.         {
  22.             tbl[i].setAttribute("width", new_size);
  23.         }
  24.     }
  25.  
  26.     // get the code blocks and widen them too
  27.     var code_box = new_size - 100 + "px";
  28.     var code = document.getElementsByClassName('codeContent');
  29.     var k = code.length;
  30.     for (var j=0; j<k; j++)
  31.     {
  32.         // set box size (enclosed in table)
  33.         code[j].style.width = code_box;
  34.     }
  35. }
  36.  
  37. window.addEventListener("load", window.bytes_new_width, false);
Mar 7 '09 #1
7 8440
Dormilich
8,658 Expert Mod 8TB
if you don't like the "Popular Articles" menu, add following code in the first for-loop:
Expand|Select|Wrap|Line Numbers
  1.         // remove Articles menu
  2.         if (tbl[i].getAttribute("class") == "maintable")
  3.         {
  4.             var row1 = tbl[i].rows[0];
  5.             // gets all <td> (even from subtable)
  6.             var cells = row1.getElementsByTagName("td");
  7.             // remove last
  8.             row1.removeChild(cells[cells.length-1]);
  9.         }
Mar 17 '09 #2
acoder
16,027 Expert Mod 8TB
Thanks, saves me having to do it myself.

You could probably avoid the for loop by accessing the table indexes directly.
Mar 19 '09 #3
Dormilich
8,658 Expert Mod 8TB
probably, though there are too many tables in the markup.
Mar 19 '09 #4
Dormilich
8,658 Expert Mod 8TB
@Dormilich
update: no need to loop over the tables.... (and doing some clean up, too)
Expand|Select|Wrap|Line Numbers
  1.         // remove Articles menu
  2.         var main = document.getElementsByClassName("maintable")[0];
  3.         if (main)
  4.         {
  5.             var row1 = main.rows[0];
  6.             // get last table cell
  7.             var cell3 = row1.cells[2];
  8.             // remove last
  9.             row1.removeChild(cell3);
  10.         }
  11.  
Mar 25 '09 #5
acoder
16,027 Expert Mod 8TB
The "maintable"-classed table is also the parent of the table with width 635, so either get the first table
Expand|Select|Wrap|Line Numbers
  1. table.getElementsByTagName("table")[0]
or via the first td (table cell) on the first row.
Mar 31 '09 #6
Dormilich
8,658 Expert Mod 8TB
after taking care of the table width, I now got annoyed by the lengthy forum descriptions in the User Control Panel…
Expand|Select|Wrap|Line Numbers
  1. // ==UserScript==
  2. // @name           bytes_overview_table
  3. // @namespace      http://bytes.com/
  4. // @include        http://bytes.com/usercp.php
  5. // @description    remove a good deal of the Forum description in the User Control Panel
  6. // ==/UserScript==
  7.  
  8. window.bytes.overview = function () 
  9. {
  10.     // get the table cells where the description is
  11.     var trs = document.getElementById("collapseobj_usercp_forums").getElementsByClassName("alt1Active");
  12.  
  13.     // got this loop termination idea from Markus
  14.     for (var i=0; trs[i]; i++)
  15.     {
  16.         // the element that actually holds the text
  17.         var div = trs[i].getElementsByClassName("smallfont")[0];
  18.  
  19.         // skip if there is no text inside
  20.         if (div.firstChild.nodeType != 3)
  21.             continue;
  22.  
  23.         // cut the text at the first hyphen
  24.         var text = div.textContent;
  25.         div.textContent = text.substring(0, text.indexOf("-"));
  26.     }
  27. };
  28.  
  29. window.addEventListener("load", window.bytes.overview, false);
Aug 14 '09 #7
Atli
5,058 Expert 4TB
Hey.

Your first script. Seems KUB changed the layout or something. Your script looks for a width of "635", but the table currently has "625px".
Was scratching my head there for like 10 minutes trying to figure out why it wouldn't work :)
Jan 6 '10 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Csaba2000 | last post by:
How do I detect when the font size has been changed (especially by user action: either Ctrl+Scroll wheel or View/Text Size)? This is just for use on IE 5.5+, but it would be great if there was a...
11
by: SarahMarsden | last post by:
I'm new to Dreamweaver (using MX 2004). I have a 2 row 3 column table. I have set each column to 200 pixels. The second row I have merged into one cell. When I enter text (or anything else) into...
2
by: James Dean | last post by:
I create a bitmap like this. The width and height are got from the compressed file i am reading. The width and height are in pixels.....1bpp bitmap = new...
2
by: Mark | last post by:
IE creates an object of every ID'd HTML tag (so it appears), and each object sets a property for any parameter I set in the tag. For example, my HTML might be: <td id='cell1'...
7
by: Don NJ | last post by:
First my site name is Sinfullblisslingerie.com. I'm starting this little business to try and make some money on the side. My kids will be going to college in a few years... Anyway, in the past...
2
by: Alexander Paul | last post by:
Hi! I'm a newbie to JavaScript and Greasemonkey and just started learning with 'Dive Into Greasemonkey'. I looked for an example on the web, but unfortunately I'm still missing something... I...
3
by: synergy_711 | last post by:
I feel like this should be fairly easy but I have been struggling with this for sometime. I have not been able to find someone who's had the same problem as mine yet. ...
1
by: rockdale | last post by:
Hi, all I am change my webpage to using div and css for my layout, it was using table before and I want to get rid of it. Basically it draws a box around my content using background pictures,...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.