# Tampermonkey script testing



## BrettStah (Nov 12, 2000)

There is a tampermonkey script that purports to enable endless scrolling on Xenforo forums. I haven't tried it yet.


----------



## Fofer (Oct 29, 2000)

BrettStah said:


> There is a tampermonkey script that purports to enable endless scrolling on Xenforo forums. I haven't tried it yet.


I found this one. Doesn't seem to be working for me though.

xenForo - Endless Forum Pages - Source code


----------



## BrettStah (Nov 12, 2000)

Anyone care to try out a tampermonkey script? It adds in a button on the "Watched Threads" page, and when you click the button, it opens up all of the threads on that page into separate tabs (going to the first unread post of each thread). I've only tested it myself, Windows 10, using the Chrome and the Tampermonkey extension. Presumably it should work with other browsers that support user-side scripts, like Tampermonkey does in Chrome.

Here's what it looks like:








The original script this is based on came from someone here, I think - FourOhFour, Fofer, someone else? Not sure, but a shout out to them, since I would not have been able to do this from scratch.

Oh yeah, this only works for the unread threads that actually appear on the page, so if you have more than 20, then this button only opens the 20 on the page. Once you open those 20 and refresh the Watched Threads page, you can click the button again to open more threads.


----------



## Fofer (Oct 29, 2000)

Yeah, I'll give it a shot.


----------



## BrettStah (Nov 12, 2000)

Doh, I could have sworn I posted the actual script! Wonder what happened...


----------



## BrettStah (Nov 12, 2000)

OK, so for some reason the forum won't let me add in script within code tags. It just never saves the changes. So I've saved it in a TXT file and shared it via this link:
https://1drv.ms/t/s!Ap8XYpUhD7_ZnpISY4xlflnfNK5BAA


----------



## BrettStah (Nov 12, 2000)

Ah, so I think it's a post length issue. The code is only 34 lines long, but I guess it's too many characters.


----------



## Fofer (Oct 29, 2000)

I've seen posts here with far more character than that 

Anyway, checking out the script now.


----------



## Fofer (Oct 29, 2000)

@BrettStah: the script appears to be working great! Thanks!


----------



## BrettStah (Nov 12, 2000)

Fofer said:


> I've seen posts here with far more character than that
> 
> Anyway, checking out the script now.


Yeah, I don't know what the deal is, but I did test post the first few lines (and then deleted them) and it worked. Feel free to try to post it yourself to see if it's some weird issue just with me (but I tried from Chrome on Windows and from my iPhone, and both failed). I didn't try from Tapatalk yet.


Fofer said:


> @BrettStah: the script appears to be working great! Thanks!


Awesome! It really wasn't too much of a hassle to do since I was just tweaking an existing script. I basically just had tell the script to just grab all elements with a class name of "unreadLink", which is what the hyperlinks linked to the thread titles use, and those are stored in an array, and then the next part adds a button to the page, and when the button's clicked, it spawns a new tab for each hyperlink in the array. It's actually easier to do with Xenforo threads than vbulletin ones slightly.


----------



## Fofer (Oct 29, 2000)

Fofer said:


> This looks like it may be of assistance?
> 
> xenForo - New Topics for Greasemonkey
> 
> userscripts/xenforonewtopics at master · ardiman/userscripts · GitHub


Did you base it off of this one? I couldn't get that one to work -- but yours is working fine.

Is there any way to have it automatically select the first tab, instead of the last one?



Fofer said:


> I found this one. Doesn't seem to be working for me though.
> 
> xenForo - Endless Forum Pages - Source code


Now I'm wondering if you've had a look at this one, and/or had any luck with it. It'd be very useful here.


----------



## BrettStah (Nov 12, 2000)

Fofer said:


> Did you base it off of this one? I couldn't get that one to work -- but yours is working fine.


No, I based it off of a script that someone linked to "elsewhere", I think. It looks like it may have also been posted here, or maybe that's where whomever originally posted it for me to see got it from:
Request: Open all threads with new posts in tabs(vBulletin) - Userscripts.org



Fofer said:


> Is there any way to have it automatically select the first tab, instead of the last one?


I'll check to see how that would be done. No promises. I'm not a javascript guru. 


Fofer said:


> Now I'm wondering if you've had a look at this one, and/or had any luck with it. It'd be very useful here.


Yeah, I was going to take a closer look at that one to see if I can figure out why it doesn't work. Maybe this weekend.[/QUOTE]


----------



## eddyj (Jun 20, 2002)

I'll try the open all script later, when I don't have so many unread threads.


----------



## Fofer (Oct 29, 2000)

BrettStah said:


