Skip to main content

Notice

Please note that most of the software linked on this forum is likely to be safe to use. If you are unsure, feel free to ask in the relevant topics, or send a private message to an administrator or moderator. To help curb the problems of false positives, or in the event that you do find actual malware, you can contribute through the article linked here.
Topic: JScript Panel script discussion/help (Read 287903 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

Re: JScript Panel script discussion/help

Reply #675
What do you mean by "Nothing appears to happen"? Is it that the added track is ignored, or on_queue_changed callbacks are not called?
Exactly what I said. Nothing "appears" to happen. ;) Turns out everything actually was happening, my playlist just isn't showing the queued status of items. Got to be related to the breaking changes. I fixed the errors, but something still isn't right I guess.

Quote
PS: Didn't have a chance to visit Austin (or Texas for that matter) yet, but now I'll have one more excuse to rectify that =)
Do it! The music is great, the beer is cheap, and the women are gorgeous. You basically can't go wrong.

Re: JScript Panel script discussion/help

Reply #676
help.
I have LastFm HTML code
Code: [Select]
<li class="metadata-item metadata-item--limit-width other-releases">	
  h2 class="metadata-title">Also featured on</h2>
    <a href="/music/John+Lennon/The+John+Lennon+Collection" title="The John Lennon Collection"><img src="https://lastfm-img2.akamaized.net/i/u/avatar42s/59ecaa8fd6474c48b04cc537a0d9e508.jpg" alt="The John Lennon Collection" /></a>
   <a href="/music/John+Lennon/Lennon" title="Lennon"><img src="https://lastfm-img2.akamaized.net/i/u/avatar42s/937195d43be848959662ad9b615ef1c1.jpg" alt="Lennon" /></a>
   <a href="/music/John+Lennon/Lennon+Legend+-+The+Very+Best+Of+John+Lennon" title="Lennon Legend - The Very Best Of John Lennon"><img src="https://lastfm-img2.akamaized.net/i/u/avatar42s/686afc08c3a94049a235314603e62fe6.jpg" alt="Lennon Legend - The Very Best Of John Lennon" /></a>
   <div class="additional-release-count">
      <a href="/music/John+Lennon/_/Instant+Karma!/+albums"><span class="release-count">+5</span> other releases</a>
    </div>
 </li>
if i I want to get "Also featured on" , I do
Code: [Select]
                var h2 = div.getElementsByTagName("h2");	
                for (i = 0; i < h2.length; i++) {
                    if (h2[i].className == "metadata-title") {
                        t = h2[i].innerHTML;
                        break;
                    }
                }
How I can get (title or alt):
"The John Lennon Collection"
"Lennon"
and
"Lennon Legend - The Very Best Of John Lennon"



UR5EQF. Ukraine


Re: JScript Panel script discussion/help

Reply #678
OMG, I'm lost. What are you guys talking about? Is this code for the JScript panel?

if i I want to get "Also featured on" , I do
Code: [Select]
                var h2 = div.getElementsByTagName("h2");	
                for (i = 0; i < h2.length; i++) {
                    if (h2[i].className == "metadata-title") {
                        t = h2[i].innerHTML;
                        break;
                    }
                }

https://jsfiddle.net/p76j7Lb4/
I'm late

Re: JScript Panel script discussion/help

Reply #679
It is an extract from his script where  he is asking how to parse the html to get the values he wants to use.
My fiddle is just pointing out how to get the values.

Re: JScript Panel script discussion/help

Reply #680
I see the logic of the script, but how do you reference an HTML element in JScript panel? At least I'm guessing the div object is one. I'm still pretty alien to HTML, as I thought it was useless for JScript panel,
I'm late

Re: JScript Panel script discussion/help

Reply #681
I see the logic of the script, but how do you reference an HTML element in JScript panel? At least I'm guessing the div object is one. I'm still pretty alien to HTML, as I thought it was useless for JScript panel,
His script is making an AJAX call to a webpage and then attempting to parse the HTML object he gets back to display the text in his theme somewhere. He's (sadly) not manipulating or displaying the HTML directly.

Re: JScript Panel script discussion/help

