« first day (1852 days earlier)      last day (3099 days later) » 

crl
11:00 PM
just try to find where the error is, sorry but have things to debug too on my side
 
document.getElementsByClassName("inbox-item") returns an empty array <- that's the problem
I don't really know how to fix it
 
then that class doesn't exist ?
 
but it does, once I click on the inbox button on the SO homepage
 
crl
maybe the dom isn't loaded yet
 
so I included a document.getElementsByClassName("topbar-icon icon-inbox yes-hover js-inbox-button")[0].click() in my userscript, but that doesn't help either
exactly, the DOM isn't loaded until I actually click on the icon
How can I get to that information in JS?
 
11:03 PM
these inbox content is picked up by ajax once you've clicked that box icon
so you have to trigger it
 
How would I trigger it? I thought document.getElementsByClassName("topbar-icon icon-inbox yes-hover js-inbox-button")[0].click() would have done the trick
 
<a class="topbar-icon icon-inbox yes-hover js-inbox-button" title="Recent inbox messages" href="#">
that's the link that you need to trigger
then it loads a div with inbox-item in the hidden div
 
I'm very new to JS. Could you please explain to me how I should trigger it? I tried clicking on it using JS (I've posted my code that does that), but that doesn't seem to work
how would I go about triggering the dom elements?
 
crl
!!> var f=function(){console.log(1)}; f()
 
@crl "undefined" Logged: 1
 
11:08 PM
@crl are you suggesting that I insert that in my code somewhere?
 
@inspectorG4dget you don't trigger an event with .click(). see developer.mozilla.org/en-US/docs/Web/Guide/Events/… for how to programatically simulate a click
 
crl
what, react 0.15 already..
 
@crl whre?
 
ahh. Thanks @Luggage
 
11:12 PM
ohh, that says it doesn't work in IE.. i thought that was the standard way..
 
.click() is a jQuery feature
 
elem.addEventListener("click",function(){}); is better
usually
except you already using jQuery :)
 
he's trying to trigger the click, not add a handler
 
^--
 
and is NOT using jQuery.
Other that those two bits of trivia, you are spot on. :)
 
11:18 PM
still not working. After the click dispatch, I still am unable to find inbox-items
 
how do you dispatch it ?
 
var event = new MouseEvent('click', {
				'view': window,
				'bubbles': true,
				'cancelable': true
			});
			var inboxButton = document.getElementsByClassName("topbar-icon icon-inbox yes-hover js-inbox-button")[0];
			inboxButton.dispatchEvent(event);
 
getElementsByClassName only takes one class name.
 
^--
take querySelector instead
 
11:19 PM
var inboxButton = document.querySelector(".topbar-icon .icon-inbox .yes-hover .js-inbox-button");
remove the [0] though
 
erm... the source code of the SO page says that the class is that entire string, though
 
the format it's in the html is different than the query language used to find it
 
if it has an id, you can use that
otherwise, if you need to find it buy a list of classes use a css selector with document.querySelector()
 
you can search by js-inbox-button only. it is unique
var inboxButton = document.getElementsByClassName('js-inbox-button')[0];
 
11:23 PM
nevermind, ignore that
 
35
Q: New! Expanded Profile Information

bluefeetYour profile is used to show off a bit about who you are as a developer, who you are as a user of Stack Overflow, or whatever else you want to include in it. In our ongoing efforts to improve it, we recently performed some minor tests for both new and existing users. The testing went well and to...

 
var container = document.getElementsByClassName("inbox-item")[m];
console.log("woof"); //:
console.log(container); //:
container = container.getElementsByClassName("item-content")[0];
That last line is screwing up, now
I see a woof on the console, but nothing where I would expect to see container
 
you really should just use querySelector
 
ok, porting over
how do I use query selector when I want the mth occurrence of a certain class?
 
you can use querySelectorAll
 
11:30 PM
^--
 
returns a nodelist (array-like)
 
thanks
 
querySelector( <ur_css_selector>) === querySelectorAll( <ur_css_selector>)[0]
 
		if (true) {//(numMsgs > 0) {
			var event = new MouseEvent('click', {
				'view': window,
				'bubbles': true,
				'cancelable': true
			});
			var inboxButton = document.querySelector('.js-inbox-button');
			inboxButton.dispatchEvent(event);
			for (var m=0; m<numMsgs; ++m) {
				var container = document.querySelectorAll(".inbox-item")[m];
				console.log("woof");  //:
				console.log("container: " + container);  //:
				container = container.querySelector(".item-content");
that last console.log gives me the output container: undefined
that doesn't make sense. Could someone please verify
 
Why doesn't it make sense? What's numMsgs?
 
11:38 PM
numMsgs has been set to 5 for debugging purposes
 
i was just digging in a laptop of a female friend whom has "weird browsing issues". Apparently she installed a mal/adware.
 
@inspectorG4dget And document.querySelectorAll(".inbox-item").length?
 
heh firefox got "infected" too. I'm going to check her browsing history to see what she did download :P
 
inb4 p0rn
 
@copy length is giving me 0, which explains the undefined bug. But I see elements of that class in the html
 
11:41 PM
var inboxButton = document.querySelector('.js-inbox-button');
inboxButton.dispatchEvent(event);

^--- wait till the ajax transfer has been completed.

var boxes = document.querySelectorAll(".inbox-item");
for (var i = 0; i < boxes.length; ++i) {
     var inputbox = boxes[i];
     // use inputbox
}
don't make yourself difficult :)
 
@inspectorG4dget You might need to use mutation observers to wait until the elements are in dom
 
is dispatchEvent blocking? will it wait for the ajax, or should I use a sleep somewhere?
 
No, (properly used) xhr doesn't block
You should use mutation observers
 
the xhr is written by SO
if it's not properly used, then i would eat my shoes
 
how would I go about writing a mutation observer?
(sorry, I'm super new to this, and started this expecting a simple hack; now I'm in too deep and can't get it out of my head)
 
11:45 PM
!! tell inspectorG4dget mdn mutation observer
 
@inspectorG4dget MutationObserver
 
please bookmark mdn, it's a reference for us, js devs
 
This is a bit over my head. I'd appreciate anyone walking me through this
 
@RoelvanUden Well, always possible I'm doing something wrong - I have what is in effect a multi-sided task management system. Angular is used more or less for the administration/power user side running on gae. The admin side sends out html emails and sms text messages, usually with a link to accept a job or reject.
@RoelvanUden The landing page needs to be as compatible and light as possible, IE8+, data driven and responsive, bootstrap , jquery, velocity are doing the job so far, albeit without a reactive/ajax design, except for 1 page where I played with knockout.
 

« first day (1852 days earlier)      last day (3099 days later) »