Скрипты для foo_uie_wsh_panel_mod

Список разделов foobar2000 Секреты foobar2000

Описание: Кнопочки, конфиги, секреты, советы.

Сообщение #1361 seriousstas » 14.11.2016, 15:06

kgena_ua
seriousstas, по времени таймера. Мне главное выцепить первую картинку.
По идее все так и должно быть , но я парочку раз словил то ,о чем писал.
По on_mouse_wheel мотается 4-е картинки из 5-ти . В папке их 5-ть .
MC Web
У меня путаница с текстом биографии - остается от предыдущего исполнителя.
Это добавил ? :
b_text_array = [];
get_pic()
;
Посмотри этот вариант:
/viewtopic.php?p=62761#p62761
Там почти без изменений(от оригинала) - никакой путаницы ничего не остается(он и не может тк сразу затирается) . Текст залетает мгновенно и все грузит.
(или скажи ,как её вызвать) пробую сейчас снова и на радио и на треках и все ок.
seriousstas
Откуда: Украина , Ивано-Франковск
Репутация: 110
С нами: 9 лет 2 месяца

Сообщение #1362 MC Web » 14.11.2016, 15:24

seriousstas:Это добавил ? :
Код: Выделить всё
    b_text_array = [];
    get_pic()
Не было, сейчас добавил. По загрузке текста, стали вообще тормоза.
У меня без добавления b_text_array = [];, только перенос get_text(); что сюда
Код: Выделить всё
if (found > 0) get_files_if_loaded(p);
              get_text();
            }
        }     
    }     
}
что сюда
Код: Выделить всё
if (found > 0) get_files_if_loaded(p);
            }
        }     
                get_text();
    }     
}
оба варианта работают нормально. Текст загружается быстро, вместе с картинкой, на плейлисте с EX.
MC Web
Репутация: 248
С нами: 10 лет 8 месяцев

Сообщение #1363 kgena_ua » 14.11.2016, 15:32

seriousstas,
1. по ограничению кол-ва символов в имени - больше 210 ругается.
режем до 200.
Код: Выделить всё
    if (!n) return;
    return n.replace(/[^a-zA-Z0-9а-яА-Я\s-&\.]/g,'').replace(/^\s+|\s+$/g,"").substr(0,200);

2.
seriousstas:По on_mouse_wheel мотается 4-е картинки из 5-ти . В папке их 5-ть .
Не знаю как это у Вас получается. при вращении колеса мыши срабатывает функция
Код: Выделить всё
function get_files_from_dir(p) {
    if (!artist) return;
    files = utils.Glob(p + "\\" + artist + "*" + p_a[select_p_a] + ".jpg").toArray();
   
    if (files.length > images.length){
        images = [];
       
        for (var i = 0; i < files.length; i += 1) {
            try {
                images.push(resize_image(gdi.Image(files[i])));
            } catch(e) {}
        }
    }
}
у меня постоянно выводится files.length и images.length. Да может быть, что images.length = 3 при кол-ве файлов в папке 5, но при первой прокрутке колеса images.length = 5.
А по времени, я наблюдал (не дома првда) файлы заходили почти минуту.
kgena_ua M
Аватара
Откуда: Украина, Днепр
Репутация: 504
С нами: 11 лет

Сообщение #1364 MC Web » 14.11.2016, 15:34

WSH Biography Text & Picture Last.fm_rus (10.11.2016)
Код: Выделить всё
// ==PREPROCESSOR==
// @name "Biography Text && Picture. www.last.fm"
// @author "kgena_ua"
// @version "10112016"
// @feature "v1.4"
// @feature "watch-metadb"
// ==/PREPROCESSOR==

function RGB(r,g,b) { return (0xff000000|(r<<16)|(g<<8)|(b)); }
function RGBA(r,g,b,a) { return ((a << 24) | (r << 16) | (g << 8) | (b)); }
function getRed(color) {return ((color >> 16) & 0xff);};
function getGreen(color) {return ((color >> 8) & 0xff);};
function getBlue(color) {return (color & 0xff);};

DT_LEFT = 0x00000000;
DT_RIGHT = 0x00000002;
DT_CENTER = 0x00000001;
DT_VCENTER = 0x00000004;
DT_SINGLELINE = 0x00000020;
DT_WORD_ELLIPSIS = 0x00040000;
DT_WORDBREAK = 0x00000010;
DT_CALCRECT = 0x00000400;
DT_NOPREFIX = 0x00000800;

MF_ENABLED = 0x00000000;   
MF_GRAYED = 0x00000001;   
MF_SEPARATOR = 0x00000800;

var ww = 200, wh = 200;

var font_name_a = window.GetProperty(" font name: artist", "Verdan");
var font_name_b = window.GetProperty(" font name: biography", "Arial");
var font_size_a_d = window.GetProperty(" font size: artist (delta)", 4);
var font_size_b = window.GetProperty(" font size: biography", 12);
var a_font_style = window.GetProperty(" font style: artist", 2);
var b_font_style = window.GetProperty(" font style: biography", 0);
var min_font_size = 12;
var max_font_size = 16;

var a_font, b_font;
get_font();

function get_font(){
    a_font = gdi.Font(font_name_a, font_size_b + font_size_a_d, a_font_style);
    b_font = gdi.Font(font_name_b, font_size_b, b_font_style);
}   
/*
ColorTypeCUI = {
    text: 0,
    selection_text: 1,
    inactive_selection_text: 2,
    background: 3,
    selection_background: 4,
    inactive_selection_background: 5,
    active_item_frame: 6
};

function get_color(){   
    bgcolor = window.GetColorCUI(ColorTypeCUI.background);
    a_color = window.GetColorCUI(ColorTypeCUI.text);
    b_color = window.GetColorCUI(ColorTypeCUI.inactive_selection_text);
    window.Repaint();
}

get_color();

function on_colors_changed(){
    get_color();
}
*/

var bgcolor = RGB(19,30,38);    // RGB(31,41,48);
var a_color = RGB(128,192,255); // RGB(220,220,220);
var b_color = RGB(192,192,192); // RGB(255,255,230);

var fso = new ActiveXObject("Scripting.FileSystemObject");

var tmp_b_path = fb.ProfilePath + "\\tmp_Biography\\";
if (!fso.FolderExists(tmp_b_path)) {fso.CreateFolder(tmp_b_path)};

var script_path = tmp_b_path + "_download\\";
if (!fso.FolderExists(script_path)) {fso.CreateFolder(script_path)};
if (!fso.FileExists(script_path + "download.vbs")) {create_download_file()};

var doc = new ActiveXObject("htmlfile");
var WshShell = new ActiveXObject("WScript.Shell");
var vbs = "cscript //nologo \"" + script_path + "download.vbs\"";

var default_img_path = window.GetProperty(" default img path",".\\tmp_Biography\\_download\\nocover.png");
var default_img = window.GetProperty(" default img", false);
var default_img_transparent = window.GetProperty(" default img transparent (0-255)", 255);

load_last_fm_logo();
var logo_img = gdi.Image(script_path + "footer_logo.png");

var artist, old_artist;
var path, directory_path;

function clean_name(n) {
    if (!n) return;
    return n.replace(/[^a-zA-Z0-9а-яА-Я\s-&\.]/g,'').replace(/^\s+|\s+$/g,"");
}

function artist_folder_path(n) {
    return tmp_b_path + n;
}

function check_folder(n) {
    if(!fso.FolderExists(n)) {fso.CreateFolder(n)};
}

String.prototype.repeat = function(n) {
    return new Array(n + 1).join(this);
}

window.SetProperty(" - user", "");
if (window.GetProperty(" - user") != "" ) window.SetProperty(" - user", "");
window.SetProperty("-".repeat(50), "");
if (window.GetProperty("-".repeat(50)) != "" ) window.SetProperty("-".repeat(50), "");

var g_img = null;
var p_margin = window.GetProperty(" margin: picture", 0);
var align_mode_a = new Array("Подогнать", "Подогнать сверху - по центру", "Подогнать сверху - слева", "По центру", "По центру - сверху", "Растянуть");
var align_mode = window.GetProperty("align mode", 0);
var selected = 0;
var files = [];
var images = [];
var save_images = window.GetProperty("save images", false);
var limit = window.GetProperty(" download limit",5);
var cycle = window.GetProperty("auto cycle (sec)", 0);
if (cycle > 0) set_cycle_timer();
var fader = 255;
var fade_effect = window.GetProperty("fade effect", false);
var fade_step = window.GetProperty("fade step", 25);
var on_pic = false;

var download_quality = window.GetProperty("download quality", 1);
var quality = [
    [ "низкое", "avatar170s" , "300"],
    [ "среднее", "300x300" , "300"],
    [ "высокое", "770x0" , ""]
];

var scrollbar = window.GetProperty(" scrollbar", true);
var scrollbar_w = window.GetProperty(" scrollbar width ", 4);
var scrollbar_k;
var sb_x = 0;
var sb_posy = 0;
var on_sb = false;
var on_sb_down = false;
var sb_color;

var b_file;
var bg_transparent = window.GetProperty(" bg transparent (0-255)", 200);
var t_margin = window.GetProperty(" margin: text", 10);
var txt_x = window.GetProperty("txt_x", window.Width / 2);
var old_txt_x = 0;
var txt_y = window.GetProperty("txt_y", window.Height / 2);
var delta_x, delta_y;
var a_x, a_y, b_x, b_y;
var text = "";
var text_not_found = new Array("\n\nНичего не найдено", "\n\nНичего не найдено");
var s_text = 0;
var a_text_row_height = 0;
var b_text_row_height = 0;
var b_text_rows = 0;
var b_text_visable_rows = 0;
var b_text_visable_height = 0;
var b_text_array = [];
var on_artist = false;
var on_text = false;
var on_text_down = false;
var refresh_txt = true;

var lang_query = new Array("", "ru/");
var lang_text = new Array("in", "ru");
var lang = window.GetProperty("lang", 0);

var select_p_a = window.GetProperty("pictures/albums", 0);
var p_a = new Array("images", "albums");

var panel_on = true;

var selection_mode = window.GetProperty("selection mode", 0);
var metadb;
on_item_focus_change();

function on_paint(gr){   
   !window.IsTransparent && gr.FillSolidRect(0, 0, ww, wh, bgcolor);
   
    draw_image(gr);

    if(set_cycle){   
        gr.FillSolidRect(0, 0, ww, wh, RGBA(getRed(bgcolor),getGreen(bgcolor),getBlue(bgcolor),bg_transparent));   
        var txt_cycle = cycle == 0 ? "Отключено" : cycle + " сек.";   
        set_cycle && gr.GdiDrawText("Зацикливание изображений \n" + txt_cycle, b_font, b_color, 0, 20, ww, wh, DT_CENTER | DT_WORD_ELLIPSIS );
    } else{   
        gr.FillSolidRect(txt_x, txt_y, ww - txt_x, wh - txt_y, RGBA(getRed(bgcolor),getGreen(bgcolor),getBlue(bgcolor),bg_transparent));   
    }   

    draw_scrollbar(gr);   
   
    gr.GdiDrawText( artist, a_font, RGB(0,0,0), a_x + 1, a_y + 2, ww - a_x - t_margin, wh, DT_CENTER | DT_WORD_ELLIPSIS | DT_NOPREFIX );   
    gr.GdiDrawText( artist, a_font, a_color, a_x, a_y, ww - a_x - t_margin, wh, DT_CENTER | DT_WORD_ELLIPSIS | DT_NOPREFIX );   

    for (var i = 0; i < b_text_visable_rows * 2; i += 2) {
        try {
            gr.GdiDrawText( b_text_array[i + s_text * 2].replace(/^\s+|\s+$/g, ""), b_font, RGB(0,0,0), b_x + 1, b_y + b_text_row_height * i / 2 + 2, ww, wh, DT_LEFT | DT_NOPREFIX );
            gr.GdiDrawText( b_text_array[i + s_text * 2].replace(/^\s+|\s+$/g, ""), b_font, b_color, b_x, b_y + b_text_row_height * i / 2 , ww, wh, DT_LEFT | DT_NOPREFIX );
        } catch(e) {}
    }

   // gr.GdiDrawText( "files " + files.length, gdi.Font("Arial",12, 0), b_color, 10, 0, ww, wh, DT_LEFT | DT_WORD_ELLIPSIS );
    //gr.GdiDrawText( "images " + images.length, gdi.Font("Arial",12, 0), b_color, 10, 20, ww, wh, DT_LEFT | DT_WORD_ELLIPSIS );
}