Reply #682
Have mercy for a non-developer, simple foobar2000 user. Learning to work with the interfaces and callbacks provided in the component documentation I was able to do wonderful things that were science fiction to me, only one year ago, but you guys are from another planet. What is an AJAX call, now?
Alright, I googled it: it's a jQuey method. So, not only HTML, but jQuery is also available in a non-browser environment such as JScript panel?
I really thought all I needed, besides the basics of jscript, was in the component docs. I'm clearly missing some big part of it.
Please enlighten me.
I'm late

Re: JScript Panel script discussion/help

Reply #683
zeremy, thank for the fact that you always help.

OMG, I'm lost. What are you guys talking about? Is this code for the JScript panel?

Code: [Select]
                var h2 = div.getElementsByTagName("h2");	
                for (i = 0; i < h2.length; i++) {
                    if (h2[i].className == "metadata-title") {
                        t = h2[i].innerHTML;
                        break;
                    }
                }
davideleo,
this code for foo_jscript_panel or foo_uie_wsh_panel_mod.
See my topic: Biography Text, Album Info, Picture. www.last.fm
UR5EQF. Ukraine

Re: JScript Panel script discussion/help

Reply #684
davideleo,
this code for foo_jscript_panel or foo_uie_wsh_panel_mod.
See my topic: Biography Text, Album Info, Picture. www.last.fm

Ok, thanks. I must admit I never checked your script. If this is an excerpt from it, I'd better download it and have a look at the whole code. Be prepared for more questions  ;)
I'm late

Re: JScript Panel script discussion/help

Reply #685
for example, we got a review of the track
UR5EQF. Ukraine

Re: JScript Panel script discussion/help

Reply #686
I've been modifying an old marc2003 code I had in order for it to fit my setup, and my problem is the elapsed playback time (%playback_time% /") only updates when I refresh the panel (so for example play/pause the song). It drives me nuts, if anyone has any idea on how to fix it, please:

Code: [Select]
// ==PREPROCESSOR==
// @name "track info + seekbar + buttons"
// @author "marc2003"
// @import "%fb2k_profile_path%js_marc2003\js\lodash.min.js"
// @import "%fb2k_profile_path%js_marc2003\js\helpers.js"
// @import "%fb2k_profile_path%js_marc2003\js\panel.js"
// @import "%fb2k_profile_path%js_marc2003\js\seekbar.js"
// ==/PREPROCESSOR==

//note the buttons are white and you'd have to edit the images to change them...
var colours = {
background : _.RGB(255, 255, 255),
title : _.RGB(60, 60, 60),
artist : _.RGB(80, 80, 80),
time : _.RGB(80, 80, 80),
};

//////////////////////////////////////////////////////////////

var panel = new _.panel("track info + seekbar + buttons");
var seekbar = new _.seekbar(60, 5, 0, 20);
var buttons = new _.buttons();
var img = null;
on_playback_new_track();

buttons.update = function () {
var y = _.round((panel.h - 36) / 2);
}

function on_size() {
panel.size();
seekbar.x = panel.h + 310
seekbar.w = panel.w - panel.h - 710;
seekbar.y = (panel.h - 20) / 2;
buttons.update();
}

function on_paint(gr) {
if (fb.IsPlaying) {
img && _.drawImage(gr, img, 0, 0, panel.h, panel.h, image.centre);
        gr.GdiDrawText(_.tfe("%title%"), gdi.Font("Helvetica Bold", 16), colours.title, 82, -1, 500, 40, LEFT);
            gr.GdiDrawText(_.tfe("%artist%"), gdi.Font("Helvetica Light", 16), colours.artist, 82, 20, 500, 30, LEFT);
            gr.GdiDrawText(_.tfe("%playback_time% /"), gdi.Font("Helvetica Light", 16), colours.time, 82, 43, 110, LEFT);
gr.GdiDrawText(_.tfe("%length%"), gdi.Font("Helvetica Light", 16), colours.time, 125, 0, 60, 107, LEFT);
;
}
}

