Completely replace a script via surrogate
Posted: Wed Jun 30, 2010 1:57 pm
Hi all, I'm running Firefox 3.6.6 and NoScript 1.9.9.98rc3. I don't know much about JS, so I hope I can explain clearly.
The page I'm trying to modify is this, https://idp.cca.unipd.it/shibboleth-idp ... pd.it%2Fsp
The JS code is located in the head of the source code and contains three functions:
#1 writes a string in the username field;
#2 sends login data;
#3 shows and hides parts of the page according to JS being enabled or not. (at least that's what I've understood)
There's an extra final part that (as far as I understand) executes function #1 on page completion after 50 ms.
Fact is that filling username field with an example string by JS interferes with Firefox password manager, so I tried to rewrite all the JS block according to my needs, i.e. stripping out function #1, its calling by the final part and then modify function #3 so that it selects the other radiobox (because I don't need the default one selected but the other one).
Here's the code, tested (in Opera, live modifying the source code and then trying to login) and working:
Now the problem is that I don't know how to make a surrogate script out of this code. I found (reading here) that in about:config I should create a two new values:
noscript.surrogate.test.sources > @https://idp.cca.unipd.it/shibboleth-idp/SSO* (is this right?)
noscript.surrogate.test.replacement > [the whole code above] (is this right too?)
Basically, I want to replace all the original JS in the page with my JS. Fact is that I tried before and it didn't work. I selected "Enable https://idp.cca.unipd.it" from NoScript menu but the page loaded as usual and not as I expected.
Can someone help me?
The page I'm trying to modify is this, https://idp.cca.unipd.it/shibboleth-idp ... pd.it%2Fsp
The JS code is located in the head of the source code and contains three functions:
#1 writes a string in the username field;
#2 sends login data;
#3 shows and hides parts of the page according to JS being enabled or not. (at least that's what I've understood)
There's an extra final part that (as far as I understand) executes function #1 on page completion after 50 ms.
Code: Select all
function initOverLabels () {
if (!document.getElementById) return;
var user = document.getElementById('j_username_js');
user.className = 'overlabel';
user.value = 'mario.rossi';
user.onfocus = function(){
this.className = 'inputsearch';
this.value = '';
};
};
function login_via_js(){
var userjs = document.getElementById('j_username_js');
var user = document.getElementById('j_username');
var radio1 = document.getElementById('radio1');
var radio2 = document.getElementById('radio2');
var jpassword = document.getElementById('j_password');
var formlogin = document.getElementById('user-login-form');
var radioselected = "";
if ( radio1.checked == true && radio2.checked == false ){
radioselected = radio1.value;
}else{
radioselected = radio2.value;
}
user.value = userjs.value + radioselected;
return true;
};
function enable_js(){
var old_login = document.getElementById('div_visible_before_js');
var new_login = document.getElementById('div_hidden_before_js');
var old_button = document.getElementById('Login');
var new_button = document.getElementById('login_button_js');
old_login.style.visibility = 'hidden';
old_login.style.display = 'none';
new_login.style.visibility = 'visible';
new_login.style.display = 'inline';
old_button.style.visibility = 'hidden';
old_button.style.display = 'none';
new_button.style.visibility = 'visible';
new_button.style.display = 'inline';
};
window.onload = function(){
enable_js();
setTimeout(initOverLabels, 50);
};
Here's the code, tested (in Opera, live modifying the source code and then trying to login) and working:
Code: Select all
function login_via_js(){
var userjs = document.getElementById('j_username_js');
var user = document.getElementById('j_username');
var radio1 = document.getElementById('radio1');
var radio2 = document.getElementById('radio2');
var jpassword = document.getElementById('j_password');
var formlogin = document.getElementById('user-login-form');
var radioselected = "";
if ( radio1.checked == true && radio2.checked == false ){
radioselected = radio1.value;
}else{
radioselected = radio2.value;
}
user.value = userjs.value + radioselected;
return true;
};
function enable_js(){
var old_login = document.getElementById('div_visible_before_js');
var new_login = document.getElementById('div_hidden_before_js');
var old_button = document.getElementById('Login');
var new_button = document.getElementById('login_button_js');
var radio_button_2 = document.getElementById('radio2');
old_login.style.visibility = 'hidden';
old_login.style.display = 'none';
new_login.style.visibility = 'visible';
new_login.style.display = 'inline';
old_button.style.visibility = 'hidden';
old_button.style.display = 'none';
new_button.style.visibility = 'visible';
new_button.style.display = 'inline';
radio_button_2.checked = 'checked';
};
window.onload = function(){
enable_js();
};
noscript.surrogate.test.sources > @https://idp.cca.unipd.it/shibboleth-idp/SSO* (is this right?)
noscript.surrogate.test.replacement > [the whole code above] (is this right too?)
Basically, I want to replace all the original JS in the page with my JS. Fact is that I tried before and it didn't work. I selected "Enable https://idp.cca.unipd.it" from NoScript menu but the page loaded as usual and not as I expected.
Can someone help me?