function draw_image(gr){
    if (g_img && images.length > 0){
        var size = calc_img_size(g_img);
        gr.DrawRect(size.x, size.y, size.width, size.height, 1, RGBA(getRed(bgcolor),getGreen(bgcolor),getBlue(bgcolor),fader));
        gr.DrawImage(g_img, size.x, size.y, size.width, size.height, size.cx, size.cy, size.cwidth, size.cheight, 0, fader);
    }
   
    if (logo_img && images.length == 0 && !default_img){
        gr.DrawImage(logo_img, 10, 10, logo_img.Width * 0.8, logo_img.Height * 0.8, 0, 0, logo_img.Width, logo_img.Height, 0, 100);         
    }

    if (images.length == 0 && default_img){
        try {
            nc_img = gdi.Image(default_img_path);
            var size = calc_img_size(nc_img);
            gr.DrawImage(nc_img, size.x, size.y, size.width, size.height, size.cx, size.cy, size.cwidth, size.cheight, 0, default_img_transparent);
        } catch(e) {};
    }
}

function draw_scrollbar(gr){
    scrollbar_h = b_text_rows > b_text_visable_rows ? b_text_visable_height * (b_text_visable_rows / b_text_rows) : 0;
    if (b_text_rows > b_text_visable_rows){ scrollbar_h = Math.max(5, scrollbar_h)}
    scrollbar_y = s_text > 0 ? s_text * scrollbar_k : 0;

    sb_x = ww - t_margin - scrollbar_w;
   
    sb_t = on_sb || on_sb_down ? 150 : 50;
    sb_color = RGBA(getRed(a_color), getGreen(a_color), getBlue(a_color), sb_t);
   
    scrollbar && gr.FillSolidRect(sb_x, b_y + scrollbar_y, scrollbar_w, scrollbar_h, sb_color);
}

function on_playlist_switch() {
    on_item_focus_change();
}

function on_playback_new_track() {
    on_item_focus_change();
}

function on_playback_dynamic_info_track() {
    on_item_focus_change();
}

function on_playback_stop() {
    on_item_focus_change();
}

function on_selection_changed(metadb) {
   on_item_focus_change();
}

function on_item_focus_change() {
    switch (selection_mode) {
    case 0:
        metadb = fb.IsPlaying ? fb.GetNowPlaying() : fb.GetFocusItem();   
        break;   
    case 1:   
       metadb = fb.GetFocusItem();
        break;   
    }   
    if (metadb) on_metadb_changed();   
}   

function Eval(field) {   
    if (!metadb) return;   
    path = fb.Titleformat("%path%").EvalWithMetadb(metadb);
    directory_path = fb.Titleformat("$directory_path(%path%)").EvalWithMetadb(metadb);
    return path.indexOf('://') > 0 ? fb.TitleFormat("[" + field + "]").Eval(true) : fb.TitleFormat("[" + field + "]").EvalWithMetadb(metadb);
}   

function on_metadb_changed() {
    if (!panel_on) return;
    if (!metadb) return;
//  artist = Eval("%artist%");
    artist = Eval("$upper([%artist%])");
    if (artist) {artist = clean_name(artist)} else {artist = ""};
    if (artist != old_artist){
        if (!save_images) del_folders(artist);
        get_pic();
//      get_text();   //////////////////////////
        old_artist = artist;
    }
}   

function get_pic() {
    images = [];
    files = [];
    selected = 0;
    g_img = null;
    window.Repaint();
   
    check_folder(artist_folder_path(artist));
    if (fso.FolderExists(artist_folder_path(artist))){
        get_files_from_dir(artist_folder_path(artist));
        if (!g_img && images.length > 0) {
            next_image(0);
        } else {
            get_lastFM_pic(artist_folder_path(artist));
        }
    }
}

function get_lastFM_pic(p){
    xmlhttp1 = new ActiveXObject("Microsoft.XMLHTTP");     
    url1 = ("http://www.last.fm/music/" + encodeURIComponent(artist) + "/+" + p_a[select_p_a]);     
    xmlhttp1.open("GET", url1, true);     
    xmlhttp1.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
    xmlhttp1.send(null);     
    xmlhttp1.onreadystatechange = function () {
        if (xmlhttp1.readyState == 4) {
            if (xmlhttp1.status == 200) {
                doc.open();     
                var div = doc.createElement("div");
                div.innerHTML = xmlhttp1.responsetext;
                var data = div.getElementsByTagName("img");
                var urls = [];
                for (i = 0; i < data.length; i++) {   
                    if (data[i].className == "image-list-image" && select_p_a == 0){       
                        if (data[i].src.indexOf("http://img2-ak.lst.fm/i/u/avatar170s") == 0 || data[i].src.indexOf("https://lastfm-img2.akamaized.net/i/u/avatar170s") == 0) {
                            urls.push(data[i].src.replace("avatar170s", quality[download_quality][1]));
                        }     
                    }   
//                    if (data[i].className == "album-grid-album-art" && select_p_a == 1){   
//                        if (data[i].src.indexOf("http://img2-ak.lst.fm/i/u/300") == 0 && data[i].src.indexOf("c6f59c1e5e7240a4c0d427abd71f3dbb") < 0) {                       
//                            urls.push(data[i].src.replace("300", quality[download_quality][2]))
                    if (data[i].className == "album-grid-album-art" && select_p_a == 1){
                        if ((data[i].src.indexOf("http://img2-ak.lst.fm/i/u/300") == 0 || data[i].src.indexOf("https://lastfm-img2.akamaized.net/i/u/300") == 0) && data[i].src.indexOf("c6f59c1e5e7240a4c0d427abd71f3dbb") < 0) {                       
                            urls.push(data[i].src.replace("300", quality[download_quality][2]))
                        }     
                    }       
                }
                var found = urls.length;
                for (i = 0; i < Math.min(urls.length, limit); i++) {     
                    file = "\"" + p + "\\" + artist + "_"  + i + "_" + p_a[select_p_a] + ".jpg" + "\"";     
                    WshShell.Run(vbs + " " + urls[i] + " " + file, false);
                }     
                doc.close();
                if (found > 0) get_files_if_loaded(p);
 //             get_text(); ////////////////////////
            }
        }     
                get_text();
    }     
}

function get_files_from_dir(p) {
    if (!artist) return;
    files = utils.Glob(p + "\\" + artist + "*" + p_a[select_p_a] + ".jpg").toArray();
   
    if (files.length > images.length){
        images = [];
       
        for (var i = 0; i < files.length; i += 1) {
            try {
                images.push(resize_image(gdi.Image(files[i])));
            } catch(e) {}
        }
    }
}

function next_image(d){
    fader = fade_effect ? 0 : 255;
    if (d < 0) {selected = selected <= 0 ? images.length - 1 : selected = selected - 1};
    if (d > 0) {selected = selected >= images.length - 1 ? 0 : selected = selected + 1};
    g_img = images[selected];
    if (g_img && fade_effect) fader_timer();
    window.Repaint();
}

function resize_image(img){
    if (!img) return;
   
    var scale_w = (window.Width - p_margin * 2) / img.Width;
    var scale_h = (window.Height - p_margin * 2) / img.Height;
    var scale = Math.min(scale_w, scale_h);
    var nww = img.Width * scale;
    var nwh = img.Height * scale

    var temp_bmp = gdi.CreateImage(nww, nwh);
    var temp_gr = temp_bmp.GetGraphics();
    temp_gr.SetSmoothingMode(2);
    temp_gr.SetInterpolationMode(7);
    temp_gr.DrawImage(img, 0, 0, nww, nwh, 0, 0, img.width, img.height);
    temp_bmp.ReleaseGraphics(temp_gr);
   
    CollectGarbage();
    return temp_bmp;
    temp_bmp.Dispose();
    temp_gr = null;
    temp_bmp = null;
}

function get_text() {
    s_text = 0;
    text = "";
    b_text_array = [];
    b_text_file = artist_folder_path(artist) + "\\" + artist + "_biography_" + lang_query[lang].replace(/\//g,'') + ".txt";
   
    refresh_txt = true;
   
    if (artist && fso.FileExists(b_text_file)){
        text = utils.ReadTextFile(b_text_file);
        get_b_text_array();
    } else{
        get_lastFM_b_text(b_text_file);
    }
}

function get_lastFM_b_text(p){
    xmlhttp2 = new ActiveXObject("Microsoft.XMLHTTP");
    url2 = ("http://www.last.fm/" + lang_query[lang] + "music/" + encodeURIComponent(artist) + "/+wiki");
    xmlhttp2.open("GET", url2, true);
    xmlhttp2.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
    xmlhttp2.send(null);
    xmlhttp2.onreadystatechange = function () {
        if (xmlhttp2.readyState == 4) {
            if (xmlhttp2.status == 200) {
                doc.open();
                var div = doc.createElement("div");
                div.innerHTML = xmlhttp2.responsetext;
                var data = div.getElementsByTagName("div");
                for (i = 0; i < data.length; i++) {
                    if (data[i].className == "wiki-content") {
                        text = strip_tags(data[i].innerHTML);
                        break;
                    }
                }
                doc.close();
            }
            if (text != "") save_biography_file(text, p);
            if (text == "") text = text_not_found[lang];
            get_b_text_array();
        }
    }
}

function strip_tags(t) {
    doc.open();
    var div = doc.createElement("div");
    div.innerHTML = t.replace(/<[Pp][^>]*>/g, "").replace(/<\/[Pp]>/g, "<br>").replace(/\n/g, "<br>");
    var text = div.innerText;
    doc.close();
    return text;
}

function get_b_text_array() {
    a_x = txt_x + t_margin;
    a_y = txt_y + t_margin;
 
    temp_bmp = gdi.CreateImage(1, 1);
    temp_gr = temp_bmp.GetGraphics();

    a_text_row_height = temp_gr.CalcTextHeight("text", a_font);
    b_text_row_height = temp_gr.CalcTextHeight("text", b_font);
   
    b_x = txt_x + t_margin;
    b_y = a_y + a_text_row_height + b_text_row_height;
   
    string_width = Math.max(ww - b_x - t_margin - scrollbar_w - 10, 0);

    if (Math.abs(txt_x - old_txt_x) > 5 || refresh_txt){
        b_text_array = [];
        if (text) b_text_array = temp_gr.EstimateLineWrap(text, b_font, string_width).toArray();
        old_txt_x = txt_x;
        refresh_txt = false;
    }
   
    b_text_rows = b_text_array.length / 2;

    b_text_visable_area = Math.floor(Math.max(0, window.Height - t_margin - b_y));
    b_text_visable_rows = Math.floor(b_text_visable_area / b_text_row_height);
    b_text_visable_height = b_text_visable_rows * b_text_row_height;


    if (b_text_visable_rows + s_text > b_text_rows && s_text > 0) {
        s_text = (b_text_rows - b_text_visable_rows);
    }
   
    scrollbar_k = b_text_visable_height / b_text_rows;
   
    temp_bmp.ReleaseGraphics(temp_gr);
    temp_bmp.Dispose();
    temp_gr = null;
    temp_bmp = null;

    window.Repaint();
}

function save_biography_file(t, p){
    if (!artist) return;
    try {
        file = fso.OpenTextFile( p, 2, true, -1)
        file.WriteLine(t);
        file.Close();
    } catch(e) {
        return;
    }
}

function on_mouse_rbtn_up (x, y){     
    var _menu = window.CreatePopupMenu();
   
    _menu.AppendMenuItem(MF_ENABLED, 10, "Английский язык");   
    _menu.AppendMenuItem(MF_ENABLED, 11, "Русский язык");   
    _menu.CheckMenuRadioItem(10, 11, lang + 10);         
    _menu.EnableMenuItem(lang + 10, 1);     

    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);   
    _menu.AppendMenuItem(MF_ENABLED, 12, "Предпочитать воспроизводимый");   
    _menu.AppendMenuItem(MF_ENABLED, 13, "Следовать за выбранным треком");   
    _menu.CheckMenuRadioItem(12, 13 , selection_mode + 12);   
    _menu.EnableMenuItem(selection_mode + 12, 1);
       
    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
    _menu.AppendMenuItem(MF_ENABLED, 14, "Фото исполнителя");   
    _menu.AppendMenuItem(MF_ENABLED, 15, "Обложка альбома");   
    _menu.CheckMenuRadioItem(14, 15 , select_p_a + 14);   
    _menu.EnableMenuItem(select_p_a + 14, 1);

    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);   
    IS_ARTIST = artist ? MF_ENABLED : MF_GRAYED;   
    _menu.AppendMenuItem(IS_ARTIST, 16, "Страничка исполнителя на Last.fm");   
   
    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
    _menu.AppendMenuItem(MF_ENABLED, 17, "Эффект плавного перехода");
    _menu.CheckMenuItem(17, fade_effect);

    _firstgroup = window.CreatePopupMenu();
    _firstgroup.AppendTo(_menu,MF_ENABLED,  "Выравнивание : " + align_mode_a[align_mode]);
   
    _firstgroup.AppendMenuItem(MF_ENABLED, 20, align_mode_a[0]);         
    _firstgroup.AppendMenuItem(MF_ENABLED, 21, align_mode_a[1]);
    _firstgroup.AppendMenuItem(MF_ENABLED, 22, align_mode_a[2]);
    _firstgroup.AppendMenuItem(MF_ENABLED, 23, align_mode_a[3]);
    _firstgroup.AppendMenuItem(MF_ENABLED, 24, align_mode_a[4]);
    _firstgroup.AppendMenuItem(MF_ENABLED, 25, align_mode_a[5]);
    _firstgroup.CheckMenuRadioItem(20, 25, align_mode + 20);
    _firstgroup.EnableMenuItem(align_mode + 20, 1);

    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
    _secondgroup = window.CreatePopupMenu();
    _secondgroup.AppendTo(_menu,MF_ENABLED,  "Качество изображения : " + quality[download_quality][0]);
   
    _secondgroup.AppendMenuItem(MF_ENABLED, 30, "Низкое");
    _secondgroup.AppendMenuItem(MF_ENABLED, 31, "Среднее");
    _secondgroup.AppendMenuItem(MF_ENABLED, 32, "Высокое");
    _secondgroup.CheckMenuRadioItem(30, 32, download_quality + 30);
    _secondgroup.EnableMenuItem(download_quality + 30, 1);

    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
    MF_STRING = images.length > 0 ? MF_ENABLED : MF_GRAYED;
    _menu.AppendMenuItem(MF_STRING, 40, "Копировать в папку с треком...");
    _menu.AppendMenuItem(MF_STRING, 50, "Открыть изображение");
   
    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
    _menu.AppendMenuItem(MF_ENABLED, 60, "Сохранять изображения и текст");
    _menu.CheckMenuItem(40, save_images);

