Greasy Fork is available in English.

Discussioni » Sviluppo

can anyone with javascript knowledge help?

§
Pubblicato: 20/02/2015

can anyone with javascript knowledge help?

i want to make youtube comments on the watch page load automatically again.
i thought it would be something like 'if (scroll of the page>value){load comments}
so i could just change it to if (1=1) or something.
and instead it looks like an inunderstandable mess.
i searched for 'scroll' and 'comments', and i think the following java script file is what i should edit, but i dont know where. i think the part that has the comments and get a delayed loading is 'comments-test-iframe', since its not there before the comments load , if that helps. it seems to not exist at first, so i think it has to be created later.
wells anyway here is the script that i think has the part i would need:

http://s.ytimg.com/yts/jsbin/www-en_US-vflGvMGAs/common.js

and thanks in advance

wOxxOmMod
§
Pubblicato: 20/02/2015
§
Pubblicato: 20/02/2015

uh.. no, that only auto-clicks the button that loads more comments...
"Basically the script simply clicks the More button once the first comment block is loaded" and the script looks like it does that too.

anyways... the div is totally empty at start. like this:

so it could be a .innerHTML adding content to it? or something like that?

§
Pubblicato: 20/02/2015

eh.. i meant to write, "like this:

"

§
Pubblicato: 20/02/2015

^^^ whatever... you see it when you quote my comment

wOxxOmMod
§
Pubblicato: 20/02/2015
Modificato: 20/02/2015

The script is now updated to work in Chrome too, previously it was only working in FF.

P.S. You can modify your posts - click the black gear icon on the right side of your post and select Edit.

§
Pubblicato: 20/02/2015

i dont use chrome though. but it still doesnt help me...
i would need the comment section to automatically load instead of waiting for the page scrolling to go down. i think it doesnt load the comments for me because the scroll check is different in my old firefox.
so can you or anyone help me?
another thing is, i noticed on an other computer where the comments load, that when it loads, the part of HTML that contains the "Loading..." message and icon are put in comment... thing. are made comments. thats why they disappear.
so i could maybe find the part i need if i searched for that

wOxxOmMod
§
Pubblicato: 20/02/2015

I'll look into that. Apparently it's autoshowing here because the video only occupies half of the browser height here so the comments are initially shown and then the userscript autoloads all of them. So if I reduce the browser window I'll be probably able to reproduce the issue.

§
Pubblicato: 21/02/2015

oh. thank you then.
actually i will try replacing all 'scrollTop' and 'pageYOffset' with a value, like 1500 or something that should be enough to make the condition true that starts the comment loads.
i will have to do that everywhere though, since it would be really hard to understand which part has to do anything with the comments. the functions seem to have random two letter names, and most of them call other functions inside too. i dont even know how anyone other than who did this could make anything out of it

§
Pubblicato: 21/02/2015

soo... now i dont know how to insert javascript in parts like this:

wOxxOmMod
§
Pubblicato: 21/02/2015
  1. The above userscript is updated and now it autoloads the comment block even if it's outside the visible part of the page 2. >the functions seem to have random two letter names

Code minification.

  1. >yt.setConfig

Inside a userscript:

  // @grant unsafeWindow
  ..................
  unsafeWindow.yt.setConfig(...............);

To use js in the addressbar you'd need to tweak your browser probably, here's an example for FF: link, then just type:
javascript:yt.setConfig(............)

§
Pubblicato: 21/02/2015

oh. i didnt notice that userscript was made by you
it still doesnt seem to work though... could it be because im using an old firefox?
comments load without any problems at /all_comments pages though. so im pretty sure its about the delayed loading and page position checking things

wOxxOmMod
§
Pubblicato: 22/02/2015

The script uses MutationObserver which was added in Firefox 14.

§
Pubblicato: 22/02/2015

oh...
could i change it somehow to work without that?

wOxxOmMod
§
Pubblicato: 22/02/2015
Modificato: 25/02/2015

Well, there were very slow DOM modification events, so I'd rather not use them, but instead a simple timer of 1000ms for intial autoload and 2000ms for subsequent clicks of the More button.

v3:

// ==UserScript==
// @name          Autoload Youtube comments (Firefox 3.6)
// @include       https://www.youtube.com/all_comments?v=*
// @include       https://www.youtube.com/watch*
// @include       https://addons.mozilla.org/*
// @description   Autoloads all comments on Youtube when you open the video page
// @version       1.0
// @author        wOxxOm
// @namespace     wOxxOm.scripts
// @license       MIT License
// @run-at        document-end
// @grant         GM_addStyle
// ==/UserScript==

