G said:
Hi, I am trying to modify some code in a toolbar I have for generating
random 'spam' entries on my forum.
[...]
function Tools_SpamSeries() {
var seed = _randomSeed();
var qoute = _getQoute();
for(var i=0; i<50; i++) {
_commentCount++;
//_postComment(qoute + ":" + seed + " #" + (i
+1));
_postComment(_commentCount);
}
//alert("Spamming Complete");
As you can tell it currently uses numbers up to 50 but I never
actually get 50 output 'comments', it seems to generate the numbers
then output them randomly and leave a few out.
You do not seem to have initialized _commentCount to begin with, so the
result of _commentCount++ is unknown (may be NaN). The rest of the relevant
code you have either commented out or omitted, so there is no telling what
happens.
That said, if the first _postComment() call was not commented out, then
there might as well be the source of your problem as you use the value of
see, which might be a random number, in the argument. Then again, there is
no telling what _randomSeed() returns as that, too, is not a built-in.
BTW, shouldn't it be "quote" instead?
PointedEars
--
Prototype.js was written by people who don't know javascript for people
who don't know javascript. People who don't know javascript are not
the best source of advice on designing systems that use javascript.
-- Richard Cornford, cljs, <
[email protected]>
Hi Thomas, thanks for your reply. I think there is a lot of spurious
code involved that I really don't need (or honestly understand), here
is the full script. I guess it must be the '_randomseed' variable that
I need to tinker with!? I am a complete n00b at this... any help is
greatly appreciated, I just have very little clue where to start with
this.
I assume it's a matter of changing it from a random generated number
within a range to a variable(?) that starts at 1 and increments up to
the 'i<??' where ?? is the last number I want to post to (in this case
50).
This script is called by a button click on the toolbar and
automatically then outputs about 30 comments (numbers) and not the 50
I desire and in no particular order. This script is more complex than
I require, it was given to me by a friend;
var _diggs;+
var _diggCursor;
var _doNext;
var _thumbsGiven;
var _pagesThumbed;
var _commentCount=0;
function domyajax(div, url, vars, isThumb){
var connector = '?';
if(url.indexOf('?') != -1) connector = '&';
url = url + connector + 'time='+new Date() ;
var request = new XMLHttpRequest();
request.open("post", url, true);
request.setRequestHeader("Content-Type","application/x-
javascript;");
request.onreadystatechange = function() {
if (request.readyState == 4 && request.status == 200) {
if (request.responseText) {
var box = window._content.document.getElementById(div);
box.innerHTML = request.responseText;
if(isThumb) {
if(!(_contains(request.responseText,"You already voted"))) {
setTimeout("_thumbCurrentDigg()",100);
}
} else {
//alert(url);
setTimeout("_doPage()",0);
}
}
}
};
request.send(vars);
}
function Tools_Redirect() {
_LoadUrl("
http://www.xxxxxxxxx.com/");
}
function _thumbCurrentDigg() {
_diggCursor++;
if(_diggCursor < _diggs.length) {
if(_contains(_diggs[_diggCursor].getAttribute("onclick"), "http://
xxxxxxxxx.com/thumb.php")
|| _contains(_diggs[_diggCursor].getAttribute("onclick"), "http://
xxxxxxxxx.com/digg.php") ) {
var foo = _diggs[_diggCursor];
if(foo!=null) {
var sub = foo.getAttribute("onclick");
var peices = sub.split("'");
_thumbsGiven++;
//if(_thumbsGiven < 10) {
domyajax(peices[1],peices[3],'',true);
//}
}
}
else {
_thumbCurrentDigg();
}
}
else {
if(_doNext) {
//alert("next");
var arrAs = window._content.document.getElementsByTagName('a');
for(var i=0; i < arrAs.length; i++) {
if(_contains(arrAs
.getAttribute("onclick"), "http://
xxxxxxxxx.com/renderComments.php")) {
//alert(arrAs.getAttribute("class"));
if(_contains(arrAs.getAttribute("class"),
"clickBoxSNoBorder")) {
if(!_contains(arrAs.getAttribute("onclick"), "offset=0")) {
var sub = arrAs.getAttribute("onclick");
var peices = sub.split("'");
//if(_pagesThumbed<3) {
domyajax(peices[1],peices[3],"",false);
//}
break;
}
}
}
}
}
}
}
function _doPage() {
_diggCursor = -1;
_diggs = window._content.document.getElementsByTagName('div');
_thumbsGiven=0;
_pagesThumbed++;
_thumbCurrentDigg();
}
function _startThumbing(next) {
_doNext = next;
_pagesThumbed=-1;
_doPage();
}
function Tools_ThumbCommentsOnPage() {
_startThumbing(false);
}
function Tools_ThumbHerd() {
_startThumbing(true);
}
function Tools_PostComment() {
_postComment("Taking over the world together :" + _randomSeed());
}
function _getQoute() {
var qoute = Math.floor(Math.random()*11);
var qoutes = new Array();
qoutes[0] = "Is your argument that the Creator of the Universe was
working under a deadline and His manager forced Him to rush
inefficient designs into production? -- John B. Breckenridge in bpot";
qoutes[1] = "Fundamentalists: believe 2+2=5 because It Is Written.
Somewhere. They have a lot of trouble on their tax returns.";
qoutes[2] = "Moderate believers: live their lives on the basis that
2+2=4. But go regularly to church to be told that 2+2 once made 5, or
will one day make 5, or in a very real and spiritual sense, should
make 5.";
qoutes[3] = "Moderate atheists: know that 2+2=4 but think it
impolite to say so too loudly as people who think 2+2=5 might be
offended.";
qoutes[4] = "The role of the president of the United States is to
support the decisions that are made by the people of Israel. It is
not up to us to pick and choose from among the political parties. --
Former White House official Ann Lewis, representing Hillary Clinton.
WaPo, Mar 18, 2008.";
qoutes[5] = "> > > Goodbye to all! Thanks for years of great fun and
good /n > > > business! /n > > Suicide or MS C++? /n > Is there a
difference? /n Suicide hurts only once... /n -- Conversation on
borland.public.delphi.non-technical";
qoutes[6] = "FORD Vs Chevy";
qoutes[7] = "BMW Vs Mercedes";
qoutes[8] = "Taking over the world together one more time";
qoutes[9] = "The only thing we have to fear is fear itself";
qoutes[10] = "Help me";
return qoutes[qoute];
}
function Tools_SpamSeries() {
var seed = _randomSeed();
var qoute = _getQoute();
for(var i=0; i<50; i++) {
_commentCount++;
//_postComment(qoute + " :" + seed + " #" + (i+1));
_postComment(_commentCount);
}
//alert("Spamming Complete");
}
function _postComment(comment) {
if(_contains(window._content.document.location,"herd")) {
var arrDivs = window._content.document.getElementsByTagName('div');
for(var i=0; i < arrDivs.length; i++) {
if(_contains(arrDivs.getAttribute("id"),"commentBox")) {
elCommentBox = arrDivs;
var arrTextAreas = elCommentBox.getElementsByTagName
('textarea');
for(var x=0; x < arrTextAreas.length; x++) {
if(_contains(arrTextAreas[x].getAttribute("id"),"commentField"))
{
arrTextAreas[x].value = comment;
var arrInputs = getElementsByClassName
(window._content.document,"input","fbbutton");
for(var y=0; y < arrInputs.length; y++) {
//alert(arrInputs[y].getAttribute("onclick"));
if(_contains(arrInputs[y].getAttribute("onclick"), "http://
xxxxxxxxx.com/postComments.php")) {
//alert("found");
//setTimeout("_executeClick(arrInputs[y])",100);
_executeClick(arrInputs[y]);
}
}
}
}
break;
}
}
}
}
function _randomSeed() {
var randomnumber=Math.floor(Math.random()*1000000)
return randomnumber;
}
function _executeClick(oElement) {
if(oElement!=null) {
var evObj = window._content.document.createEvent('MouseEvents');
evObj.initEvent('click',true,true);
var ret = oElement.dispatchEvent(evObj);
}
}
function getElementsByClassName(oElm, strTagName, strClassName){
var arrElements = (strTagName == "*" && oElm.all)? oElm.all :
oElm.getElementsByTagName(strTagName);
var arrReturnElements = new Array();
strClassName = strClassName.replace(/\-/g, "\\-");
var oRegExp = new RegExp("(^|\\s)" + strClassName + "(\\s|$)");
var oElement;
for(var i=0; i<arrElements.length; i++){
oElement = arrElements;
if(oRegExp.test(oElement.className)){
arrReturnElements.push(oElement);
}
}
return (arrReturnElements)
}
function _LoadUrl(url) {
window._content.document.location = url;
}
function _contains(target, sub) {
if(target==null || target.toString().indexOf(sub.toString())
== -1)
return false;
return true;
}