//    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);   
//    _menu.AppendMenuItem(MF_ENABLED, 100, "Перезагрузить");   
    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);   
    _menu.AppendMenuItem(MF_ENABLED, 110, "Свойства WSH");   
    _menu.AppendMenuItem(MF_ENABLED, 120, "Настройки WSH...");

    ret = _menu.TrackPopupMenu(x,y);

    switch (ret) {
    case 10:
        lang = 0;
        window.SetProperty("lang", lang);
        get_text();
        break;
    case 11:
        lang = 1;
        window.SetProperty("lang", lang);
        get_text();
        break;
    case 12:
        selection_mode = 0;
        window.SetProperty("selection mode", selection_mode);
        on_item_focus_change();
        break;
    case 13:
        selection_mode = 1;
        window.SetProperty("selection mode", selection_mode);
        on_item_focus_change();
        break;
    case 14:
        select_p_a = 0;
        window.SetProperty("pictures/albums", select_p_a);
        get_pic();
        break;
    case 15:
        select_p_a = 1;
        window.SetProperty("pictures/albums", select_p_a);
        get_pic();
        break;
    case 16:
        WshShell.run("http://www.last.fm/" + lang_query[lang] + "music/" + encodeURIComponent(artist));
        break;
    case 17:
        window.SetProperty("fade effect", !fade_effect);
        fade_effect = window.GetProperty("fade effect");
        break;
    case 20:
    case 21:
    case 22:
    case 23:
    case 24:
    case 25:
        align_mode = ret - 20;
        window.SetProperty("align mode", align_mode);
        window.Repaint();
        break;
    case 30:
    case 31:
    case 32:   
        download_quality = ret - 30;
        window.SetProperty("download quality", download_quality);
        break;
    case 40:
        copy_files();
        break;
    case 50:
        try {
            if (images[selected]) WshShell.run( '"' + artist_folder_path(artist)+ "\\" + artist + "_"  + selected + "_" + p_a[select_p_a] + ".jpg" + '"' );
        } catch(e) {}
        break;
    case 60:
        window.SetProperty("Save images", !save_images);
        save_images = window.GetProperty("Save images");
        break;
//    case 100:
//        window.Reload();
//        break;
    case 110:
        window.ShowProperties();
        break;   
    case 120:
        window.ShowConfigure();   
        break;   
   }
    _menu.Dispose();   
    return true;   
}   

var timer;

function get_files_if_loaded(p){
    timer && window.ClearInterval(timer);
    timer = window.SetInterval(function() {
        get_files_from_dir(p);
        if (images.length > 0)  {
            next_image(0);
            window.ClearInterval(timer);
        }
    }, 500 );   // 500
}

var set_cycle = false;

function on_key_down(vkey) {
    if (vkey == 16){
        set_cycle = true;
        dis_set();
        window.Repaint();
    }
}

var cycle_timer, step = 0;

function set_cycle_timer(){
    cycle_timer && window.ClearInterval(cycle_timer);
    cycle_timer = window.SetInterval(function() {
        step =  set_cycle ? 0 : step + 1;
        if (cycle > 0 && step >= cycle){
            get_files_from_dir(artist_folder_path(artist));
            if (images.length > 1){
                next_image(1);
                step = 0;
            }
        }
        window.Repaint();
    }, 1000 );  // 1000
}

var dis_timer, dis = 0;

function dis_set(){
    dis = 0;
    dis_timer && window.ClearInterval(dis_timer);
    dis_timer = window.SetInterval(function() {
        if (set_cycle) {
            dis++;
            if(dis == 1) {
                set_cycle = false;
                if (cycle > 0) set_cycle_timer();
                if (cycle == 0) window.ClearInterval(cycle_timer);
                window.ClearInterval(dis_timer)
                window.Repaint();
            };
        }
    }, 1000 );  // 1000
}

var delay = false;

function fdelay(){
    var delay_timer = window.SetTimeout(function() {
        delay = false;
        window.ClearTimeout(delay_timer);
    }, 200);    // 200
}

var ftimer;

function fader_timer(){
    fader = 0;
    ftimer && window.ClearInterval(ftimer);
    ftimer = window.SetInterval(function() {
        fader = fader + fade_step;
        if (fader >= 255) {
            fader= 255;
            window.ClearInterval(ftimer);
        }
        window.Repaint();
    }, 42 );
}

function load_last_fm_logo(){
    if(!fso.FileExists(script_path + "footer_logo.png")) {
        var url = "http://www.last.fm/static/images/logo_beta.png?eb6d3ca20e73"
        var file = "\"" + script_path + "last_fm_logo.jpg" + "\"";
        WshShell.Run(vbs + " " + url + " " + file, false);
       
        var url = "http://static-web.last.fm/static/images/favicon.702b239b6194.ico"
        var file = "\"" + script_path + "last_fm_ico.ico" + "\"";
        WshShell.Run(vbs + " " + url + " " + file, false);

        var url = "http://static-web.last.fm/static/images/footer_logo.ddcfd65712a6.png"
        var file = "\"" + script_path + "footer_logo.png" + "\"";
        WshShell.Run(vbs + " " + url + " " + file, false);
    }
}

function create_download_file() {
    try {
        file = fso.CreateTextFile(script_path + "download.vbs" )
       
        var text =   
            "If (WScript.Arguments.Count <> 2) Then" + "\n\r" +   
            "   WScript.Quit" + "\n\r" +
            "End If" + "\n\r" + "\n\r" +   

            "url = WScript.Arguments(0)" + "\n\r" +   
            "file = WScript.Arguments(1)" + "\n\r"  + "\n\r" +   

            "Set objFSO = Createobject(" + '"Scripting.FileSystemObject"' + ")" + "\n\r" +   
            "If objFSO.Fileexists(file) Then" + "\n\r" +   
            "   Set objFSO = Nothing" + "\n\r" +
            "   WScript.Quit" + "\n\r" +
            "End If" + "\n\r" + "\n\r" +   

            "Set objXMLHTTP = CreateObject(" + '"MSXML2.XMLHTTP"' + ")" + "\n\r" +   
            "objXMLHTTP.open " + '"GET"' + ", url,false" + "\n\r" +   
            "objXMLHTTP.send()" + "\n\r" + "\n\r" +   

            "If objXMLHTTP.Status = 200 Then" + "\n\r" +   
            "   Set objADOStream = CreateObject(" + '"ADODB.Stream"' + ")" + "\n\r" +
            "   objADOStream.Open" + "\n\r" +
            "   objADOStream.Type = 1" + "\n\r" +
            "   objADOStream.Write objXMLHTTP.ResponseBody" + "\n\r" +
            "   objADOStream.Position = 0" + "\n\r" +
            "   objADOStream.SaveToFile file" + "\n\r" +
            "   objADOStream.Close" + "\n\r" +
            "   Set objADOStream = Nothing" + "\n\r" +
            "End If" + "\n\r" + "\n\r" +   

            "Set objFSO = Nothing" + "\n\r" +   
            "Set objXMLHTTP = Nothing"   
        ;

        file.WriteLine(text);
        file.Close();
    } catch(e) {};
}

function on_mouse_move(x, y) {
    window.SetCursor(32649);

    on_text = x >= txt_x && x < sb_x && y  >= txt_y ? true : false;
    on_sb =  x >= sb_x && x < ww && y >= txt_y && y < wh ? true : false;
    on_pic = !on_text && !on_sb ? true : false;

    if (on_text_down){
        txt_x = x - delta_x;
        txt_y = y - delta_y;

        txt_x = txt_x <= 0 ? 0 : txt_x >= ww - 50 ? ww - 50: txt_x;
        txt_y = txt_y <= 0 ? 0 : txt_y >= wh - (a_text_row_height + t_margin * 2) ? wh - (a_text_row_height + t_margin * 2) : txt_y;

        get_b_text_array();
    }

    if (on_sb_down && scrollbar && b_text_rows > b_text_visable_rows){
        sb_posy = y + delta_y;
        s_text = y + delta_y >= 0 ? y + delta_y <= (b_text_rows - b_text_visable_rows) * scrollbar_k ? Math.round(sb_posy / scrollbar_k) : b_text_rows - b_text_visable_rows : 0;
        //window.Repaint();
        window.RepaintRect(txt_x, txt_y, ww - txt_x, wh - txt_y);
    }
   
    window.RepaintRect(sb_x, txt_y, ww, wh);
}