> Anyone care to try out a tampermonkey script? It adds in a button on the "Watched Threads" page, and when you click the button, it opens up all of the threads on that page into separate tabs (going to the first unread post of each thread).


I modified the @include to have this instead:

*


Code:


// @include        http://www.tivocommunity.com/community/*

*So now it works not only in Watched Threads but also in sub-forums directly.

I also added another @include for another Xenforo-based forum I'm on, and it works well there too.

Thanks again!


----------



## Fofer (Oct 29, 2000)

Now I'm wondering if there's any way for the button to dynamically mention the number of threads it'll be opening. 

It knows if there are zero (the button only appears if there's one or more.) So for example, if there are five, it would say "Open 5 updated threads in tabs." Is that possible? I'm still learning javascript myself.


----------



## BrettStah (Nov 12, 2000)

That should be possible based on my knowledge of other languages. By the time the button is generated the array is already populated, so getting the count of elements in the array and using that number with the button text should be easy to do. I'll try it later today or tomorrow as time permits.


----------



## eddyj (Jun 20, 2002)

BrettStah said:


> That should be possible based on my knowledge of other languages. By the time the button is generated the array is already populated, so getting the count of elements in the array and using that number with the button text should be easy to do. I'll try it later today or tomorrow as time permits.


Just change this line:

var t = document.createTextNode("Open all updated threads in tabs");

to:

var t = document.createTextNode("Open all updated threads in tabs: " + newposts.length);


----------



## Fofer (Oct 29, 2000)

Thanks @eddyj! That works very well and now I've learned something too. I tweaked your code just a little bit:

var t = document.createTextNode("Open " + newposts.length + " updated threads in tabs" );


----------



## eddyj (Jun 20, 2002)

I was too lazy for that.


----------



## Fofer (Oct 29, 2000)

LOL  Thanks.

How can a thicker border be added to the button? I found this page but my attempts aren't working.


----------



## BrettStah (Nov 12, 2000)

How about something like this?










I stumbled across css styling via the script, so pretty much the button can be made to look however you'd like it to.

Basically add this line:

```
btn.style.cssText = '-webkit-border-radius: 28;  -moz-border-radius: 28;  border-radius: 28px;  -webkit-box-shadow: 0px 1px 3px #666666;  -moz-box-shadow: 0px 1px 3px #666666;  box-shadow: 0px 1px 3px #666666;  font-family: Arial;  color: #ffffff;  font-size: 16px;  background: #3498db;  padding: 5px 20px 3px 20px;  text-decoration: none;';
```
before this line (which I've also tweaked using what you and eddy discussed):

```
var t = document.createTextNode("Open the " + newposts.length + " updated threads below in separate tabs");
```
I used this site to generate the CSS code, and then just had to take the code it generated and put it into a single line.


----------



## David Bott (Jan 1, 1999)

Guys...This started out has a helpful Tips thread and now really is kind of off course. Tips are things normal users could benefit from...you got away from the good stuff.


----------



## BrettStah (Nov 12, 2000)

Yeah, agreed! Can you spin off all of the scripting stuff into a new thread, by any chance? I can create a new thread but obviously I couldn't move anyone else's posts.


----------



## Fofer (Oct 29, 2000)

David Bott said:


> Guys...This started out has a helpful Tips thread and now really is kind of off course. Tips are things normal users could benefit from...you got away from the good stuff.


Agreed and thanks for breaking it off. Sorry to have veered off course in the first place.

Can you fix the spelling of this thread though, the add-on is called "TamperMonkey."

Thanks!


----------



## BrettStah (Nov 12, 2000)

Fofer said:


> Agreed and thanks for breaking it off. Sorry to have veered off course in the first place.
> 
> Can you fix the spelling of this thread though, the add-on is called "TamperMonkey."
> 
> Thanks!


I was able to edit it.


----------



## BrettStah (Nov 12, 2000)

@Fofer, can you try posting the script in its entirety here within CODE tags, to see if it works or not?

Also, I don't see exactly how to choose which tab gets the focus - I suspect it's just the last one it opens though. I bet if I reversed the iteration through the array so that the links were open in reverse order, then the top thread would be opened last, and it would get the focus.


----------



## Fofer (Oct 29, 2000)

BrettStah said:


> @Fofer, can you try posting the script in its entirety here within CODE tags, to see if it works or not?


Weird, trying to post the code and it's not working for me either. The page's colors get all wonky and the post submission never completes.


----------



## BrettStah (Nov 12, 2000)

Yep, the buttons turn green for me.


----------



## Fofer (Oct 29, 2000)

BrettStah said:


> Also, I don't see exactly how to choose which tab gets the focus - I suspect it's just the last one it opens though. I bet if I reversed the iteration through the array so that the links were open in reverse order, then the top thread would be opened last, and it would get the focus.


Makes sense. Not really a big deal though. I'm happy with it as-is.


----------



## Fofer (Oct 29, 2000)

BrettStah said:


> Yep, the buttons turn green for me.


Which feels like a bug with the forum software. I can post this test text:


```
testing 123
testing 123
testing 123
testing 123
```
Hmm...


----------



## Fofer (Oct 29, 2000)

Perhaps as a workaround for the bug in the meantime (and also a good resource for this sort of thing in general as well as the future

If you submit this style to userstyles.org it will be easier for everyone to install it, and stay updated with any changes. As CSS it works with Stylish, and also auto-formats the code as a userscript for TamperMonkey and GreaseMonkey, all of which work with all browsers:


----------



## BrettStah (Nov 12, 2000)

That is a repository for all types of greasemonkey/tampermonkey scripts? This one isn't really doing much CSS stuff.

Mynplan was to hash out the script here and get it tweaked as needed, and then host it somewhere, and then post about it in Happy Hour.


----------



## Fofer (Oct 29, 2000)

Yeah, it's got userscripts and user styles, I've got dozens installed that way. And your plan sounds like a great one! I'm on board and will help spread the word once it's ready. Thanks for your work on it. It's a great time and click saver


----------



## BrettStah (Nov 12, 2000)

Did you see the extra line I posted that styles the button, by the way? Any thoughts?


----------



## Fofer (Oct 29, 2000)

Yes! It looks and feels great. I tinkered a bit and changed the background color, just to make it a bit more subdued. And I shortened the button's text.

Is there any way to move the button up a few pixels so it's vertically centered in this space?


----------



## David Bott (Jan 1, 1999)

```
// ==UserScript==
// @name           TCF Xenforo Open Updated Threads in Tabs
// @description    Open all forum new topics in tabs
// @include        http://www.tivocommunity.com/community/index.php?watched/threads*
// @grant          GM_openInTab
// ==/UserScript==

var newposts = [];
var lnks = document.getElementsByClassName('unreadLink');
for (var i=0; i < lnks.length; i++) {
//  if (/index.php\?.+\/unread/.test(lnks[i].href)) {
    newposts.push(lnks[i].href);
//  }
}

// DON'T DISPLAY IF NO NEW POSTS IN FORUM
if (!newposts.length) return;
//var divs = document.getElementsByClassName('titleBar');
var divs = document.getElementsByClassName('discussionList sectionMain');
var div = divs[0];
var btn = div.insertBefore(document.createElement('BUTTON'), div.firstElementChild);
var t = document.createTextNode("Open all updated threads in tabs");
btn.appendChild(t);
//btn.setAttribute('class','textcontrol');
//btn.setAttribute('href','javascript:void(0);');
//btn.innerHTML = "Open up all updated posts in tabs";
//btn.style.marginRight = '10px';
btn.addEventListener("click",
  function(e) {
    for (var i=0; i < newposts.length; i++) {
      GM_openInTab(newposts[i]);
      e.preventDefault();
    }
  }, false);
```


----------



## eddyj (Jun 20, 2002)

eddyj said:


> I was too lazy for that.


Actually, after trying a few things, I like it better with the count at the end (though I added parenthesis) so that it is easier to pick out the number, rather than being in the middle of the string. It may be worse English, but I find it more usable:


----------



## Fofer (Oct 29, 2000)

Can this very useful "Ignore Thread" shortcut (userscript) be tweaked to work with Xenforo now?

Ignore Thread

All we'd need is for the little "x" icon to link to the thread's URL with "/ignore-confirm" appended at the end.


----------



## BrettStah (Nov 12, 2000)

Hey, do you have a screenshot showing how the old script looked, with the little square X image?


----------



## Fofer (Oct 29, 2000)

Why yes, yes I do 










http://www.tivocommunity.com/commun...ignore-this-thread.420864/page-4#post-7130571


----------



## BrettStah (Nov 12, 2000)

Thanks! Looking at the original script, I'm pretty clueless as to actually how it works (unlike the "open in new tabs" script, which wasn't too hard to modify). 

So I've asked about converting it over at userstyles.org - let's see if someone can spot a quick and easy way to convert it!


----------



## Fofer (Oct 29, 2000)

Thank YOU!


----------



## BrettStah (Nov 12, 2000)

I know pretty much what needs to happen - iterate through all of the threads in the div with the class="discussionList section", grab the HREF url from each thread (which are in h3 tags with a class="title"), add in a new element next to the thread, use the same HREF url - except it needs to replace */unread *with */ignore-confirm*. But I don't know HOW to do that with javascript.


----------



## Fofer (Oct 29, 2000)

@FourOhFour was the original author of that particular script, perhaps he'd be interested in taking a new stab at it?


----------



## eddyj (Jun 20, 2002)

@BrettStah - The Open all Unread Threads script is not working.  I don't know anything about this, so maybe someone else can poke at it?


----------



## BrettStah (Nov 12, 2000)

eddyj said:


> @BrettStah - The Open all Unread Threads script is not working.  I don't know anything about this, so maybe someone else can poke at it?


Hmmm, just got to my laptop, opened up a brand new tab, opened up my bookmark to the "Watched Threads" page, and showed the button (11 unopened threads) - and the button properly opened them all into new tabs. So my guess is one of these are true:

1) You didn't have any unread threads at the time (the button doesn't show up if there are zero unread threads)
2) You need to reboot your computer.


