2 // @name Provveditorato Studi Enna Fix
3 // @description Fix the site from the Provveditorato agli Studi di Enna
4 // @namespace http://oblomov.myopenid.com
5 // @include http://provvstudienna.it/*
6 // @include http://*.provvstudienna.it/*
7 // @author Giuseppe "Oblomov" Bilotta
11 if (typeof(unsafeWindow) == 'undefined') unsafeWindow = window;
13 String.prototype.ltrim = function() { return this.replace(/^\s+/,'') };
14 String.prototype.rtrim = function() { return this.replace(/\s+$/,'') };
15 String.prototype.trim = function() { return this.ltrim().rtrim() };
19 /* replace the non-standard startDownload() behavior with standard XMLHttpRequest */
20 var marq = unsafeWindow.document.getElementById('externalmarquee');
22 var url = marq.getAttribute('src').replace(/\\/g,'/');
23 xhr = new XMLHttpRequest();
24 xhr.open("GET", url, true);
25 xhr.onreadystatechange = function() {
26 if (xhr.readyState == 4) {
27 if (xhr.status == 200) {
28 marq.innerHTML = xhr.responseText;
30 marq.innerHTML = 'impossibile caricare le news';
37 /* Replace the unneeded Java menu applet with a standard menu */
38 var menu = unsafeWindow.document.getElementsByTagName('applet')[0];
39 if (typeof(menu) == 'object') {
40 var pnode = menu.parentNode;
41 var neib = menu.nextSibling;
43 pnode.removeChild(neib);
44 neib = menu.nextSibling;
46 var nodes = menu.getElementsByTagName('param');
48 /* The following code expects menu items to appear in sequence:
49 label1, sublabel1.1, url1.1, sublabel1.2, url1.2, label2, etc
50 (as they are on the processed site. If params are given off-sequence,
51 it will break. Beware if you port the code to other sites too */
52 for (var i = 0; i < nodes.length; ++i) {
54 var match = /^(\d+)-Label$/.exec(param.name);
56 ops[parseFloat(match[1])-1] = {label: param.value.trim(), entry: []};
59 match = /^(\d+)-Entry(\d+)$/.exec(param.name);
61 ops[parseFloat(match[1])-1].entry[parseFloat(match[2]-1)] = {label: param.value.trim()};
64 match = /^(\d+)-URL(\d+)$/.exec(param.name);
66 ops[parseFloat(match[1])-1].entry[parseFloat(match[2]-1)].url = param.value.replace(/\\/g, '/');
71 if (typeof(JSON) == 'object') {
72 alert(JSON.stringify(ops));
76 pnode.removeChild(menu);
77 menu = document.createElement('ul');
78 menu.id = 'hypermenu';
79 for (var i = 0; i < ops.length; ++i) {
80 menu.appendChild(document.createElement('li'));
81 var item = menu.lastChild;
82 item.id = ops[i].label.replace(/\./g,'').replace(/\W/g,'-').toLowerCase();
83 item.appendChild(document.createElement('p'));
84 item.lastChild.appendChild(document.createTextNode(ops[i].label));
85 item.appendChild(document.createElement('ul'));
86 item = item.lastChild;
87 for (var j = 0; j < ops[i].entry.length; ++j) {
88 item.appendChild(document.createElement('li'));
89 item.lastChild.appendChild(document.createElement('a'));
90 link = item.lastChild.lastChild;
91 link.href = ops[i].entry[j].url;
92 link.appendChild(document.createTextNode(ops[i].entry[j].label));
95 pnode.appendChild(menu);
99 /* Styling for the menu */
100 /* we could grab most of these from the params to the java applet, but I'm too lazy to write that code for now */
101 /* TODO: metal effect */
102 style = '#hypermenu { font-family: Dialog, sans-serif; font-size: 12px; list-style-type: none; text-align: left; background-color: #e2e2e2; margin:0 auto; padding:0;width: 100%}';
103 style += '#hypermenu > li { margin:0; padding:0}';
104 style += '#hypermenu > li > p { font-weight: bold; background-color: #284828; margin:0; padding: 6px 0 6px 3px; }';
105 style += '#hypermenu > li > p:hover { color: #00FF00; }';
106 style += '#hypermenu ul { color:black; font-weight:normal; list-style-type: none; margin:0; padding:0; background-color: #C0C0C0}';
107 style += '#hypermenu ul > li { padding: 3px}';
108 style += '#hypermenu ul > li:hover { color: #CC0000; font-weight: bold}';
109 style += '#hypermenu a { color:inherit; text-decoration:none }' ;
112 style += '#hypermenu > li > p { border: 1px solid gray }';
113 style += '#hypermenu > li > ul {display:none}';
114 style += '#hypermenu > li:hover > ul {display:block}';
116 stel = unsafeWindow.document.createElement('style');
117 stel.appendChild(document.createTextNode(style));
118 unsafeWindow.document.getElementsByTagName('head')[0].appendChild(stel);