function on_mouse_wheel(delta) {
    ShiftDown = utils.IsKeyPressed(0x10) ? true : false;
   
   if (ShiftDown) on_key_down();
   
    if (on_pic && !ShiftDown && !delay){
        get_files_from_dir(artist_folder_path(artist));
        if (files.length > 1){
            delay = true;
            fdelay();
            next_image(delta);
            if (cycle > 0) step = 0;
        }
    }
   
    if (on_text && !ShiftDown){
        if (b_text_rows > b_text_visable_rows){
            if (delta < 0) {s_text = b_text_rows - s_text <= b_text_visable_rows ? b_text_rows - b_text_visable_rows : s_text += 1}
            if (delta > 0) {s_text = s_text <= 0 ? 0 : s_text -= 1}
        }
        window.RepaintRect(txt_x, txt_y, ww - txt_x, wh - txt_y);
    }
   
    if (on_text && ShiftDown && !delay){
        delay = true;
        fdelay();
        if (delta < 0) {font_size_b = font_size_b <= min_font_size ? min_font_size : font_size_b - 2;};
        if (delta > 0) {font_size_b = font_size_b >= max_font_size ? max_font_size : font_size_b + 2;};
        window.SetProperty("font size: biography", font_size_b);
        get_font();
        refresh_txt = true;
        get_b_text_array();
    }

    if (set_cycle && on_pic) {
        if (delta < 0) {cycle = cycle <= 0 ? 0 : cycle - 5;};
        if (delta > 0) {cycle = cycle >= 60 ? 60 : cycle + 5;};
        window.SetProperty("auto cycle (sec)", cycle);
        window.Repaint();
    }
}

function on_mouse_lbtn_down(x,y){
    if (on_text){
        on_text_down = true;
        delta_x = x - txt_x;
        delta_y = y - txt_y;
    }
    if (on_sb){
        on_sb_down = true;
        sb_posy = s_text * scrollbar_k;
        delta_y = sb_posy - y;
    }
}

function on_mouse_lbtn_up(x,y){
    window.SetProperty("txt_x", txt_x);
    window.SetProperty("txt_y", txt_y);
    on_text_down = false;
    on_sb_down = false;
}

function on_mouse_lbtn_dblclk (x,y){
    if (on_text){
        lang = lang == 1 ? 0 : 1;
        window.SetProperty("lang", lang);
        get_text();
    }

    if (on_pic){
        select_p_a = select_p_a == 1 ? 0 : 1;
        window.SetProperty("pictures/albums", select_p_a);
        get_pic();
    }
}

function on_mouse_leave() {
    window.SetCursor(32512);
    on_sb = false;
    window.Repaint();
}

function on_size(){
    ww = window.Width;   
    wh = window.Height;
   
    txt_x = window.GetProperty("txt_x");
    txt_y = window.GetProperty("txt_y");

    txt_x = txt_x >= ww - 50 && txt_x >= 0 ? ww - 50 : txt_x;
    txt_y = txt_y >= wh - (a_text_row_height + t_margin * 2) && txt_y >= 0 ? wh - (a_text_row_height + t_margin * 2) : txt_y;
   
    refresh_txt = true;
    get_b_text_array();
}

function del_folders(n){
    var dir = fso.GetFolder(tmp_b_path);
    var e = new Enumerator( dir.SubFolders );
    try {
        for(; !e.atEnd(); e.moveNext() ) {
            var name = e.item().Name;
            if (name.indexOf("_download") < 0){
                if (name.indexOf(n) < 0){
                    fso.deleteFolder(tmp_b_path + name, true);
                }
            }   
        }
    } catch(e) {};
}

function calc_img_size(img){
    if(!img) return;
    var size = {x:0, y:0, width:0, height:0, cx:0, cy:0, cwidth:0, cheight:0};

    switch(align_mode) {   
   case 0: // adjust     
        var sw = ww / img.Width;
        var sh = wh / img.Height;
        var s = Math.min(sw, sh);
       
        var x = 0;
        var y = 0;
       
        if (sw > sh) x = (ww - img.Width * s) / 2;
        else if (sw < sh) y = (wh - img.height * s) / 2;

        var width = img.Width * s;
        var height = img.Height * s;
        var cx = 0;
        var cy = 0;
        var cwidth = img.Width;
        var cheight = img.Height;
      break;
       
    case 1: // adjust top - center
        var sw = ww / img.Width;
        var sh = wh / img.Height;
        var s = Math.min(sw, sh);

        var x = 0;
        if (sw > sh) x = (ww - img.Width * s) / 2;
        var y = 0;
        var width = img.Width * s;
        var height = img.Height * s;
        var cx = 0;
        var cy = 0;
        var cwidth = img.Width;
        var cheight = img.Height;
      break;
       
    case 2: // adjust top - left
        var sw = ww / img.Width;
        var sh = wh / img.Height;
        var s = Math.min(sw, sh);
       
        var x = 0;
        var y = 0;
        var width = img.Width * s;
        var height = img.Height * s;
        var cx = 0;
        var cy = 0;
        var cwidth = img.Width;
        var cheight = img.Height;
      break;

   case 3: // centre   
      var sr = img.Width / img.Height;   
      var dr = ww / wh;   
      if (sr < dr) {   
         var r = img.Width / ww;
         var cheight = wh * r;
         var cy = Math.round((img.Height - cheight) / 2);
         var cwidth = img.Width;
         var cx = 0;
      } else {   
         var r = img.Height / wh;
         var cwidth = ww * r;
         var cx = Math.round((img.Width - cwidth) / 2);
         var cheight = img.Height;
         var cy = 0;
      }   
        var x = 0;         
        var y = 0;         
        var width = ww;         
        var height = wh;         
      break;   
       
   case 4: // centre - top     
      var sr = img.Width / img.Height;   
      var dr = ww / wh;   
      if (sr < dr) {   
         var r = img.Width / ww;
         var cheight = wh * r;
         var cy = 0;
         var cwidth = img.Width;
         var cx = 0;
      } else {   
         var r = img.Height / wh;
         var cwidth = ww * r;
         var cx = Math.round((img.Width - cwidth) / 2);
         var cheight = img.Height;
         var cy = 0;
      }
        var x = 0;
        var y = 0;
        var width = ww;
        var height = wh;
      break;   
       
   case 5: // stretch     
        var x = 0;
        var y = 0;
        var width = ww;
        var height = wh;
        var cx = 0;
        var cy = 0;
        var cwidth = img.Width;
        var cheight = img.Height;
      break;   
    }
   
    size.x = x + p_margin;
    size.y = y + p_margin;
    size.width = width - p_margin * 2;
    size.height = height - p_margin * 2;
    size.cx = cx;
    size.cy = cy;
    size.cwidth = cwidth;
    size.cheight = cheight;
   
    return size;
}

function copy_files(){
    var save_images_state = save_images;
    if (!save_images_state) save_images = true;

    var destination_path;
    var tmp_files = files;
    var tmp_artist = artist;
    var tmp_p_a = p_a[select_p_a];
    var tmp_directory_path;
   
    if (path.indexOf('://') > 0 || path.indexOf('youtube') == 0 || path.indexOf('cdda') == 0) {
        tmp_directory_path = fb.ProfilePath + tmp_p_a + "\\";
    } else {
        tmp_directory_path = directory_path + "\\" + tmp_p_a + "\\";
    }   
   
    var nl = "\" + chr(10) + \"";
    var input_box_text = "Копировать  " + nl + nl + tmp_artist + " " + tmp_p_a + ".jpg" + nl + "файлы в";

    var string = input_box(input_box_text, tmp_directory_path, "Foobar 2000");

    if (string){
        destination_path = folder_exists(string);
        if (!destination_path) {
            copy_files();
        } else{
            copy_files_to_folder(destination_path, tmp_files, tmp_p_a);
        }
    }
    save_images = save_images_state;
}

function copy_files_to_folder(p, f, pa){
    if (p.length != "\\"){p = p + "\\"}
    for (i in f) {
        if (f[i].indexOf(pa) > 0){
            try {
                fso.CopyFile (f[i], p  , 1 );
            } catch(e) {}
        }
    }
}

function input_box(p_text, d_text, w_title){
    vbe = new ActiveXObject('ScriptControl');
    vbe.Language = 'VBScript';
    return vbe.eval( "InputBox(\"" + p_text + "\",\"" + w_title + "\",\"" + d_text + "\")");
}

function clean_path_name(n) {
    if (!n) return;
    return n.replace(/[\/\:\*\?\"\<\>\|]/g,'');
}

function folder_exists(n) {
    var driver = fso.GetDriveName(n);
    if (!fso.DriveExists(driver)) {
        return "";
    } else {
        var p = "";
        var split_string = [];
        split_string = n.replace(/\\$/g, "").split("\\");

        for (var i = 1; i < split_string.length; i += 1) {
            p = p + clean_path_name(split_string[i]) + "\\";
            try {
                if(!fso.FolderExists(driver + "\\" + p)) fso.CreateFolder(driver + "\\" + p);
            } catch(e) {};
        }
      return driver + "\\" + p;
    }
}

function on_notify_data(name, info) {
    if(name == "panel") {
        if (info == "bio"){
            panel_on = true;
            artist = "";
            on_metadb_changed();
        } else{
            panel_on =  false;
        }
    }
}

//var WshShell = WScript.CreateObject("WScript.Shell")
//WshShell.SendKeys("+{F10}");
Сейчас этот вариант у себя гоняю...
Последний раз редактировалось MC Web 14.11.2016, 16:42, всего редактировалось 2 раз(а).
MC Web
Репутация: 248
С нами: 10 лет 8 месяцев

Сообщение #1365 seriousstas » 14.11.2016, 15:37

kgena_ua
1.Ок
2.Если снова словлю - засниму.. (тесты всегда с фейдером..)
Последний раз редактировалось seriousstas 14.11.2016, 16:05, всего редактировалось 3 раз(а).
seriousstas
Откуда: Украина , Ивано-Франковск
Репутация: 110
С нами: 9 лет 2 месяца

Сообщение #1366 MC Web » 14.11.2016, 15:41

По on_mouse_wheel мотается 4-е картинки из 5-ти . В папке их 5-ть .
Это скорее два одинаковые, но с разным разрешением, картинки. Поэтому кажется при перемотке что их 4, а не 5...
MC Web
Репутация: 248
С нами: 10 лет 8 месяцев

Сообщение #1367 seriousstas » 14.11.2016, 15:42

MC Web
Текст загружается быстро, вместе с картинкой
А без картинки ?
Полагаю при таком варианте отдельно текст не вывести ..
seriousstas
Откуда: Украина , Ивано-Франковск
Репутация: 110
С нами: 9 лет 2 месяца

Сообщение #1368 MC Web » 14.11.2016, 15:49

seriousstas:Полагаю при таком варианте отдельно текст не вывести ..
Мне он без картинки и не нужен.
Или вопрос по поводу вывода биографии при отсутствии картинки на сайте ?
Попадались такие варианты, но уже не помню с этим скриптом или нет.
MC Web
Репутация: 248
С нами: 10 лет 8 месяцев

Сообщение #1369 seriousstas » 14.11.2016, 15:57

Условие :
if (found > 0) get_text();
Если найдены картинки - берем текст,
а если не найдены ?.... :)
seriousstas
Откуда: Украина , Ивано-Франковск
Репутация: 110
С нами: 9 лет 2 месяца

Сообщение #1370 MC Web » 14.11.2016, 16:19

seriousstas:Условие :
if (found > 0) get_text();
Если найдены картинки - берем текст,
а если не найдены ?.... :)

Ну напиши
if (found >= 0) get_text();
MC Web
Репутация: 248
С нами: 10 лет 8 месяцев

Сообщение #1371 kgena_ua » 14.11.2016, 19:09

Biography Text && Picture. www.last.fm
version "14112016"


Грузит все, сбоев нет.
Код: Выделить всё
// ==PREPROCESSOR==
// @name "Biography Text && Picture. www.last.fm"
// @author "kgena_ua"
// @version "14112016"
// @feature "v1.4"
// @feature "watch-metadb"
// ==/PREPROCESSOR==