----------



## eddyj (Jun 20, 2002)

Hmm, weird. It does work correctly on my other Xenforo forum that I added. Let me play some more.


----------



## markp99 (Mar 21, 2002)

Brett,

I had modified the the old Ignore Thread script to encode/embed the "[-]" image, vs pointing to a hosted image. It worked perfectly.


```
<<I cannot seem to paste the old tampermonkey code>>
```


/thx for clarification


----------



## Fofer (Oct 29, 2000)

Just for clarity's sake, the old "Better Ignore" script was different from the old "Ignore Thread" script. Due to the improved way XenForo handles ignores, the former script isn't really needed anymore.


----------



## eddyj (Jun 20, 2002)

eddyj said:


> Hmm, weird. It does work correctly on my other Xenforo forum that I added. Let me play some more.


Rebooted and all, but no joy. I definitely have unread threads.

Other Xenforo forum:









TCF:









I be sad! This was working perfectly earlier!


----------



## Fofer (Oct 29, 2000)

BrettStah said:


> Hmmm, just got to my laptop, opened up a brand new tab, opened up my bookmark to the "Watched Threads" page, and showed the button (11 unopened threads) - and the button properly opened them all into new tabs.


It's working fine for me too, FWIW.


----------



## eddyj (Jun 20, 2002)

