Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Discussion on Boards.ie user scripts

Options
2»

Comments

  • Registered Users Posts: 21,254 ✭✭✭✭Eoin


    Cool - I'm a bit out of the loop these days :)


  • Closed Accounts Posts: 3,609 ✭✭✭Boards.ie: Danny


    Don't bother trying to console.log here on Boards.ie or any other vBulletin site though, vBulletin has a lovely piece of console-log killer code in it's global.js ;)


  • Registered Users Posts: 1,311 ✭✭✭Procasinator


    Don't bother trying to console.log here on Boards.ie or any other vBulletin site though, vBulletin has a lovely piece of console-log killer code in it's global.js ;)

    I can see that, replaces all the console.x methods with a blank function. I'm guessing that is to disable their debug message being emitted in production mode. That and stop errors in IE.

    Kind of annoying when libraries go monkey-patching the core though.


  • Closed Accounts Posts: 3,609 ✭✭✭Boards.ie: Danny


    I can see that, replaces all the console.x methods with a blank function. I'm guessing that is to disable their debug message being emitted in production mode. That and stop errors in IE.

    Kind of annoying when libraries go monkey-patching the core though.

    Yep, absolutely crazy stuff going on there. Would have been better off wrapping it up in a vBulletin logger and then having a debug on/off on that for production instead of this minified, half obfuscated mess of a JS library thrown in on the page. So yeah, console.log is all well and good when you know what you're doing :pac:


  • Closed Accounts Posts: 14,762 ✭✭✭✭stupidusername


    Here's what I've got:
    alert(document.getElementsByClassName("smallfont")[0].innerHTML);
    

    I've tried numerous different versions, using ClassName, TagName, different classes and tags obviously, getting at different parts of the array etc etc. The above is not doing anything at all to my page.

    This:
    var smalltext = document.getElementsByClassName("smallfont");
    alert(smalltext.length);
    
    is alerting 0

    This:
    var bigtext = document.getElementsByTagName("div");
    alert(bigtext.length);
    
    is alerting 0 also.

    So no matter what I try it with, I have an empty array. I don't know what I'm doing wrong.


  • Advertisement
  • Registered Users Posts: 10,624 ✭✭✭✭28064212


    Here's what I've got:
    alert(document.getElementsByClassName("smallfont")[0].innerHTML);
    
    I've tried numerous different versions, using ClassName, TagName, different classes and tags obviously, getting at different parts of the array etc etc. The above is not doing anything at all to my page.
    It should be. Doesn't sound like the script is running at all, just add alert("test"); at the top to be sure. Are you using Chrome or Firefox? Are you saving the page locally and adding the javascript to it directly, or using Greasemonkey?

    Boardsie Enhancement Suite - a browser extension to make using Boards on desktop a better experience (includes full-width display, keyboard shortcuts, dark mode, and more). Now available through your browser's extension store.

    Firefox: https://addons.mozilla.org/addon/boardsie-enhancement-suite/

    Chrome/Edge/Opera: https://chromewebstore.google.com/detail/boardsie-enhancement-suit/bbgnmnfagihoohjkofdnofcfmkpdmmce



  • Closed Accounts Posts: 14,762 ✭✭✭✭stupidusername


    28064212 wrote: »
    It should be. Doesn't sound like the script is running at all, just add alert("test"); at the top to be sure. Are you using Chrome or Firefox? Are you saving the page locally and adding the javascript to it directly, or using Greasemonkey?

    It is running, I've tried with "Bla" and it works. I think it's the innerHTML part that isn't working. whenever that's in it doesn't run anything.
    I'm working in Chrome, and the page is saved locally, with the script saved on top.


  • Registered Users Posts: 10,624 ✭✭✭✭28064212


    It is running, I've tried with "Bla" and it works. I think it's the innerHTML part that isn't working. whenever that's in it doesn't run anything.
    I'm working in Chrome, and the page is saved locally, with the script saved on top.
    Ah, move it to the bottom. The element probably doesn't exist yet when the script runs

    Boardsie Enhancement Suite - a browser extension to make using Boards on desktop a better experience (includes full-width display, keyboard shortcuts, dark mode, and more). Now available through your browser's extension store.

    Firefox: https://addons.mozilla.org/addon/boardsie-enhancement-suite/

    Chrome/Edge/Opera: https://chromewebstore.google.com/detail/boardsie-enhancement-suit/bbgnmnfagihoohjkofdnofcfmkpdmmce



  • Closed Accounts Posts: 14,762 ✭✭✭✭stupidusername


    But then wouldn't it return something, like Undefined? I put this at the bottom, and there's now no alert box.
    var smalltext = document.getElementsByClassName("smallfont");
    alert(smalltext.length);
    


  • Registered Users Posts: 10,624 ✭✭✭✭28064212


    But then wouldn't it return something, like Undefined? I put this at the bottom, and there's now no alert box.
    var smalltext = document.getElementsByClassName("smallfont");
    alert(smalltext.length);
    
    No, because when you call innerHTML on an undefined element, it throws an error and the script stops running. The last few lines of your HTML file should be:
    ...
    <script language="javascript">
    var smalltext = document.getElementsByClassName("smallfont");
    alert(smalltext.length);
    </script>
    </body>
    </html>
    

    Boardsie Enhancement Suite - a browser extension to make using Boards on desktop a better experience (includes full-width display, keyboard shortcuts, dark mode, and more). Now available through your browser's extension store.

    Firefox: https://addons.mozilla.org/addon/boardsie-enhancement-suite/

    Chrome/Edge/Opera: https://chromewebstore.google.com/detail/boardsie-enhancement-suit/bbgnmnfagihoohjkofdnofcfmkpdmmce



  • Advertisement
  • Closed Accounts Posts: 14,762 ✭✭✭✭stupidusername


    the problem was I had put it into an already existing script tag, with script type defined, rather than script language. So now I've it in: <script language="javascript"> and it works! :D thanks!


  • Registered Users Posts: 586 ✭✭✭Aswerty


    It is running, I've tried with "Bla" and it works. I think it's the innerHTML part that isn't working. whenever that's in it doesn't run anything.
    I'm working in Chrome, and the page is saved locally, with the script saved on top.

    Ha ha, I'm a big fan of bla but I like to add a h on to the end, blah. Blah, blah, blah all day long..

    Thanks to the procrastinator for the youtube link for the chrome dev tool. I use it for inspecting HTML but didn't realise I could breakpoint my javascript with it. I guess my alert("blah") is going to go the same way as my printf("hello").


  • Closed Accounts Posts: 14,762 ✭✭✭✭stupidusername


    Hmmm. Just been thinking about this, and looking at it a bit. 28062412, you said all I have to do is find the element on the page that contains the number and go from there.... but the number will is static. it will only update when you refresh the page... so that's not going to work. I mean unless the page is getting refreshed somehow, the number of the Unread PMs is going to remain at 0.

    Now, that's a different thing - doing an auto refresh every 30seconds or so, but definitely don't want to do that. I do want to check the unread messages count, but I don't see how I can do that given the information on the page.

    Ugh, I don't know what I'm at here tbh, thinking I should just give up!


  • Closed Accounts Posts: 3,609 ✭✭✭Boards.ie: Danny


    Don't give up, what'd be the fun in that? ;)

    Have you ever noticed that if you stay on the same page on the Beta theme and somebody sends you a PM eventually your PM icon will turn orange and start flashing? Why would that happen without a refresh of the page (which we don't do :)). Look at it yourself - swap to the Beta theme, get your Browser Console's Network tab open and wait - finding this stuff out yourself will help you learn but if you don't want to do that then see spoiler below.
    We've got an endpoint you can send an ajax request to which will provide you with the unread count of PMs and Followed Threads for the currently logged in user.

    http://www.boards.ie/development/api/cascade/json/index.php

    Also, if you're going to poll this resource then poll it as little as possible, definitely no more than once per minute :)


  • Closed Accounts Posts: 14,762 ✭✭✭✭stupidusername


    Yeah I know, and I was trying stuff out myself. . . but then i come to realise I know so little, and well, I think I'm at nothing. I assumed it was something to do with JQuery, but thanks for explaining. I still don't know what's what though. might take a fresh look at it tomorrow.


Advertisement