function RGB(r,g,b) { return (0xff000000|(r<<16)|(g<<8)|(b)); }
function RGBA(r,g,b,a) { return ((a << 24) | (r << 16) | (g << 8) | (b)); }
function getRed(color) {return ((color >> 16) & 0xff);};
function getGreen(color) {return ((color >> 8) & 0xff);};
function getBlue(color) {return (color & 0xff);};

DT_LEFT = 0x00000000;
DT_RIGHT = 0x00000002;
DT_CENTER = 0x00000001;
DT_VCENTER = 0x00000004;
DT_SINGLELINE = 0x00000020;
DT_WORD_ELLIPSIS = 0x00040000;
DT_WORDBREAK = 0x00000010;
DT_CALCRECT = 0x00000400;
DT_NOPREFIX = 0x00000800;

MF_ENABLED = 0x00000000;   
MF_GRAYED = 0x00000001;   
MF_SEPARATOR = 0x00000800; 

var ww = 200, wh = 200;

var font_name_a = window.GetProperty(" font name: artist", "Arial");
var font_name_b = window.GetProperty(" font name: biography", "Arial");
var font_size_a_d = window.GetProperty(" font size: artist (delta)", 0);
var font_size_b = window.GetProperty(" font size: biography", 12);
var a_font_style = window.GetProperty(" font style: artist", 1);
var b_font_style = window.GetProperty(" font style: biography", 0);
var min_font_size = 12;
var max_font_size = 16;

var a_font, b_font;
get_font();

function get_font(){
    a_font = gdi.Font(font_name_a, font_size_b + font_size_a_d, a_font_style);
    b_font = gdi.Font(font_name_b, font_size_b, b_font_style);
}   

ColorTypeCUI = {
    text: 0,
    selection_text: 1,
    inactive_selection_text: 2,
    background: 3,
    selection_background: 4,
    inactive_selection_background: 5,
    active_item_frame: 6
};

function get_color(){   
    bgcolor = window.GetColorCUI(ColorTypeCUI.background);
    a_color = window.GetColorCUI(ColorTypeCUI.text);
    b_color = window.GetColorCUI(ColorTypeCUI.inactive_selection_text);
    window.Repaint();
}

get_color();

function on_colors_changed(){
    get_color();
}

var fso = new ActiveXObject("Scripting.FileSystemObject");

var tmp_b_path = fb.ProfilePath + "\\tmp_Biography\\";
if (!fso.FolderExists(tmp_b_path)) {fso.CreateFolder(tmp_b_path)};

var script_path = tmp_b_path + "_download\\";
if (!fso.FolderExists(script_path)) {fso.CreateFolder(script_path)};
if (!fso.FileExists(script_path + "download.vbs")) {create_download_file()};

var doc = new ActiveXObject("htmlfile");
var WshShell = new ActiveXObject("WScript.Shell");
var vbs = "cscript //nologo \"" + script_path + "download.vbs\"";

var default_img_path = window.GetProperty(" default img path",".\\maybe\\textures\\nocover\\nocover.png");
var default_img = window.GetProperty(" default img", false);
var default_img_transparent = window.GetProperty(" default img transparent (0-255)", 100);

load_last_fm_logo();
var logo_img = gdi.Image(script_path + "footer_logo.png");

var artist, old_artist;
var path, directory_path;

function clean_name(n) {
    if (!n) return;
    return n.replace(/[^a-zA-Z0-9а-яА-Я\s-&\.,]/g,'').replace(/^\s+|\s+$/g,"").substr(0,200);
}

function artist_folder_path(n) {
    return tmp_b_path + n;
}

function check_folder(n) {
    if (!n) return;
    if(!fso.FolderExists(n)) {fso.CreateFolder(n)};
}

String.prototype.repeat = function(n) {
    return new Array(n + 1).join(this);
}

window.SetProperty(" - user", "");
if (window.GetProperty(" - user") != "" ) window.SetProperty(" - user", "");
window.SetProperty("-".repeat(50), "");
if (window.GetProperty("-".repeat(50)) != "" ) window.SetProperty("-".repeat(50), "");

var g_img = null;
var p_margin = window.GetProperty(" margin: picture", 0);
var align_mode_a = new Array("adjust", "adjust top - center", "adjust top - left", "centre", "centre - top", "stretch");
var align_mode = window.GetProperty("align mode", 0);
var selected = 0;
var files = [];
var images = [];
var save_images = window.GetProperty("save images", false);
var limit = window.GetProperty(" download limit",5);
var cycle = window.GetProperty("auto cycle (sec)", 0);
if (cycle > 0) set_cycle_timer();
var fader = 255;
var fade_effect = window.GetProperty("fade effect", false);
var fade_step = window.GetProperty("fade step", 25);
var on_pic = false;

var download_quality = window.GetProperty("download quality", 1);
var quality = [
    [ "low", "avatar170s" , "avatar300s"],
    [ "medium", "300x300" , "300x300"],
    [ "high", "770x0" , ""]
];

var scrollbar = window.GetProperty(" scrollbar", true);
var scrollbar_w = window.GetProperty(" scrollbar width ", 4);
var scrollbar_k;
var sb_x = 0;
var sb_posy = 0;
var on_sb = false;
var on_sb_down = false;
var sb_color;

var b_file;
var bg_transparent = window.GetProperty(" bg transparent (0-255)", 200);
var t_margin = window.GetProperty(" margin: text", 10);
var txt_x = window.GetProperty("txt_x", window.Width / 2);
var old_txt_x = 0;
var txt_y = window.GetProperty("txt_y", window.Height / 2);
var delta_x, delta_y;
var a_x, a_y, b_x, b_y;
var text = "";
var text_not_found = new Array(". . .", ". . .");
var s_text = 0;
var a_text_row_height = 0;
var b_text_row_height = 0;
var b_text_rows = 0;
var b_text_visable_rows = 0;
var b_text_visable_height = 0;
var b_text_array = [];
var on_artist = false;
var on_text = false;
var on_text_down = false;
var refresh_txt = true;

var lang_query = new Array("", "ru/");
var lang_text = new Array("in", "ru");
//var lang_query = new Array("", "zh/");
//var lang_text = new Array("in", "zh");

var lang = window.GetProperty("lang", 0);

var select_p_a = window.GetProperty("pictures/albums", 0);
var p_a = new Array("images", "albums");

var panel_on = true;

var selection_mode = window.GetProperty("selection mode", 0);
var metadb;
on_item_focus_change();

function on_paint(gr){   
   !window.IsTransparent && gr.FillSolidRect(0, 0, ww, wh, bgcolor);
   
    draw_image(gr);

    if(set_cycle){   
        gr.FillSolidRect(0, 0, ww, wh, RGBA(getRed(bgcolor),getGreen(bgcolor),getBlue(bgcolor),bg_transparent));   
        var txt_cycle = cycle == 0 ? "off" : cycle + " sec";   
        set_cycle && gr.GdiDrawText("auto cycle:   " + txt_cycle, b_font, b_color, 0, 20, ww, wh, DT_CENTER | DT_WORD_ELLIPSIS );
    } else{   
        gr.FillSolidRect(txt_x, txt_y, ww - txt_x, wh - txt_y, RGBA(getRed(bgcolor),getGreen(bgcolor),getBlue(bgcolor),bg_transparent));   
    }   

    draw_scrollbar(gr);   
   
    gr.GdiDrawText( artist, a_font, RGB(0,0,0), a_x + 1, a_y + 2, ww - a_x - t_margin, wh, DT_LEFT | DT_WORD_ELLIPSIS | DT_NOPREFIX );   
    gr.GdiDrawText( artist, a_font, a_color, a_x, a_y, ww - a_x - t_margin, wh, DT_LEFT | DT_WORD_ELLIPSIS | DT_NOPREFIX );   

    for (var i = 0; i < b_text_visable_rows * 2; i += 2) {
        try {
            gr.GdiDrawText( b_text_array[i + s_text * 2].replace(/^\s+|\s+$/g, ""), b_font, RGB(0,0,0), b_x + 1, b_y + b_text_row_height * i / 2 + 2, ww, wh, DT_LEFT | DT_NOPREFIX );
            gr.GdiDrawText( b_text_array[i + s_text * 2].replace(/^\s+|\s+$/g, ""), b_font, b_color, b_x, b_y + b_text_row_height * i / 2 , ww, wh, DT_LEFT | DT_NOPREFIX );
        } catch(e) {}
    }

    //gr.GdiDrawText( "files " + files.length, gdi.Font("Arial",12, 0), b_color, 10, 0, ww, wh, DT_LEFT | DT_WORD_ELLIPSIS );
    //gr.GdiDrawText( "images " + images.length, gdi.Font("Arial",12, 0), b_color, 10, 20, ww, wh, DT_LEFT | DT_WORD_ELLIPSIS );
}

function draw_image(gr){
    if (g_img && images.length > 0){
        var size = calc_img_size(g_img);
        gr.DrawRect(size.x, size.y, size.width, size.height, 1, RGBA(getRed(bgcolor),getGreen(bgcolor),getBlue(bgcolor),fader));
        gr.DrawImage(g_img, size.x, size.y, size.width, size.height, size.cx, size.cy, size.cwidth, size.cheight, 0, fader);
    }
   
    if (logo_img && images.length == 0 && !default_img){
        gr.DrawImage(logo_img, 10, 10, logo_img.Width * 0.8, logo_img.Height * 0.8, 0, 0, logo_img.Width, logo_img.Height, 0, 100);         
    }

    if (images.length == 0 && default_img){
        try {
            nc_img = gdi.Image(default_img_path);
            var size = calc_img_size(nc_img);
            gr.DrawImage(nc_img, size.x, size.y, size.width, size.height, size.cx, size.cy, size.cwidth, size.cheight, 0, default_img_transparent);
        } catch(e) {};
    }
}

function draw_scrollbar(gr){
    scrollbar_h = b_text_rows > b_text_visable_rows ? b_text_visable_height * (b_text_visable_rows / b_text_rows) : 0;
    if (b_text_rows > b_text_visable_rows){ scrollbar_h = Math.max(5, scrollbar_h)}
    scrollbar_y = s_text > 0 ? s_text * scrollbar_k : 0;

    sb_x = ww - t_margin - scrollbar_w;
   
    sb_t = on_sb || on_sb_down ? 150 : 50;
    sb_color = RGBA(getRed(a_color), getGreen(a_color), getBlue(a_color), sb_t);
   
    scrollbar && gr.FillSolidRect(sb_x, b_y + scrollbar_y, scrollbar_w, scrollbar_h, sb_color);
}

function on_playlist_switch() {
    on_item_focus_change();
}

function on_playback_new_track() {
    on_item_focus_change();
}

function on_playback_dynamic_info_track() {
    on_item_focus_change();
}

function on_playback_stop() {
    on_item_focus_change();
}

function on_selection_changed(metadb) {
   on_item_focus_change();
}

function on_item_focus_change() {
    switch (selection_mode) {
    case 0:
        metadb = fb.IsPlaying ? fb.GetNowPlaying() : fb.GetFocusItem();   
        break;   
    case 1:   
        metadb = fb.GetFocusItem();
        break;   
    }   
    if (metadb) on_metadb_changed();   
}   

function Eval(field) {   
    if (!metadb) return;   
    path = fb.Titleformat("%path%").EvalWithMetadb(metadb);
    directory_path = fb.Titleformat("$directory_path(%path%)").EvalWithMetadb(metadb);
    return path.indexOf('://') > 0 ? fb.TitleFormat("[" + field + "]").Eval(true) : fb.TitleFormat("[" + field + "]").EvalWithMetadb(metadb);
}   

function on_metadb_changed() {
 //   if (!panel_on) return;
    if (!metadb) return; 
    artist = Eval("%artist%");
    if (artist) {artist = clean_name(artist)} else {artist = ""};
    if (artist != old_artist){
        if (!save_images) del_folders(artist);
        clear_text_var();
        get_pic();
        old_artist = artist;
    }
}   