if (location.href.indexOf('all_comments') > 0) {

  GM_addStyle('.content-alignment {width:100%}');
  var footer = document.querySelector('#footer-container');
  if (footer)
    footer.parentNode.removeChild(footer);

  clickMore();

} else {

  var f = document.createElement('iframe');
  f.src = 'https://www.youtube.com/all_comments?v=' + location.href.match(/v=(.+?)([#&]|$)/)[1];
  f.width = '640px';
  f.height = '3000px';

  var e = document.querySelector('#watch-discussion');
  e.parentNode.insertBefore(f, e);
  e.parentNode.removeChild(e);

}

function clickMore() {
  var more = document.querySelector('.show-more');
  if (more) {
    more.click();
    setTimeout(clickMore, 2000);
  }
}
§
Pubblicato: 22/02/2015

still doesnt work though... it just moves the comment block into the visible area right?
but i think the problem is that the position checking doesnt work.since it might be different in later browsers or something. actually i didnt see comments on the watch page ever since it was changed, thats why i would need to solve this. and thank you for caring about it

wOxxOmMod
§
Pubblicato: 22/02/2015
it just moves the comment block into the visible area right?

Yes.

since it might be different in later browsers or something. actually i didnt see comments on the watch page ever since it was changed

Indeed, it's quite probable that Google stopped caring about the old browsers, this is what they do usually and Opera browser was the first victim afaik.

§
Pubblicato: 22/02/2015

it seems to be a problem for people using internet explorer too...
the only things in the function that seems like its related to comment "render" and page position are:
window.location.search.length
and
window.location.hash.length
but those arent really related to the scroll position right?
since i dont know how to paste a script in that thing where the script url is now, i will try to upload a changed file and make it call that instead

wOxxOmMod
§
Pubblicato: 22/02/2015

I've installed Firefox 3.6, opened youtube.com and the site immediately warned me that the browser is not supported, then on a video watch page the browser console showed an error occured in youtube javascript code which clearly indicated that it uses some things that only new browsers support.

I'm quite sure you won't be able to fix this.

§
Pubblicato: 23/02/2015

but on the all_comments pages they load perfectly... and its probably the things that check the page/scroll position. they would just need to load immediately with the page like they do there.
other people are having problems on internet explorers too if im right, not just on old browsers.
i dont know what to do though, thats why i hoped someone can do something

§
Pubblicato: 23/02/2015

if i write something like 1500 in the place of 'scrollTop' and 'pageYOffset' it should work though right?
or there are some other things that check the scroll position?

wOxxOmMod
§
Pubblicato: 24/02/2015

I've updated the code block above so that it dumbly loads the all_comments page in a scrollable IFRAME, this should work in FF 3.6.

§
Pubblicato: 25/02/2015

i dont want to bother you any more, but still doesnt seem to work...
BUT i might have a better idea...
if i would know which firefox file gets those things in later versions, i could just replace that one file and it should work right? i mean the comments and the scripts too

wOxxOmMod
§
Pubblicato: 25/02/2015
Modificato: 25/02/2015

I've updated the code above again and this time it works, I've had checked it on FF3.6 in a sandbox.

As for those things in later versions, it's actually an inseparable core of the browser.

§
Pubblicato: 25/02/2015

cool script wOxxOm , just tested on Google Chrome, works fine, it's loading all comments

wOxxOmMod
§
Pubblicato: 25/02/2015
just tested on Google Chrome, works fine

The February 20 version was already working in Chrome with Tampermonkey extension (it's an analog of Greasemonkey in Chrome).

§
Pubblicato: 26/02/2015

oh. thank you, it really does work.
it looks kindof weird to have the whole all_comments page there in a frame though.
wouldnt it be simple to just edit the part which checks if the comments should load, and make it always return true? or whatever value is needed
i really dont want to bother you with this, and thank you for everything, but i will probably use whatever script you do for all my future time on youtube. unless they fix or change it sonmewhat

wOxxOmMod
§
Pubblicato: 26/02/2015

Well, the frame looked okay when I tried it, just a small video thumbnail over the comments and a scrollbar on the right were revealing its foreign origin. BTW you can remove any unwanted elements from the frame quite easily yourself, rightclick the element and choose firebug/inspector, then step up the hierarchy until you find the enclosing element (click it to see it highlighted on the page) and paste its id (prepend it with #) or class (prepend it with .) in the example below and put it on a new line after GM_addStyle in the userscript.

  if (e = document.querySelector('#watch-response-header')) 
    e.parentNode.removeChild(e);

This one should remove the small vieo thumbnail from the top.

§
Pubblicato: 27/02/2015

oh, thank you.
but wouldnt it be possible to load only the comments part? or to make the watch page comments load on page load? i dont know much about javascript. sorry

wOxxOmMod
§
Pubblicato: 27/02/2015

In short, no.

§
Pubblicato: 28/02/2015

oh... sorry then. guess im asking too much
thank you though

§
Pubblicato: 01/03/2015

but wait... why would it be impossible? if they made it in javascript, it should be able to be changed with javascript in any way, i think.
if you dont want to do it that doesnt mean someone else cant, right?
since this is really important for me

§
Pubblicato: 07/03/2015

but what if i just replace the scrollbar checking things with a version that works on my firefox? why wouldnt that work?

§
Pubblicato: 08/03/2015

i know i bothered you enough, but i just need to know what i should edit.
since the all_comments comments section loads, there should be an apparent difference between the loading of it and the /watch pages...
since the javascript file seems to be the same, there should be a part distinguishing them or something at least.

wOxxOmMod
§
Pubblicato: 08/03/2015

The thing is I don't understand what's wrong since it looked okay last time I checked. Maybe some screenshots will help.

§
Pubblicato: 09/03/2015

um... its still the same.
i just need the watch page comments to load somehow..
your script is awesome but not really the same, and i dont know if it would be good to have the comments be like that all the time from now on, or maybe until they change it back.
so i thought it should be possible to get the real watch page comments load instantly, even if the code is obfuscated or what its called.made hard to understand.
since the loading only after an amount of scroll is what should be dealt with, i thought it could work if i replaced scrollTop and pageYOffset everywhere with 1500. since thats a value they could return that would make the comments load, right?
so i uploaded the java script files from the youtube source which had those functions or whatever those are, but replaced them with 1500:
http://a.pomf.se/qxzoyz.js =ytcommon.js
http://a.pomf.se/zfyibf.js =ythtml5.js
http://a.pomf.se/ctlyas.js =ytpageframe.js
http://a.pomf.se/pzxrib.js =ytspf.js
so... if i inserted the java script calling code from the page source but put these URL-s instead of the current ones, would it work?
or there could be something easier too, but i dont think its impossible..
since people made codes changing the player, and changing complex things, like how many video thumbnails load and how, how the video loads, even made something like playing part of the video on mouse hover if im right, i thought there would be a code for this too, but i searched a lot for it and didnt find one, even though many people seemed to be complaining about the new comment load too. im sorry if i missed something. and im sorry for bothering you, but you seem like the only person willing to help

wOxxOmMod
§
Pubblicato: 09/03/2015

Ah, now I see. Well, this is way beyond my level, I can only do something simple as can be seen from my tiny scripts on GF with 10-20 lines of code. Not a wizard like the author of Youtube Center userscript.

§
Pubblicato: 10/03/2015
Modificato: 10/03/2015

you seem to be the only one who cares though..
and you seem to know a lot about javascript too.
um.. ill check if what i wanted to try works

§
Pubblicato: 10/03/2015

doesnt seem to work..

§
Pubblicato: 12/03/2015

now i tried to do something in Customize your web extension/addon whatever.
the comments seem to be in an iframe i cant do anything with, and even if i cut and paste the DIV its in, the page wont load. is there a way to do something with the iframe? i dont really know what that means

wOxxOmMod
§
Pubblicato: 12/03/2015
Modificato: 12/03/2015

If that addon is similar to Stylish (the most popular addon of the kind) then you need to specify the iframe's source url for the style you create. To see the url rightclick inside the iframe, choose "This frame", "Open in new tab", then use that tab's address for your style - remember to strip all volatile data, usually a minimal unique prefix is used e.g. https://www.youtube.com/all_comments. Search the userstyles forum for [more] tips on styling the frame and iframe containers.

§
Pubblicato: 13/03/2015

customize your web is kindof like that, but you dont have to write codes. just click things mostly. could you check if its possible to create the iframe before it exists, or something like that?

§
Pubblicato: 13/03/2015

OH damn-
yes, when i open them that way, it works perfectly. if the exact same thing could be on the watch page it would be perfect. unfortunately, when i try to cut it with customize your web, i always get an error that: "Action could not be added because the URL of the target window doesn't match with the url patterns defined for the current script."
even though i added all the URLS in the URL include list. i tried it with the profile pictures and the same error comes up, even though their URLs are obvious when you view the picture itself in the browser, and i included them...
can you help put it on the page somehow? i literally just need the exact same things that come up when viewing the frame only.
like:
https://apis.google.com/u/0/wm/4/_/widget/render/comments?usegapi=1&first_party_property=YOUTUBE&href=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DtPEE9ZwTmy0&owner_id=9kN-ROrTY81zH856AxXuGQ&query=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DtPEE9ZwTmy0&stream_id=UC9kN-ROrTY81zH856AxXuGQ&substream_id=tPEE9ZwTmy0&view_type=FILTERED&width=612&youtube_video_acl=PUBLIC&viewer_id=UCVGg4TBGsIoW29hdo9ji1-g&hl=hu_HU&origin=https%3A%2F%2Fwww.youtube.com&search=%3Fv%3DtPEE9ZwTmy0&hash=&gsrc=1p&jsh=m%3B%2F_%2Fscs%2Fabc-static%2F_%2Fjs%2Fk%3Dgapi.gapi.en.ehmAeuu_4hE.O%2Fm%3D__features__%2Fam%3DAAI%2Frt%3Dj%2Fd%3D1%2Frs%3DAItRSTNcM--L6Y_snQHC2igwllAwLSbYBg#_methods=onPlusOne%2C_ready%2C_close%2C_open%2C_resizeMe%2C_renderstart%2Concircled%2Cdrefresh%2Cerefresh%2Confirsttimeplusonepromo%2Conthumbsup%2Contimestampclicked%2Conshareboxopen%2Conready%2Conallcommentsclicked&id=I0_1322865902788&parent=https%3A%2F%2Fwww.youtube.com&pfname=&rpctoken=17281705

wOxxOmMod
§
Pubblicato: 13/03/2015

Dunno about that addon. Anyway it's offtopic here.

§
Pubblicato: 14/03/2015

umkay. i dont need that addon, but its easier to use and i dont need to write codes in it. i just need those frames so be on the page originally and it would be perfect

§
Pubblicato: 14/03/2015

like... could you just edit your code that puts the all_comments page there to put the comments frame there instead? the one the page would call i mean.
and then this topic would be solved

§
Pubblicato: 14/03/2015
Modificato: 14/03/2015

okays, its possible to just use the URL without all that long stuff after it, like this:
https://apis.google.com/u/0/wm/4/_/widget/render/comments?usegapi=1&first_party_property=YOUTUBE&href=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DtPEE9ZwTmy0

but with different video URL pasted after v% it doesnt work.
would it be possible to check what URL the frame would be loaded from, to put that in the script?

EDIT:
i was stupid as hell...
the video url is only the one after v%3D and i deleted the D too
so tPEE9ZwTmy0 is the video URL after ?v= for the comment link above.
could you be so awesome to make the frame load that way? so basically this same URL above, but with the video URL which is after ?v= after v%3D
could you do this please?

§
Pubblicato: 15/03/2015
Modificato: 15/03/2015

okay now it works, but its like refreshing the page a bit after it loads... is that necessary?

or at least the video starts over. the comments are already loaded at the time though. so dont really know why

§
Pubblicato: 19/03/2015

could you help with one last thing though please?
how to make the whole frame visible all the time?
i tried f.overflow = 'visible';
but it still has the scrollbars and doesnt expand downwards.. could you help please?

wOxxOmMod
§
Pubblicato: 20/03/2015

This can only be achieved by setting frame's height to the actual content height, but the problem is that the frame and the parent page are in different sandboxes script-wise, so such a trivially looking task would require some non-trivial code to pass the value between them.

§
Pubblicato: 20/03/2015

so its not possible with overflow? its practically just overflowing though.
could you give any tips? maybe the size of the scrollbar could be checked to determine the height or something? if there is no easier way.
i thought it should be pretty simple though. if the frame knows how much content isnt visible, shouldnt it be simple to just make it show all?

wOxxOmMod
§
Pubblicato: 20/03/2015

The frame holds a different document and the scrollbar belongs to that inner document, but the parent page can only set and see the dimensions of the frame container, not its contents. Thus, so such a trivially looking task would require some non-trivial code to pass the value between them.

§
Pubblicato: 21/03/2015

but you could help somewhat right? i dont know anything about this

wOxxOmMod
§
Pubblicato: 21/03/2015

Well, maybe someday :-)

§
Pubblicato: 21/03/2015

oh.. then do you think i could just make the comments load instantly somehow? it would be the best solution. if this widget/comments render or something is what they are loaded from, there should be something about this delayed loading or what too right?

wOxxOmMod
§
Pubblicato: 21/03/2015

I can't say right away because I don't know. What I know is that google's code is very complex and nearly impossible to hack due to obsfuscation.

§
Pubblicato: 22/03/2015
Modificato: 22/03/2015

can you tell me what these are supposed to do?
window.location.search.length
and
window.location.hash.length

they are right next to the comment render url, in the same function

wOxxOmMod
§
Pubblicato: 22/03/2015

It would require a lot of debugging and mind boggling deciphering of the obfuscated google's code to tell how exactly they use it. The discussion became non-practical, count me out.

§
Pubblicato: 23/03/2015

so you wont help... but what if it would be easy to figure out? since the only thing that behaves like that is the comment frame that loads only when you scroll there..
and it wouldnt even be necessary to find that, if i could have the frame resize itself

§
Pubblicato: 23/03/2015
Modificato: 24/03/2015

could you at least tell me how to make* a button inside the frame resize it?
so if i clicked more comments, it would add to the height

wOxxOmMod
§
Pubblicato: 23/03/2015

could you at least tell me how to a button inside the frame resize it?

It can't be helped. The document inside the frame can't influence the frame container. I'm tired of repeating the same thing. I'll ignore this thread from now on.

§
Pubblicato: 24/03/2015
Modificato: 24/03/2015

WAIT
i asked about this on stack overflow.
http://stackoverflow.com/questions/29194898/how-to-make-a-frames-height-the-same-as-the-contents?noredirect=1#comment46602911_29194898
and on this site they linked: http://www.dyn-web.com/tutorials/iframes/height/
they did it just like i would need it. but i think "onload" means it would only change the height when the frame loads. but it should work otherwise too right? if nothing else can be done to optimize it somehow, cant the frame be made to check this every second or so?
this is all i need now

wOxxOmMod
§
Pubblicato: 24/03/2015
Modificato: 24/03/2015

I didn't know that, never worked with the damn frames.

You can use a timer to check it every second:

var interval = setInterval(function(){
  //do the voodoo magic
........................
........................
........................
  if (everythingIsDone) {
    clearInterval(interval);
  }
}, 1000);
§
Pubblicato: 25/03/2015

um.. sorry i just want to be sure.
so basically i just paste the two functions from that site inside your code where the comment is... but then the functions wont have the id of the frame, so, since the f variable refers to the frame, i would have to
write setIframeHeight(f) instead of setIframeHeight(this.id) right?...

wait im dumb as hell again. the two functions dont need to be in your code, only the calling of them, if im right. they should just be above it i think...

§
Pubblicato: 28/03/2015

could you confirm this? this is the last thing i need. everything works, now i just need the frame to resize itself

§
Pubblicato: 01/04/2015

soo... it would work like this right?:


function getDocHeight(doc) {
    doc = doc || document;
    var body = doc.body, html = doc.documentElement;
    var height = Math.max( body.scrollHeight, body.offsetHeight, 
        html.clientHeight, html.scrollHeight, html.offsetHeight );
    return height;
}

var interval = setInterval(function(){
  function setIframeHeight(id) {
    var ifrm = document.getElementById(id);
    var doc = ifrm.contentDocument? ifrm.contentDocument: 
        ifrm.contentWindow.document;
    ifrm.style.visibility = 'hidden';
    ifrm.style.height = "10px"; // reset to minimal height ...
    // IE opt. for bing/msn needs a bit added or scrollbar appears
    ifrm.style.height = getDocHeight( doc ) + 4 + "px";
    ifrm.style.visibility = 'visible';
}

........................
........................
........................
  if (everythingIsDone) {
    clearInterval(interval);
  }
}, 1000);

or instead of pasting the function itself there, shouldnt it only be called? .
i really dont know much about javascript.

§
Pubblicato: 01/04/2015

oh... sorry.
i would need "setIframeHeight(this.id)" there, when called from the frame or something right? and the function declaration or what its called before somewhere...
but since the frame was created with the "f" variable being assigned to it or something, it should be "setIframeHeight(f)" right?
since it was created like this: var f = document.createElement('iframe');

§
Pubblicato: 20/04/2015
Modificato: 20/04/2015

sorry, i thought that would be the last time i bother you, but i STILL couldnt solve the problem. i learned about Same Origin policy, and other crap which made me totally unable to solve this really simple problem of resizing the frame...
i found some codes though for cross-domain communication, so the iframe's content could send the height of its body or anything to the domain that has the iframe on the page...
the code doesnt work for some reason though. i still use firefox 3,6,10, but it SHOULD work, since the postmessage is said to be working from firefox3.
could you tell me if you see anything wrong by quickly looking at it?

javascript inserted in the content page of iframe:



script inserted in the page the iframe is on (watch page)



and iframe code thing inserted on the page that should have the iframe (watch page)




the alert things are there so i see when the scripts run or not.
this would be the last thing i need... still.

Pubblica risposta

Accedi per pubblicare una risposta.