function on_playback_new_track() {
var metadb = fb.GetNowPlaying();
if (!metadb)
return;
_.dispose(img);
img = utils.GetAlbumArtV2(metadb, 0);
window.Repaint();
}

function on_playback_edited() {
window.Repaint();
}

function on_playback_seek() {
seekbar.playback_seek();
}

function on_playback_stop() {
buttons.update();
window.Repaint();
}

function on_playback_pause() {
buttons.update();
window.Repaint();
}

function on_playback_starting() {
buttons.update();
window.Repaint();
}

function on_mouse_wheel(s) {
buttons.leave();
}

function on_mouse_move(x, y) {
if (buttons.move(x, y))
return;
seekbar.move(x, y);
}

function on_mouse_leave() {
buttons.leave();
}

function on_mouse_lbtn_down(x, y) {
seekbar.lbtn_down(x, y);
}

function on_mouse_lbtn_up(x, y) {
if (buttons.lbtn_up(x, y))
return;
if (seekbar.lbtn_up(x, y))
return;
fb.RunMainMenuCommand("View/Show now playing in playlist");
}

function on_mouse_rbtn_up(x, y) {
return panel.rbtn_up(x, y);
}

Re: JScript Panel script discussion/help

Reply #687
Have mercy for a non-developer, simple foobar2000 user. Learning to work with the interfaces and callbacks provided in the component documentation I was able to do wonderful things that were science fiction to me, only one year ago, but you guys are from another planet. What is an AJAX call, now?
Alright, I googled it: it's a jQuey method. So, not only HTML, but jQuery is also available in a non-browser environment such as JScript panel?
I really thought all I needed, besides the basics of jscript, was in the component docs. I'm clearly missing some big part of it.
Please enlighten me.

JScript panel is not a browser and you can't import jQuery, but it is possible to import (via ==PREPROCESSOR==)  some JavaScript utility libraries like :
https://lodash.com/
http://underscorejs.org/

As for AJAX , MordredKLB was referring to AJAX = Asynchronous JavaScript And XML that is possible by using ActiveX object. (Microsoft.XMLHTTP)https://www.w3schools.com/xml/ajax_xmlhttprequest_create.asp

The possibility to use ActiveX objects is documented in the wiki.
https://github.com/marc2k3/foo_jscript_panel/wiki

A few other ActiveX objects (not limited to) that you may find in other jScript panel scripts are :
Scripting.FileSystemObject
WScript.Shell
Shell.Application

They are loaded in the script  (e.g for WScript.Shell)
var WshShell = new ActiveXObject("WScript.Shell");

Study the scripts from the major contributors  and you will discover them and find out how to use them.
 

Re: JScript Panel script discussion/help

Reply #688
my problem is the elapsed playback time (%playback_time% /") only updates when I refresh the panel

may be add
function on_playback_time(time){}
UR5EQF. Ukraine

Re: JScript Panel script discussion/help

Reply #689
I've been modifying an old marc2003 code I had in order for it to fit my setup, and my problem is the elapsed playback time (%playback_time% /") only updates when I refresh the panel (so for example play/pause the song).

Try:
           if (fb.PlaybackLength > 0) {
                   gr.GdiDrawText(_.tfe("%playback_time% /"), gdi.Font("Helvetica Light", 16), colours.time, 82, 43, 110, LEFT);
           }


Re: JScript Panel script discussion/help

Reply #690
may be add
function on_playback_time(time){}
Yeah, you should be able add that callback and throw a window.Repaint() in there and it should solve your problem. Like so:

Code: [Select]
function on_playback_time(time){
    window.Repaint();
}

Re: JScript Panel script discussion/help

Reply #691
JScript panel is not a browser and you can't import jQuery, but it is possible to import (via ==PREPROCESSOR==)  some JavaScript utility libraries like :
https://lodash.com/
http://underscorejs.org/

As for AJAX , MordredKLB was referring to AJAX = Asynchronous JavaScript And XML that is possible by using ActiveX object. (Microsoft.XMLHTTP)https://www.w3schools.com/xml/ajax_xmlhttprequest_create.asp

The possibility to use ActiveX objects is documented in the wiki.
https://github.com/marc2k3/foo_jscript_panel/wiki

Thanks zeremy, now it is a bit clearer. I'm aware of the possibility to use ActiveXObjects and I've been using it myself in some scripts. Nevertheless, it's a very wide topic and I don't really know where to look for references. I've learned to use some properties and methods of the Scripting.FileSystemObject and of the WScript.Shell, only because I've seen it done in other people's scripts, but the Microsoft.XMLHTTP is totally new to me (I guess I will find an example in kgena_ua's script). Is there some online resource with a guide to ActiveXObjects? I usually end up on some microsoft doc page when I google, but they're nothing like a guide, they're basically a brief reference for the initiate.
Same thing for the libraries: I've been using the lodash library because I've seen examples in marc2000's scripts (and because it comes bundled with the sample docs of the component), but where do you learn about libraries such as the underscorjs? If I were to look for it myself, I'd be lost (thanks for the link BTW).
I'm late