function get_pic() {
    images = [];
    files = [];
    selected = 0;
    g_img = null;
    window.Repaint();
   
    check_folder(artist_folder_path(artist));
    if (fso.FolderExists(artist_folder_path(artist))){
        get_files_from_dir(artist_folder_path(artist));
        if (!g_img && images.length > 0) {
            next_image(0);
            get_text();
        } else {
            get_lastFM_pic(artist_folder_path(artist));
        }
    }
}

function get_lastFM_pic(p){
    xmlhttp1 = new ActiveXObject("Microsoft.XMLHTTP");     
    url1 = ("http://www.last.fm/music/" + encodeURIComponent(artist) + "/+" + p_a[select_p_a]);     
    xmlhttp1.open("GET", url1, true ); 
    xmlhttp1.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
    xmlhttp1.send(null);     
    xmlhttp1.onreadystatechange = function () {
        if (xmlhttp1.readyState == 4) {
            if (xmlhttp1.status == 200) { 
                doc.open();     
                var div = doc.createElement("div");
                div.innerHTML = xmlhttp1.responsetext;
                var data = div.getElementsByTagName("img");
                var urls = [];
                for (i = 0; i < data.length; i++) {   
                    if (data[i].className == "image-list-image" && select_p_a == 0){       
                        if (data[i].src.indexOf("http://img2-ak.lst.fm/i/u/avatar170s") == 0 || data[i].src.indexOf("https://lastfm-img2.akamaized.net/i/u/avatar170s") == 0) {
                            urls.push(data[i].src.replace("avatar170s", quality[download_quality][1]));
                        }     
                    }   
                    if (data[i].className == "album-grid-album-art" && select_p_a == 1){ 
                        if ((data[i].src.indexOf("http://img2-ak.lst.fm/i/u/300") == 0 || data[i].src.indexOf("https://lastfm-img2.akamaized.net/i/u/300") == 0) && data[i].src.indexOf("c6f59c1e5e7240a4c0d427abd71f3dbb") < 0) {                       
                            urls.push(data[i].src.replace("300x300", quality[download_quality][2]))
                        }     
                    }
                }
                var found = urls.length;
                for (i = 0; i < Math.min(urls.length, limit); i++) {     
                    var file = "\"" + p + "\\" + artist + "_"  + i + "_" + p_a[select_p_a] + ".jpg" + "\"";     
                    WshShell.Run(vbs + " " + urls[i] + " " + file, 0, false);
                }     
                doc.close();
                if (found > 0) get_files_if_loaded(p);
            }
        }
        get_text();       
    }     
}

function get_files_from_dir(p) {
    if (!artist) return;
    files = utils.Glob(p + "\\" + artist + "*" + p_a[select_p_a] + ".jpg").toArray();
   
    if (files.length > images.length){
        images = [];
       
        for (var i = 0; i < files.length; i += 1) {
            try {
                images.push(resize_image(gdi.Image(files[i])));
            } catch(e) {}
        }
    }
}

function next_image(d){
    fader = fade_effect ? 0 : 255;
    if (d < 0) {selected = selected <= 0 ? images.length - 1 : selected = selected - 1};
    if (d > 0) {selected = selected >= images.length - 1 ? 0 : selected = selected + 1};
    g_img = images[selected];
    if (g_img && fade_effect) fader_timer();
    window.Repaint();
}

function resize_image(img){
    if (!img) return;
   
    var scale_w = (window.Width - p_margin * 2) / img.Width;
    var scale_h = (window.Height - p_margin * 2) / img.Height;
    var scale = Math.min(scale_w, scale_h);
    var nww = img.Width * scale;
    var nwh = img.Height * scale

    var temp_bmp = gdi.CreateImage(nww, nwh);
    var temp_gr = temp_bmp.GetGraphics();
    temp_gr.SetSmoothingMode(2);
    temp_gr.SetInterpolationMode(7);
    temp_gr.DrawImage(img, 0, 0, nww, nwh, 0, 0, img.width, img.height);
    temp_bmp.ReleaseGraphics(temp_gr);
   
    CollectGarbage();
    return temp_bmp;
    temp_bmp.Dispose();
    temp_gr = null;
    temp_bmp = null;
}

function clear_text_var() {
    s_text = 0;
    text = "";
    b_text_array = [];
}

function get_text() {
    clear_text_var();
    b_text_file = artist_folder_path(artist) + "\\" + artist + "_biography_" + lang_text[lang] + ".txt";
   
    refresh_txt = true;
   
    if (artist && fso.FileExists(b_text_file)){
        text = utils.ReadTextFile(b_text_file);
        get_b_text_array();
    } else{
        get_lastFM_b_text(b_text_file);
    }
}

function get_lastFM_b_text(p){
    xmlhttp2 = new ActiveXObject("Microsoft.XMLHTTP");
    url2 = ("http://www.last.fm/" + lang_query[lang] + "music/" + encodeURIComponent(artist) + "/+wiki");
    xmlhttp2.open("GET", url2, true);
    xmlhttp2.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
    xmlhttp2.send(null);
    xmlhttp2.onreadystatechange = function () {
        if (xmlhttp2.readyState == 4) {
            if (xmlhttp2.status == 200) {
                doc.open();
                var div = doc.createElement("div");
                div.innerHTML = xmlhttp2.responsetext;
                var data = div.getElementsByTagName("div");
                for (i = 0; i < data.length; i++) {
                    if (data[i].className == "wiki-content") {
                        text = strip_tags(data[i].innerHTML).replace(/^\s+|\s+$/g,"");
                        break;
                    }
                }
                doc.close();
            }
            if (text != "") save_biography_file(text, p);
            if (text == "") text = text_not_found[lang];
            get_b_text_array();
        }
    }
}

function strip_tags(t) {
    doc.open();
    var div = doc.createElement("div");
    div.innerHTML = t.replace(/<[Pp][^>]*>/g, "").replace(/<\/[Pp]>/g, "<br>").replace(/\n/g, "<br>");
    var text = div.innerText;
    doc.close();
    return text;
}

function get_b_text_array() {
    a_x = txt_x + t_margin;
    a_y = txt_y + t_margin;
 
    temp_bmp = gdi.CreateImage(1, 1);
    temp_gr = temp_bmp.GetGraphics();

    a_text_row_height = temp_gr.CalcTextHeight("text", a_font);
    b_text_row_height = temp_gr.CalcTextHeight("text", b_font);
   
    b_x = txt_x + t_margin;
    b_y = a_y + a_text_row_height + b_text_row_height;
   
    string_width = Math.max(ww - b_x - t_margin - scrollbar_w - 10, 0);

    if (Math.abs(txt_x - old_txt_x) > 5 || refresh_txt){
        b_text_array = [];
        if (text) b_text_array = temp_gr.EstimateLineWrap(text.replace(/^\s+|\s+$/g,""), b_font, string_width).toArray();
        old_txt_x = txt_x;
        refresh_txt = false;
    }
   
    b_text_rows = b_text_array.length / 2;

    b_text_visable_area = Math.floor(Math.max(0, window.Height - t_margin - b_y));
    b_text_visable_rows = Math.floor(b_text_visable_area / b_text_row_height);
    b_text_visable_height = b_text_visable_rows * b_text_row_height;


    if (b_text_visable_rows + s_text > b_text_rows && s_text > 0) {
        s_text = (b_text_rows - b_text_visable_rows);
    }
   
    scrollbar_k = b_text_visable_height / b_text_rows;
   
    temp_bmp.ReleaseGraphics(temp_gr);
    temp_bmp.Dispose();
    temp_gr = null;
    temp_bmp = null;

    window.Repaint();
}

function save_biography_file(t, p){
    if (!artist) return;
    try {
        file = fso.OpenTextFile( p, 2, true, -1)
        file.WriteLine(t);
        file.Close();
    } catch(e) {
        return;
    }
}

function on_mouse_rbtn_up (x, y){     
    var _menu = window.CreatePopupMenu();
   
    _menu.AppendMenuItem(MF_ENABLED, 10, lang_text[0] + " text");   
    _menu.AppendMenuItem(MF_ENABLED, 11, lang_text[1] + " text");   
    _menu.CheckMenuRadioItem(10, 11, lang + 10);         
    _menu.EnableMenuItem(lang + 10, 1);     

    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);   
    _menu.AppendMenuItem(MF_ENABLED, 12, "Prefer now playing");   
    _menu.AppendMenuItem(MF_ENABLED, 13, "Follow selected track");   
    _menu.CheckMenuRadioItem(12, 13 , selection_mode + 12);   
    _menu.EnableMenuItem(selection_mode + 12, 1);
       
    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0); 
    _menu.AppendMenuItem(MF_ENABLED, 14, "Artist pictures");   
    _menu.AppendMenuItem(MF_ENABLED, 15, "Albums pictures");   
    _menu.CheckMenuRadioItem(14, 15 , select_p_a + 14);   
    _menu.EnableMenuItem(select_p_a + 14, 1);

    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);   
    IS_ARTIST = artist ? MF_ENABLED : MF_GRAYED;   
    _menu.AppendMenuItem(IS_ARTIST, 16, "last.fm Artist");   
   
    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
    _menu.AppendMenuItem(MF_ENABLED, 17, "Fade effect");
    _menu.CheckMenuItem(17, fade_effect);

    _firstgroup = window.CreatePopupMenu();
    _firstgroup.AppendTo(_menu,MF_ENABLED,  "Align : " + align_mode_a[align_mode]);
   
    _firstgroup.AppendMenuItem(MF_ENABLED, 20, align_mode_a[0]);         
    _firstgroup.AppendMenuItem(MF_ENABLED, 21, align_mode_a[1]);
    _firstgroup.AppendMenuItem(MF_ENABLED, 22, align_mode_a[2]);
    _firstgroup.AppendMenuItem(MF_ENABLED, 23, align_mode_a[3]);
    _firstgroup.AppendMenuItem(MF_ENABLED, 24, align_mode_a[4]);
    _firstgroup.AppendMenuItem(MF_ENABLED, 25, align_mode_a[5]);
    _firstgroup.CheckMenuRadioItem(20, 25, align_mode + 20);
    _firstgroup.EnableMenuItem(align_mode + 20, 1);

    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
    _secondgroup = window.CreatePopupMenu();
    _secondgroup.AppendTo(_menu,MF_ENABLED,  "Download quality : " + quality[download_quality][0]);
   
    _secondgroup.AppendMenuItem(MF_ENABLED, 30, "Low");
    _secondgroup.AppendMenuItem(MF_ENABLED, 31, "Medium");
    _secondgroup.AppendMenuItem(MF_ENABLED, 32, "High");
    _secondgroup.CheckMenuRadioItem(30, 32, download_quality + 30);
    _secondgroup.EnableMenuItem(download_quality + 30, 1);

    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
    MF_STRING = images.length > 0 ? MF_ENABLED : MF_GRAYED;
    _menu.AppendMenuItem(MF_STRING, 40, "Copy to folder containing track...");
    _menu.AppendMenuItem(MF_STRING, 50, "Open image");
   
    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
    _menu.AppendMenuItem(MF_ENABLED, 60, "Save images and text");
    _menu.CheckMenuItem(60, save_images);

    //_menu.AppendMenuItem(MF_SEPARATOR, 0, 0);   
    //_menu.AppendMenuItem(MF_ENABLED, 100, "Reload");   
    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);   
    _menu.AppendMenuItem(MF_ENABLED, 110, "Properties");   
    _menu.AppendMenuItem(MF_ENABLED, 120, "Configure ...");

    ret = _menu.TrackPopupMenu(x,y);

    switch (ret) {
    case 10:
        lang = 0;
        window.SetProperty("lang", lang);
        get_text();
        break;
    case 11:
        lang = 1;
        window.SetProperty("lang", lang);
        get_text();
        break;
    case 12:
        selection_mode = 0;
        window.SetProperty("selection mode", selection_mode);
        on_item_focus_change();
        break;
    case 13:
        selection_mode = 1;
        window.SetProperty("selection mode", selection_mode);
        on_item_focus_change();
        break;
    case 14:
        select_p_a = 0;
        window.SetProperty("pictures/albums", select_p_a);
        get_pic();
        break;
    case 15:
        select_p_a = 1;
        window.SetProperty("pictures/albums", select_p_a);
        get_pic();
        break;
    case 16:
        WshShell.run("http://www.last.fm/" + lang_query[lang] + "music/" + encodeURIComponent(artist));
        break;
    case 17:
        window.SetProperty("fade effect", !fade_effect);
        fade_effect = window.GetProperty("fade effect");
        break;
    case 20:
    case 21:
    case 22:
    case 23:
    case 24:
    case 25:
        align_mode = ret - 20;
        window.SetProperty("align mode", align_mode);
        window.Repaint();
        break;
    case 30:
    case 31:
    case 32:   
        download_quality = ret - 30;
        window.SetProperty("download quality", download_quality);
        break;
    case 40:
        copy_files();
        break;
    case 50:
        try {
            if (images[selected]) WshShell.run( '"' + artist_folder_path(artist)+ "\\" + artist + "_"  + selected + "_" + p_a[select_p_a] + ".jpg" + '"' );
        } catch(e) {}
        break;
    case 60:
        window.SetProperty("Save images", !save_images);
        save_images = window.GetProperty("Save images");
        break;
    //case 100:
    //    window.Reload();
    //    break;
    case 110:
        window.ShowProperties();
        break;   
    case 120:
        window.ShowConfigure();   
        break;   
   }
    _menu.Dispose();   
    return true;   
}   

