![]() ![]() |
hi guys... i have a litte question.. since 3 days i try to write a userscript for greasemonkey with no result :( first for better understanding
i want to disable an existing input-field with the name "prio" the code looks like this: http://jsfiddle.net/gv3XF/5/
in firefox 2.0.0.11 i recieve the error Error: document.querySelector is not a function
in firefox 10 the same code works only on jsfiddle but not on localhost and i recieve the error Error: oldInput is null
the code looks this: // ==UserScript==
var oldInput = document.querySelector ("input[name=prio]");
any ideas what here is the problem?
thanks best regards
|
![]() ![]() |
Reason for error in FF 2.x:
Reason for error in FF 10:
Try this instead for FF10+:
var oldInput = document.querySelector('input[name="prio"]');
if (oldInput) {
// Only set the attribute if it actually found the element.
oldInput.setAttribute('disabled', 'disabled');
}
or this for FF2.x: var inputs = document.getElementsByTagName('input');
for (var i = 0; i < inputs.length; i++) {
var oldInput = inputs[i];
if (oldInput.getAttribute('name') === 'prio') {
oldInput.setAttribute('disabled', 'disabled');
break;
}
}
I seriously recommend that you upgrade your Firefox to the latest version and your Greasemonkey to the latest as well. (FFv15.0 / GMv1.0 as of today) Edit: Fixed typo in code. |
![]() ![]() |
// create Attribute "disabled and set =disabled;
var disabled = document.createAttribute("disabled");
disabled.nodeValue = "disabled";
// find first element with name prio
var inp= document.getElementsByName("prio")[0];
// set Attribute to it
inp.setAttributeNode(disabled);
really that does not work on FF 1.0 ? http://jsfiddle.net/Q8MER/ |
![]() ![]() |
hi Cletus.. i need only the code for FF2.x i know that we have to update.. but it is not possible! :( the softwarecompany build the system for this browser!
so i need only a code for FF2.x :D your code says: syntax error on line 8
thanks for the quick response ;) |
![]() ![]() |
sems foreach should be only a simple "for" |
![]() ![]() |
sorry for posting again.... can't edit the post.. hi Comswitch...
inp has no propertyies on line 14
|
![]() ![]() |
Check that the input can found on your site.
window.addEventListener("load", function(e) {
startmydisablefunction();
},false);
Is the input field in HTML or is it created on the fly by a javascript, your softwareprodukt? Then you should delay your script (500-1000ms) after site loading is finished. |
![]() ![]() |
the code @ jsfiddle was just a small code
#tr valign="top"# #td "="" align="left"#Prio: #/td# #td align="left"##input maxlength="10" onfocus="setColoredField(this)" name="prio" accesskey="p" value="270.0" size="7" type="text"##/td# #/tr# have to edit the code.. replaced < and > with # because code wasn't visible i don't know what you mean with "But you first start your script since the main site is finised with loading?" my english is not the best :D
edit: the input field is normaly generated like the sourcecode i wrot above.. the problem is that i may not edit the sourcecode (license)
|
![]() ![]() |
I have understood you can get it working, but you get an error.
|
![]() ![]() |
bernte wrote:Bah... that should be a for not foreach. Too many languages in my head at once. I guess that's what I get for not testing it... :P I've edited the code above. Try it again.
ComSwitch wrote:As this is in a userscript, you don't need to add a listener for window.load (GM runs scripts at DOMContentLoaded by default, which is faster than window.load.)
|
![]() ![]() |
@ComSwitch i think your script is fine... i maybe found the error.. i have the test-site with the priobox in an tab.. and got an tab with this thread.. i think the error comes when i change the tabs because my rule says // @include * which means search on all sites right? maybe i can that edit by set the ip for the * @ Cletus your code works fine too!!!! :D thanks for helping! |
![]() ![]() |
hi guys.. first i wanna say thank you again! both codes work perfect!
first take a look at this: http://jsfiddle.net/gv3XF/8/ is it possible to modify the code?
is it possible to do that in javascript with the code above for FF2.x? example:
else
best regards
|
![]() ![]() |
Here you go, http://jsfiddle.net/gv3XF/9/
// List of users.
var users = [
'John',
'Luke',
'Jeff',
'Max',
'Andy'
];
// true = accepts only "John", false = accepts "John" or "john".
var caseSensitive = true;
// Creates the RegExp.
var reg = new RegExp('\(User: (' + users.join('|') + ')\)', ((caseSensitive) ? '' : 'i' ));
// Gets footer text.
var userStr = document.getElementById('footer').lastChild.textContent;
// If username was NOT in the list, disable priority input.
if (!reg.test(userStr)) {
// Gets all inputs.
var inputs = document.getElementsByTagName('input');
// Loops through inputs.
for (var i = 0; i < inputs.length; i++) {
var oldInput = inputs[i];
if (oldInput.getAttribute('name') === 'prio') {
// Input found, disable it.
oldInput.setAttribute('disabled', 'disabled');
break;
}
}
}
Just add the users to the list. Feel free to change the |
![]() ![]() |
hi Cletus... your code looks great!
sorry that was my fault :( i replaced the footer with the original code.. i have only a class="user" updated version: http://jsfiddle.net/gv3XF/10/ edit: and getElementsByClassName doesn't work in FF2.x ... damn :( |
![]() ![]() |
a bit of topic: you want do security by GM Script, but what is the user delete or edit your script? why not this way: link deleted edit: jsfiddle link deleted |
![]() ![]() |
@ComSwitch
with your code i recieve the error: document.getElementById("footer") has no properties Line: 16 i have updated my version (http://jsfiddle.net/gv3XF/10/). i don't have the id "footer" anymore. it was my fault! sorry for that :( |
![]() ![]() |
What do I have to do, that the user can not edit the user.js file, and he can not deaktivate GM.
//I fogott to update jsfidle.
var str="";
var userStr="";
var elm=document.getElementsByTagName("td");
for (var i = 0; i < elm.length; i++) {
str+="i="+i+" ";
if(elm[i].getAttribute("class")=="user"){
str+="Found:"+elm[i].innerHTML;
userStr= elm[i].lastChild.textContent;
}
str+="
I expect that you not only copy code,you should understood and edit by your own.
|
![]() ![]() |
you need 2 to do some changes.. its very easy..
sorry ComSwitch..
and your code i don't understand :D i see what you did but can't finish it :( |
![]() ![]() |
Pls describe it in a short way. I can deaktivate my monkey and I can edit the monkey script, I can deaktivate a script if I have more then one which should work on a page.
|
![]() ![]() |
ok.. here we go! 1. Press right-mouse on greasemonkey logo and click customize (right side of google search window)
4. install Menu Editor for Firefox (https://addons.mozilla.org/en-US/firefox/addon/...)
9. install Pulblic Fox for Firefox (https://addons.mozilla.org/en-US/firefox/addon/...)
15. Have FUN :D if you want to edit greasemonkey scripts you can do that over Tools -> Add-ons -> User Scripts
hope you like it |
![]() ![]() |
the only thing i see at ff10.x @http://jsfiddle.net/ppGe8/2/ in the preview box is i=0 Found: Logout (User: John) i=1 i=2 (User: John) the inputs are gone :/ when i try it in ff2.x the browser crashes |
![]() ![]() |
Thank you, sounds complicated, but seems you understood what you do. you wrote You asked to finde the td tag with class="user", the example show how you could get your information. |
![]() ![]() |
Here ya go:
// List of users.
var users = [
'John',
'Luke',
'Jeff',
'Max',
'Andy'
];
// true = accepts only "John", false = accepts "John" or "john".
var caseSensitive = true;
// Creates the RegExp.
var reg = new RegExp('^Logout (' + users.join('|') + ')$', ((caseSensitive) ? '' : 'i' ));
// Gets all links and loops through them.
var links = document.getElementsByTagName('a');
for (var i = 0; i < links.length; i++) {
if (links[i].hasAttribute('title')) {
var title = links[i].getAttribute('title');
// Check if link is the logout link.
if (title.indexOf('Logout') < 0) {
// Wrong link, try the next one.
continue;
}
// Check if username in list, if so, exit.
if (reg.test(title)) {
break;
}
// Username not in list, disable priority input.
else {
// Gets all inputs and loops through them.
var inputs = document.getElementsByTagName('input');
for (var j = 0; j < inputs.length; j++) {
var oldInput = inputs[j];
if (oldInput.getAttribute('name') === 'prio') {
// Input found, disable it.
oldInput.setAttribute('disabled', 'disabled');
break;
}
}
}
}
}
I am just looping through the links looking for a title that contains "Logout USER", and then acting on that. |
![]() ![]() |
yeahhh cletus that works!
|
![]() ![]() |
No problem! Feel free to PM me if you need any help. |