Found it! I switched last night to https for this site, which is available to Club Members, but the script listed the http and not the https paths. Adding that fixed it.

Added: 
// @include https://www.tivocommunity.com/community/*


----------



## BrettStah (Nov 12, 2000)

So, do you guys actually use this button on pages other than "Watched Threads"? In my experience it would be really rare for me to want to open every thread in Now Playing, Happy Hour, etc.


----------



## markp99 (Mar 21, 2002)

For me, just "watched threads" would suffice.


----------



## eddyj (Jun 20, 2002)

BrettStah said:


> So, do you guys actually use this button on pages other than "Watched Threads"? In my experience it would be really rare for me to want to open every thread in Now Playing, Happy Hour, etc.


Been using it in the Political Forum too.


----------



## BrettStah (Nov 12, 2000)

eddyj said:


> Been using it in the Political Forum too.


Ah, that's a good one too. I am thinking I'll just keep mine limited to the Watched Threads, and will add the Political forum, to avoid accidentally clicking it elsewhere. At least at worst case it'll only open up 20! 

Has anyone gotten that endless scrolling script to work, by the way? How does that work in conjunction with this Open Unread in Tabs script?


----------



## Fofer (Oct 29, 2000)

BrettStah said:


> So, do you guys actually use this button on pages other than "Watched Threads"? In my experience it would be really rare for me to want to open every thread in Now Playing, Happy Hour, etc.


I don't use it often but like having it available in Happy Hour. It helps that the current maximum number of threads displayed is 20. I ignore some, some are already read, so it would just work on 12-15 or so new/updated threads.


----------



## BrettStah (Nov 12, 2000)

Still no response to my question about modifying that "Ignore Thread" script for Xenforo forums, by the way. I wish I had some time to set aside for a few hours and just try to figure it out, but I have meetings and other things scattered throughout this week. Maybe this weekend...


----------



## BrettStah (Nov 12, 2000)

I'm wondering if there's not much visibility here on this thread - I'm thinking about posting in Happy Hour, asking if there are any javascript gurus who could take a gander at the "Ignore Threads" script.


----------



## eddyj (Jun 20, 2002)

BrettStah said:


> I'm wondering if there's not much visibility here on this thread - I'm thinking about posting in Happy Hour, asking if there are any javascript gurus who could take a gander at the "Ignore Threads" script.


At least get it moved to Forum Operations. No one ever looks at this forum unless they are testing posts.


----------



## BrettStah (Nov 12, 2000)

Fofer said:


> Why yes, yes I do
> 
> 
> 
> ...


Heh, I just now noticed why you posted the smiley face!


----------



## Fofer (Oct 29, 2000)




----------