var timer;

function get_files_if_loaded(p){
    timer && window.ClearInterval(timer);
    timer = window.SetInterval(function() {
        get_files_from_dir(p);
        if (images.length > 0)  {
            next_image(0);
            window.ClearInterval(timer); 
        }
    }, 500 );
}

var set_cycle = false;

function on_key_down(vkey) {
    if (vkey == 16){
        set_cycle = true;
        dis_set();
        window.Repaint();
    }
}

var cycle_timer, step = 0;

function set_cycle_timer(){
    cycle_timer && window.ClearInterval(cycle_timer);
    cycle_timer = window.SetInterval(function() {
        step =  set_cycle ? 0 : step + 1;
        if (cycle > 0 && step >= cycle){
            get_files_from_dir(artist_folder_path(artist));
            if (images.length > 1){
                next_image(1);
                step = 0;
            }
        }
        window.Repaint();
    }, 1000 );
}

var dis_timer, dis = 0;

function dis_set(){
    dis = 0;
    dis_timer && window.ClearInterval(dis_timer);
    dis_timer = window.SetInterval(function() {
        if (set_cycle) {
            dis++;
            if(dis == 1) {
                set_cycle = false;
                if (cycle > 0) set_cycle_timer();
                if (cycle == 0) window.ClearInterval(cycle_timer);
                window.ClearInterval(dis_timer)
                window.Repaint();
            };
        }
    }, 1000 );
}

var delay = false;

function fdelay(){
    var delay_timer = window.SetTimeout(function() {
        delay = false;
        window.ClearTimeout(delay_timer);
    }, 200);
}

var ftimer;

function fader_timer(){
    fader = 0;
    ftimer && window.ClearInterval(ftimer);
    ftimer = window.SetInterval(function() {
        fader = fader + fade_step;
        if (fader >= 255) {
            fader= 255;
            window.ClearInterval(ftimer);
        }
        window.Repaint();
    }, 42 );
}

function load_last_fm_logo(){
    if(!fso.FileExists(script_path + "footer_logo.png")) {
        var url = "http://www.last.fm/static/images/logo_beta.png?eb6d3ca20e73"
        var file = "\"" + script_path + "last_fm_logo.jpg" + "\"";
        WshShell.Run(vbs + " " + url + " " + file, false);
       
        var url = "http://static-web.last.fm/static/images/favicon.702b239b6194.ico"
        var file = "\"" + script_path + "last_fm_ico.ico" + "\"";
        WshShell.Run(vbs + " " + url + " " + file, false);

        var url = "http://static-web.last.fm/static/images/footer_logo.ddcfd65712a6.png"
        var file = "\"" + script_path + "footer_logo.png" + "\"";
        WshShell.Run(vbs + " " + url + " " + file, false);
    }
}

function create_download_file() {
    try {
        file = fso.CreateTextFile(script_path + "download.vbs" )
       
        var text =   
            "If (WScript.Arguments.Count <> 2) Then" + "\n\r" +   
            "   WScript.Quit" + "\n\r" +
            "End If" + "\n\r" + "\n\r" +   

            "url = WScript.Arguments(0)" + "\n\r" +   
            "file = WScript.Arguments(1)" + "\n\r"  + "\n\r" +   

            "Set objFSO = Createobject(" + '"Scripting.FileSystemObject"' + ")" + "\n\r" +   
            "If objFSO.Fileexists(file) Then" + "\n\r" +   
            "   Set objFSO = Nothing" + "\n\r" +
            "   WScript.Quit" + "\n\r" +
            "End If" + "\n\r" + "\n\r" +   

            "Set objXMLHTTP = CreateObject(" + '"MSXML2.XMLHTTP"' + ")" + "\n\r" +   
            "objXMLHTTP.open " + '"GET"' + ", url,false" + "\n\r" +   
            "objXMLHTTP.send()" + "\n\r" + "\n\r" +   

            "If objXMLHTTP.Status = 200 Then" + "\n\r" +   
            "   Set objADOStream = CreateObject(" + '"ADODB.Stream"' + ")" + "\n\r" +
            "   objADOStream.Open" + "\n\r" +
            "   objADOStream.Type = 1" + "\n\r" +
            "   objADOStream.Write objXMLHTTP.ResponseBody" + "\n\r" +
            "   objADOStream.Position = 0" + "\n\r" +
            "   objADOStream.SaveToFile file" + "\n\r" +
            "   objADOStream.Close" + "\n\r" +
            "   Set objADOStream = Nothing" + "\n\r" +
            "End If" + "\n\r" + "\n\r" +   

            "Set objFSO = Nothing" + "\n\r" +   
            "Set objXMLHTTP = Nothing"   
        ;

        file.WriteLine(text);
        file.Close();
    } catch(e) {};
}

function on_mouse_move(x, y) {
    window.SetCursor(32649);

    on_text = x >= txt_x && x < sb_x && y  >= txt_y ? true : false;
    on_sb =  x >= sb_x && x < ww && y >= txt_y && y < wh ? true : false;
    on_pic = !on_text && !on_sb ? true : false;

    if (on_text_down){
        txt_x = x - delta_x;
        txt_y = y - delta_y;

        txt_x = txt_x <= 0 ? 0 : txt_x >= ww - 50 ? ww - 50: txt_x;
        txt_y = txt_y <= 0 ? 0 : txt_y >= wh - (a_text_row_height + t_margin * 2) ? wh - (a_text_row_height + t_margin * 2) : txt_y;

        get_b_text_array();
    }

    if (on_sb_down && scrollbar && b_text_rows > b_text_visable_rows){
        sb_posy = y + delta_y;
        s_text = y + delta_y >= 0 ? y + delta_y <= (b_text_rows - b_text_visable_rows) * scrollbar_k ? Math.round(sb_posy / scrollbar_k) : b_text_rows - b_text_visable_rows : 0;
        //window.Repaint();
        window.RepaintRect(txt_x, txt_y, ww - txt_x, wh - txt_y);
    }
   
    window.RepaintRect(sb_x, txt_y, ww, wh);
}

function on_mouse_wheel(delta) {
    ShiftDown = utils.IsKeyPressed(0x10) ? true : false;
   
    if (on_pic && !ShiftDown && !delay){
        get_files_from_dir(artist_folder_path(artist));
        if (files.length > 1){
            delay = true;
            fdelay();
            next_image(delta);
            if (cycle > 0) step = 0;
        }
    }
   
    if (on_text && !ShiftDown){
        if (b_text_rows > b_text_visable_rows){
            if (delta < 0) {s_text = b_text_rows - s_text <= b_text_visable_rows ? b_text_rows - b_text_visable_rows : s_text += 1}
            if (delta > 0) {s_text = s_text <= 0 ? 0 : s_text -= 1}
        }
        window.RepaintRect(txt_x, txt_y, ww - txt_x, wh - txt_y);
    }
   
    if (on_text && ShiftDown && !delay){
        delay = true;
        fdelay();
        if (delta < 0) {font_size_b = font_size_b <= min_font_size ? min_font_size : font_size_b - 2;};
        if (delta > 0) {font_size_b = font_size_b >= max_font_size ? max_font_size : font_size_b + 2;};
        window.SetProperty("font size: biography", font_size_b);
        get_font();
        refresh_txt = true;
        get_b_text_array();
    }

    if (set_cycle && on_pic) {
        if (delta < 0) {cycle = cycle <= 0 ? 0 : cycle - 5;};
        if (delta > 0) {cycle = cycle >= 60 ? 60 : cycle + 5;};
        window.SetProperty("auto cycle (sec)", cycle);
        window.Repaint();
    }
}

function on_mouse_lbtn_down(x,y){
    if (on_text){
        on_text_down = true;
        delta_x = x - txt_x;
        delta_y = y - txt_y;
    }
    if (on_sb){
        on_sb_down = true;
        sb_posy = s_text * scrollbar_k;
        delta_y = sb_posy - y;
    }
}

function on_mouse_lbtn_up(x,y){
    window.SetProperty("txt_x", txt_x);
    window.SetProperty("txt_y", txt_y);
    on_text_down = false;
    on_sb_down = false;
}

function on_mouse_lbtn_dblclk (x,y){
    if (on_text){
        lang = lang == 1 ? 0 : 1;
        window.SetProperty("lang", lang);
        get_text();
    }

    if (on_pic){
        select_p_a = select_p_a == 1 ? 0 : 1;
        window.SetProperty("pictures/albums", select_p_a);
        get_pic();
    }
}

function on_mouse_leave() {
    window.SetCursor(32512);
    on_sb = false;
    window.Repaint();
}

function on_size(){
    ww = window.Width;   
    wh = window.Height;
   
    txt_x = window.GetProperty("txt_x");
    txt_y = window.GetProperty("txt_y");

    txt_x = txt_x >= ww - 50 && txt_x >= 0 ? ww - 50 : txt_x;
    txt_y = txt_y >= wh - (a_text_row_height + t_margin * 2) && txt_y >= 0 ? wh - (a_text_row_height + t_margin * 2) : txt_y;
   
    refresh_txt = true;
    get_b_text_array();
}

function del_folders(n){
    var dir = fso.GetFolder(tmp_b_path);
    var e = new Enumerator( dir.SubFolders );
    try {
        for(; !e.atEnd(); e.moveNext() ) {
            var name = e.item().Name;
            if (name.indexOf("_download") < 0){
                if (name.indexOf(n) < 0){
                    fso.deleteFolder(tmp_b_path + name, true);
                }
            }   
        }
    } catch(e) {};
}