Re: JScript Panel script discussion/help

Reply #692
As for AJAX , MordredKLB was referring to AJAX = Asynchronous JavaScript And XML that is possible by using ActiveX object. (Microsoft.XMLHTTP)https://www.w3schools.com/xml/ajax_xmlhttprequest_create.asp

So, let me get this straight: are all the methods of the XMLHttpRequest object listed in the w3schools AJAX chapter, available in JScript panel as methods of the Microsoft.XMLHTTP object?
I'm late

Re: JScript Panel script discussion/help

Reply #693
davideleo: I won't speak to ActiveX, but there's a whole world of libraries that Javascript developers are typically familiar with which the average person will never need to know about. Libraries like lodash and underscore are pretty common utility libraries that add extra functionality which make working with certain objects/data easier. The thing you need to be aware of is that EVERY javascript library (whether for the browser or JScript, etc.) isn't adding any new building blocks, just arranging them in ways that make things more convenient to use. This is fundamentally different than plugins for foobar or .DLLs for a c++ project.

For clarification, lodash/_ have a _.first(array, n) method which allow you to get the first n values of an array. There's no new functionality here, you could write it yourself in javascript just as easily as:
Code: [Select]
function first(array, n) {
    return array.slice(0, n);
}

That's why in my estimation js libraries are almost always overkill for JScript panels. In that lodash example there are 100+ other new methods, 99% of which you aren't going to use. Figure out what you want to do, see if somebody is doing it in a library already, and then rip off their code. :)

My theme is a massive 8k line beast. There is some functionality I wanted to implement that requires methods available in ES6 (a newer version of javascript than JScript provides). Specifically, I wanted to find keys matching a certain value in an array of JSON objects. ES6 has an array.find, but it doesn't work in JScript. Because I knew the method existed, I looked it up on MDN (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find) and if you scroll down you'll see a Polyfill. That's a piece of code that allows older browsers to implement the new functionality. I just copied that polyfill to my code, and voilá! array.find now works for me.

The JS ecosystem is vast, and ever changing. Unfortunately most of it has moved on from the IE9 browser that JScript implements. Rather than trying to learn it all (and particularly a version 7 years old), your best bet is to google around and ask in here.

Re: JScript Panel script discussion/help

Reply #694
Additionally, looking for a way to have a different image on hover for these buttons:
Code: [Select]
// ==PREPROCESSOR==
// @name "Playback Buttons"
// @author "marc2003"
// @import "%fb2k_profile_path%js_marc2003\js\lodash.min.js"
// @import "%fb2k_profile_path%js_marc2003\js\helpers.js"
// @import "%fb2k_profile_path%js_marc2003\js\panel.js"
// ==/PREPROCESSOR==

var panel = new _.panel("Playback Buttons", ["custom_background"]);
var buttons = new _.buttons();
var bs = 27;

buttons.update = function () {
this.buttons.previous = new _.button(0, 0, bs, bs, {normal : "buttons\\track_previous.png"}, function () { fb.Prev(); }, "");
    this.buttons.play = new _.button(30, 0, bs, bs, {normal : !fb.IsPlaying || fb.IsPaused ? "buttons\\play.png" : "buttons\\pause.png"}, function () { fb.PlayOrPause(); }, !fb.IsPlaying || fb.IsPaused ? "" : "");
this.buttons.next = new _.button(60, 0, bs, bs, {normal : "buttons\\track_next.png"}, function () { fb.Next(); }, "");
}

