I made a little random title script for the movie review pages with more than one review. A little impulsive thing... that took 40 minutes to figure out. Ugh. Here's how it turned out though, in two parts. It's in JS.
First there's the header, that either shows a random title from a specific list, or if the user has JS disabled, a standard one:
<h1><script src="/theme/js/more-reviews.js" type="text/javascript"></script><noscript>More Reviews!</noscript></h1>
Then there's the script with the aforementioned list, and code to cycle through the titles randomly, above refereed to as more-reviews.js
:
var r_text = new Array ();
r_text[0] = "More Reviews!";
r_text[1] = "Added Addages!";
r_text[2] = "Ongoing Opinions!";
r_text[3] = "Latter Ramblings!";
r_text[4] = "Future Views!";
r_text[5] = "Later Watches!";
var i = Math.floor(7*Math.random());
if (navigator.appName == "Netscape")
{
document.write(r_text[i]);
}
else
{
document.write(r_text[i]);
}
That's it! Depending on your number of titles you might need to change the formula below the list too. I tried using a solution that didn't rely on numbers at all first, but just couldn't get it working, so this is it.
This is what it looks like in action (reload page to see more):
It's such a simple thing, but I dug through such a huge mess of other methods before finding one that for some reason actually worked, that I felt like I needed to post about it. It's not all that strange this one did, but it's strange the others didn't. I still have no idea why. Something with the way H1 tags work? Something about including a JS script in a header? If you have any knowledge about such limitations I'd be intrigued to hear.
So, stranger who stumbled upon this post, if you're wise then feel free to send me a message, and if you're in the same situation - searching for a solution to the same problem, hopefully this will find you faster than it found me! And hopefully it'll work for you, too. It's just a little random random title script, but it sure took a big effort to get right.
Comments
The Comment Form
© CyberD.org 2025
Keeping the world since 2004.
how do you run this and why bother create an if statement if both branches execute the same thing?
You just embed it in any HTML page, wherever you want. Doesn't have to be in a header either. You could include the JS directly if you can't save it separately, it'd just get messy to have all that code in the middle of the page in my case. Makes it easier to edit when all instances refer to the same script, too. Better answer: https://www.quora.com/How-do-I-run-JavaScript-code
If you ever want to just play around with code and test stuff right away: https://jsfiddle.net/
As for the double statement hmm, man, I didn't notice that before. It's just a bit I've been using for all these things. It's possible it's some weird compatibility thing... will need to research!
I couldn't get that site to compile, so I used http://www.js.do instead.
any idea of how to make JS extensions?
Oh cool, a cool site I didn't know about!
Yupp, been using Userscripts for a while, with bits of JS just for specific sites. Good guide/script directory here: https://greasyfork.org/
Basically you'll need to install a browser add-on to load specific scripts, and then just install/make the bits you need. They'll load either for all or just specific intended sites, and can easily be toggled on/off. There's been a bunch of them made for NG over the years, though badly maintained now: https://knugen.newgrounds.com/news/post/444342
...think I have the links to at least one other similar lists somewhere if you're interested.
You can always run a JS directly on a particular page via the browser's developer console too, btw, but it'll be a manual thing each time. Shortcut keys for that vary with the browser, SHIFT + F12 on Chrome, I think. On FF I usually just right-click and 'inspect element' to open that up. Great for taking a full-page screenshot too, outside the visible area.
ahh, cool, good thinking...I will try the console option out.
any idea how I could grab variables from another script? For example, say I wanted to grab the r_text variable from more-reviews.js.
My example script here would first grab that variable. If r_text isn't equal to Added Adages! then it will refresh the page. The script would continue to execute until r_text = Added Adages!
nvm...found what I was looking for:
document.getElementsByClassName(object name)[0].someAction();
not sure why the index is necessary, but it works. try it:
document.getElementsByClassName("btn")[0].click();
also, on FireFox, there's actually a built-in javascript editor, press shift + F4
ok, so I know why there commands needs an index. you can technically have different instances of a class on your page, hence they are indexed in an array...(I said 'object name', it should be class. 'btn' is the name of the class for your button here.)
Wonder what you're trying to make there hmmm...
Oh cool the Randomly Wise prompt via alternate method. XD Learning quite a bit here. Wonder how long you've been fiddling around with JS? New hobby? I'm still mostly molding together the scripts I use via bits and pieces I find elsewhere, don't yet fully understand how everything I use works.
Thanks for the note on that Scratchpad too! Notepad built into the browser! :D Wonder if Chrome has anything similar...
The console shortcut there was just plain F12 btw, no need to shift.
not much, just visiting those websites where content is not indexed by pages, but rather seamlessly loaded on the same page by clicking a button (or scrolling). It would be impossible to download all this content via automation, unless I was able to execute a script that automatically clicks such buttons so everything can be loaded within the html.
I suppose I started yesterday. There's much to learn about languages. But you don't always need to understand a programming language to complete a task...just the logic and paradigms, which are universal.
Aha! I like where this is going. :) Such a script would be interesting to try out oncet ready!
For sure. Sounds like you have a natural talent for this type of logic, though, I've been around code so long but still mastered little outside the details that deal with design and designation.
I suppose it is ready, except it ooesn't actually load to the html file, just the browser. So if you try to view the source or save the page, it will only have the content before you press any buttons...Obviously it's still accessible somewhere, just not sure where...
Yeah I've been wondering how they actually load in that content too. Definitely not via a static script, since that'd defeat the purpose of a 'load more' feature in the first place... this thing could currently load up an endless array in one swoop though? Like NG feed history?
yes, in one swoop.
so...actually all you have to do see the generated content is select all + view source.
Awesome. :) After it´s been loaded right? Possible to send over that script via PM, if you don't feel like posting?
var x = 0, amount = 1000;
function openContent() {
document.getElementsByClassName("button")[0].click();
x++;
if( x 1000 times, or until all the content is loaded. Using these two metrics (1000 clicks with a 1000 ms delay) it works for about ~250 clicks. of course you can set x higher. you could try to set the ms parameter in setTimeout() lower too, but it's really a matter of how fast the browser can load the new content once the button is clicked.
this is just a brute force method, but it works. I though a simple loop would work for this, but the execution is too fast. IOW, the script doesn't wait for the browser to actually register a click, it just executes the JS command and proceeds regardless. For example, I had x set to 100 in a loop, but only got one click command before the loop was the finished. I could alternatively set x to Javascript's max integer size, but Firefox wouldn't like that. so that's why you have to use setTimeout() between clicks.
i also find it weird how setTimeout() works, you can't just enter the time as a parameter, you have to pass it a function as well. So essentially what is happening here is the last line (OpenContent()) executes first, and the function is called recursively (in a sense) as long as x > 1000.
oops accidentally cut off the code.
var x = 0, amount = 1000;
function openContent() {
document.getElementsByClassName("button")[0].click();
x++;
if(x < amount){
setTimeout(openContent(), 1000);
}
}
openContent();
also seems like the comment boxes don't
like
tabs
but
do
multiple
spaces
work
i guess not...btw ur getting spammed. time to cleanup
Yupp, tabs don't work! Multiple spaces don't either. :P
Have to have HTML like that sealed off to keep out possibly malicious spam comment stuff, but allowing for tabs and spaces hmm, that might be doable... further research required. Could turn into one of those tiny feature = 40 minute type of things. XD
As for the script: looks good! Shall try it for the aforementioned feed in a bit.
Oh whoops, looks like HTML like that is NOT sealed off... looks like I should probably look up some stuff there too...