function calc_img_size(img){
    if(!img) return;
    var size = {x:0, y:0, width:0, height:0, cx:0, cy:0, cwidth:0, cheight:0};

    switch(align_mode) {   
   case 0: // adjust      
        var sw = ww / img.Width;
        var sh = wh / img.Height;
        var s = Math.min(sw, sh);
       
        var x = 0;
        var y = 0;
       
        if (sw > sh) x = (ww - img.Width * s) / 2;
        else if (sw < sh) y = (wh - img.height * s) / 2;

        var width = img.Width * s;
        var height = img.Height * s;
        var cx = 0;
        var cy = 0;
        var cwidth = img.Width;
        var cheight = img.Height;
      break;
       
    case 1: // adjust top - center
        var sw = ww / img.Width;
        var sh = wh / img.Height;
        var s = Math.min(sw, sh);

        var x = 0;
        if (sw > sh) x = (ww - img.Width * s) / 2;
        var y = 0;
        var width = img.Width * s;
        var height = img.Height * s;
        var cx = 0;
        var cy = 0;
        var cwidth = img.Width;
        var cheight = img.Height;
      break;
       
    case 2: // adjust top - left
        var sw = ww / img.Width;
        var sh = wh / img.Height;
        var s = Math.min(sw, sh);
       
        var x = 0;
        var y = 0;
        var width = img.Width * s;
        var height = img.Height * s;
        var cx = 0;
        var cy = 0;
        var cwidth = img.Width;
        var cheight = img.Height;
      break;

   case 3: // centre   
      var sr = img.Width / img.Height;   
      var dr = ww / wh;   
      if (sr < dr) {   
         var r = img.Width / ww;
         var cheight = wh * r;
         var cy = Math.round((img.Height - cheight) / 2);
         var cwidth = img.Width;
         var cx = 0;
      } else {   
         var r = img.Height / wh;
         var cwidth = ww * r;
         var cx = Math.round((img.Width - cwidth) / 2);
         var cheight = img.Height;
         var cy = 0;
      }   
        var x = 0;         
        var y = 0;         
        var width = ww;         
        var height = wh;         
      break;   
       
   case 4: // centre - top      
      var sr = img.Width / img.Height;   
      var dr = ww / wh;   
      if (sr < dr) {   
         var r = img.Width / ww;
         var cheight = wh * r;
         var cy = 0;
         var cwidth = img.Width;
         var cx = 0;
      } else {   
         var r = img.Height / wh;
         var cwidth = ww * r;
         var cx = Math.round((img.Width - cwidth) / 2);
         var cheight = img.Height;
         var cy = 0;
      }
        var x = 0;
        var y = 0;
        var width = ww;
        var height = wh;
      break;   
       
   case 5: // stretch      
        var x = 0;
        var y = 0;
        var width = ww;
        var height = wh;
        var cx = 0;
        var cy = 0;
        var cwidth = img.Width;
        var cheight = img.Height;
      break;   
    }
   
    size.x = x + p_margin;
    size.y = y + p_margin;
    size.width = width - p_margin * 2;
    size.height = height - p_margin * 2;
    size.cx = cx;
    size.cy = cy;
    size.cwidth = cwidth;
    size.cheight = cheight;
   
    return size;
}

function copy_files(){
    var save_images_state = save_images;
    if (!save_images_state) save_images = true;

    var destination_path;
    var tmp_files = files;
    var tmp_artist = artist;
    var tmp_p_a = p_a[select_p_a];
    var tmp_directory_path;
   
    if (path.indexOf('://') > 0 || path.indexOf('youtube') == 0 || path.indexOf('cdda') == 0) {
        tmp_directory_path = fb.ProfilePath + tmp_p_a + "\\";
    } else {
        tmp_directory_path = directory_path + "\\" + tmp_p_a + "\\";
    }   
   
    var nl = "\" + chr(10) + \"";
    var input_box_text = "Copy  " + nl + nl + tmp_artist + " " + tmp_p_a + ".jpg" + nl + "files to";

    var string = input_box(input_box_text, tmp_directory_path, "Foobar 2000");

    if (string){
        destination_path = folder_exists(string);
        if (!destination_path) {
            copy_files();
        } else{
            copy_files_to_folder(destination_path, tmp_files, tmp_p_a);
        }
    }
    save_images = save_images_state;
}

function copy_files_to_folder(p, f, pa){
    if (p.length != "\\"){p = p + "\\"}
    for (i in f) {
        if (f[i].indexOf(pa) > 0){
            try {
                fso.CopyFile (f[i], p  , 1 );
            } catch(e) {}
        }
    }
}

function input_box(p_text, d_text, w_title){
    vbe = new ActiveXObject('ScriptControl');
    vbe.Language = 'VBScript';
    return vbe.eval( "InputBox(\"" + p_text + "\",\"" + w_title + "\",\"" + d_text + "\")");
}

function clean_path_name(n) {
    if (!n) return;
    return n.replace(/[\/\:\*\?\"\<\>\|]/g,'');
}

function folder_exists(n) {
    var driver = fso.GetDriveName(n);
    if (!fso.DriveExists(driver)) {
        return "";
    } else {
        var p = "";
        var split_string = [];
        split_string = n.replace(/\\$/g, "").split("\\");

        for (var i = 1; i < split_string.length; i += 1) {
            p = p + clean_path_name(split_string[i]) + "\\";
            try {
                if(!fso.FolderExists(driver + "\\" + p)) fso.CreateFolder(driver + "\\" + p);
            } catch(e) {};
        }
        return driver + "\\" + p;
    }
}
/*
function on_notify_data(name, info) {
    if(name == "panel") {
        if (info == "bio"){
            panel_on = true;
            artist = "";
            on_metadb_changed();
        } else{
            panel_on =  false;
        }
    }
}
*/
kgena_ua M
Аватара
Откуда: Украина, Днепр
Репутация: 504
С нами: 11 лет

Сообщение #1372 Marakobes » 14.11.2016, 19:52

kgena_ua:Biography Text && Picture. www.last.fm
version "14112016"

посоны, скажите куда вставлять код то?? кроме анатомических отверстиев! не могу больше без биографии :fie: и еще вопрос - этот скрипт тянет дискографию исполнителя (описание альбомов по годам)?
Marakobes
Репутация: 1
С нами: 11 лет 8 месяцев

Сообщение #1373 seriousstas » 14.11.2016, 19:57

Marakobes
Ставишь добавляешь панельку
По ПКМ > Configure - копипастишь скрипт .
Если сложно - качай обсуждаемые сборки - там везде есть эта био .
seriousstas
Откуда: Украина , Ивано-Франковск
Репутация: 110
С нами: 9 лет 2 месяца

Сообщение #1374 MC Web » 14.11.2016, 20:49

kgena_ua, опечатка:
Код: Выделить всё
var lang_text = new Array("in", "ru");
MC Web
Репутация: 248
С нами: 10 лет 8 месяцев

Сообщение #1375 ximenlangzige » 15.11.2016, 00:43

kgena_ua
Привет!
С самого начала, я нашел эту версию биографии с 10,112,016 фотографии не могут быть отображены, в том числе 14,112,016 этой версии! Тем не менее, трек может отображаться на английском языке, после изменения языка дисплея является английский с может отображаться китайская основа, включая английские биографии китайского языка. Таким образом, я открыл сайт last.fm, HTTP: //www.last.fm/zh/music/ Присцилла / вики, чтобы найти его, действительно, биография и образ, я обнаружил, что китайцы могут помечать песни не в биографии панели показать имя художника, так что я думаю, что проблема не вызвана именем дисплея, поэтому я сравнил эту версию о 09,102,016,
Код: Выделить всё
function clean_name(n) {
    if (!n) return;
    return n.replace(/[\/\:\*\?\"\<\>\|]/g,' ');
}

Я скопировать его на новую версию сценария после того, как проблема решена!
В дополнение к новой версии:
Код: Выделить всё
function clean_name(n) {
    if (!n) return;
    return n.replace(/[^a-zA-Z0-9а-яА-Я\s-&\.,]/g,'').replace(/^\s+|\s+$/g,"").substr(0,200);
}

function clean_name(n) {
    if (!n) return;
    return n.replace(/[\/\:\*\?\"\<\>\|]/g,' ');
}
И 14,112,016 версии Right-Reload не разрушится, и теперь чувствую себя прекрасно! Спасибо! Отличная работа!
[spoiler][/spoiler]
Вложения
2016-11-15_040645.png
2016-11-15_040610.png
2016-11-15_040338.png
2016-11-15_040338.png (6.22 КБ) Просмотров: 2358
ximenlangzige
Репутация: 3
С нами: 9 лет 5 месяцев

Сообщение #1376 seriousstas » 15.11.2016, 04:51

В последнем
Мод Biography Text && Picture 14112016 @author "kgena_ua"
Переделал вызов текста:
Теперь закрытие всегда кликом по заголовку (без крестика).
Положение окна с текстом задаётся тасканием.
После перетаскивания координаты запоминаются и будут по-умолчанию .
Вынес настройки цвета текста и заголовка в Пропертиз .
+ мелкие правки .
Все остальное (автопереключение и кавер из папки) в моём сетапе работает .
phpBB [media]
Последний раз редактировалось seriousstas 15.11.2016, 05:02, всего редактировалось 2 раз(а).
seriousstas
Откуда: Украина , Ивано-Франковск
Репутация: 110
С нами: 9 лет 2 месяца

Сообщение #1377 AHAPXICT » 15.11.2016, 04:53

kgena_ua, пока готовил сообщение со своим вопросом нашёл ещё один фикс. Для скриншота увеличил ширину полосы прокрутки для наглядности, а за одно и заметил, что при отключении scrollbar текст не меняет своего положения, с маленькой шириной это не заметно. Не знаю, вроде бы правильно сделал.
Строка 476: string_width = scrollbar ? Math.max(ww - b_x - t_margin - scrollbar_w - 10, 0) : Math.max(ww - b_x - t_margin, 0);

Вот какой совет нужен. Использую для полосы прокрутки бекграунд, и из за разного положения окна с текстом, а так же количества строк в тексте естественно меняется высота полосы. Как смог сделал, но остаётся разница +- пару пикселей между бекграудом. То есть не всегда доходит до конца панели, а иногда залазит чуть ниже. Минимальную высоту сделал 20. В вашем варианте всё правильно, все привязки работают как положено.
Сяду обновлю сборку, оставлю всё как есть, думаю никто и не заметит.

Ещё один вопрос по footer_logo.png. Новая иконка сразу пришлась по душе, как там и была. А зачем вы оставили старую logo_beta.png и старую ссылку на : http://www.last.fm/static/images/logo_beta.png?eb6d3ca20e73 ? Эта ссылка так и кочует из версии к версии, они уже давно заменили логотип на: http://www.last.fm/static/images/logo_static.png?5b6b42188c40 То есть, теоретически я могу заремить весь блок включая last_fm_ico.ico?

Ну и как всегда мега респект за работу! :beer:
Спойлер
Scrollbar.jpg
Последний раз редактировалось AHAPXICT 15.11.2016, 05:02, всего редактировалось 1 раз.
AHAPXICT M
Аватара
Откуда: Киев
Репутация: 252
С нами: 10 лет 5 месяцев

Сообщение #1378 seriousstas » 15.11.2016, 04:56

AHAPXICT
Я снова тебя опередил .. :smile:
поклацай МОД с Кутузовым . Вроде-бы сейчас удобнее должно-быть .
seriousstas
Откуда: Украина , Ивано-Франковск
Репутация: 110
С нами: 9 лет 2 месяца

Сообщение #1379 AHAPXICT » 15.11.2016, 04:58

seriousstas, не надо так пугать! Отправляю сообщение, а оно зависло и потом окно видео с ютуб на экране! Я уже думал всё сообщение заново придётся набирать. Это же надо в три часа ночи, отправить два сообщения одновременно!

Добавлено спустя 56 секунд:
Я уже понял :biggrin:

Сейчас засяду сборку обновлять, это до утра, а как проснусь сразу приступлю к тестированию.
Последний раз редактировалось AHAPXICT 15.11.2016, 05:10, всего редактировалось 1 раз.
AHAPXICT M
Аватара
Откуда: Киев
Репутация: 252
С нами: 10 лет 5 месяцев

Сообщение #1380 seriousstas » 15.11.2016, 04:59

я поэтому и написал следующий пост ,что-б Ты со стула не упал ..)
seriousstas
Откуда: Украина , Ивано-Франковск
Репутация: 110
С нами: 9 лет 2 месяца

Пред.След.

Вернуться в Секреты foobar2000