function on_size() {
panel.size();
buttons.update();
}

function on_paint(gr) {
panel.paint(gr);
buttons.paint(gr);
}

function on_playback_stop() {
buttons.update();
window.Repaint();
}

function on_playback_pause() {
buttons.update();
window.Repaint();
}

function on_playback_starting() {
buttons.update();
window.Repaint();
}

function on_mouse_move(x, y) {
buttons.move(x, y);
}

function on_mouse_leave() {
buttons.leave();
}

function on_mouse_lbtn_up(x, y) {
buttons.lbtn_up(x, y);
}

function on_mouse_rbtn_up(x, y) {
return panel.rbtn_up(x, y);
}

I've been modifying an old marc2003 code I had in order for it to fit my setup, and my problem is the elapsed playback time (%playback_time% /") only updates when I refresh the panel (so for example play/pause the song).

Try:
           if (fb.PlaybackLength > 0) {
                   gr.GdiDrawText(_.tfe("%playback_time% /"), gdi.Font("Helvetica Light", 16), colours.time, 82, 43, 110, LEFT);
           }



Thanks but it doesn't work. It displays it, but still doesn't refresh.

Re: JScript Panel script discussion/help

Reply #695
I've been modifying an old marc2003 code I had in order for it to fit my setup, and my problem is the elapsed playback time (%playback_time% /") only updates when I refresh the panel (so for example play/pause the song). It drives me nuts, if anyone has any idea on how to fix it, please:

Code: [Select]
            gr.GdiDrawText(_.tfe("%playback_time% /"), gdi.Font("Helvetica Light", 16), colours.time, 82, 43, 110, LEFT);

You're missing a coordinate in that line. Unsure if that would break stuff, but it's possible.

Re: JScript Panel script discussion/help

Reply #696
Thanks but it doesn't work. It displays it, but still doesn't refresh.
Did you see my post with the on_playback_time code? Without that callback it's never going to update unless you manually draw in a loop (which would be REALLY dumb).

Re: JScript Panel script discussion/help

Reply #697
As for AJAX , MordredKLB was referring to AJAX = Asynchronous JavaScript And XML that is possible by using ActiveX object. (Microsoft.XMLHTTP)https://www.w3schools.com/xml/ajax_xmlhttprequest_create.asp

So, let me get this straight: are all the methods of the XMLHttpRequest object listed in the w3schools AJAX chapter, available in JScript panel as methods of the Microsoft.XMLHTTP object?

Here is a link for the basics.
https://developer.mozilla.org/en-US/docs/Web/Guide/AJAX/Getting_Started

Re: JScript Panel script discussion/help

Reply #698
Thanks but it doesn't work. It displays it, but still doesn't refresh.
Did you see my post with the on_playback_time code? Without that callback it's never going to update unless you manually draw in a loop (which would be REALLY dumb).

I'm also using a script based on marc2003's samples, but it doesn't call on_playback_time anywhere. (!)

My elapsed time code is in an on_paint function which came from the Seekbar sample. It turns out that Seekbar.js continually checks fb.IsPlaying and calls for a refresh if it is, obviating the use of on_playback_time. I wondered what I was doing right....

@firewater   Sorry for wasting your time.

Re: JScript Panel script discussion/help

Reply #699
My elapsed time code is in an on_paint function which came from the Seekbar sample. It turns out that Seekbar.js continually checks fb.IsPlaying and calls for a refresh if it is, obviating the use of on_playback_time. I wondered what I was doing right....
I haven't looked at that code, but I assume it was doing something similar to:
Code: [Select]
setInterval(function () {
    if (fb.IsPlaying) window.Repaint();
},1000);
That's fine and will obviously work, but the callback is a much cleaner and more accurate way to do it and will have less wasted repaints (which are probably trivial in most cases/themes, but a full repaint for me can take 30-40ms).