Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==PREPROCESSOR==
- // @name "WSH Last.fm panel"
- // @version "1.2"
- // @author "so_kindly"
- // ==/PREPROCESSOR==
- //== changelog ======================================
- // 1.1: "Microsoft.XMLHTTP" activex object replaced on "Msxml2.XMLHTTP.6.0"
- // 1.2: Added stream support, minor fixes
- //===================================================
- // Variables {{
- // Text flags
- var DT_TOP = 0x00000000;
- var DT_LEFT = 0x00000000;
- var DT_CENTER = 0x00000001;
- var DT_RIGHT = 0x00000002;
- var DT_VCENTER = 0x00000004;
- var DT_BOTTOM = 0x00000008;
- var DT_WORDBREAK = 0x00000010;
- var DT_CALCRECT = 0x00000400;
- var DT_NOPREFIX = 0x00000800;
- var DT_END_ELLIPSIS = 0x00008000;
- var DT_NOCLIP = 0x00000100;
- var IDC_HAND = 32649;
- var IDC_ARROW = 32512;
- var FontStyle = {
- Regular: 0,
- Bold: 1,
- Italic: 2,
- BoldItalic: 3,
- Underline: 4,
- Strikeout: 8
- };
- var StringAlignment = {
- Near: 0,
- Center: 1,
- Far: 2
- };
- var StringTrimming = {
- None: 0,
- Character: 1,
- Word: 2,
- EllipsisCharacter: 3,
- EllipsisWord: 4,
- EllipsisPath: 5
- };
- var StringFormatFlags = {
- DirectionRightToLeft: 0x00000001,
- DirectionVertical: 0x00000002,
- NoFitBlackBox: 0x00000004,
- DisplayFormatControl: 0x00000020,
- NoFontFallback: 0x00000400,
- MeasureTrailingSpaces: 0x00000800,
- NoWrap: 0x00001000,
- LineLimit: 0x00002000,
- NoClip: 0x00004000,
- BypassGDI: 0x80000000
- }
- // Flags of Menu
- var MF_SEPARATOR = 0x00000800;
- var MF_ENABLED = 0x00000000;
- var MF_GRAYED = 0x00000001;
- var MF_DISABLED = 0x00000002;
- var MF_UNCHECKED = 0x00000000;
- var MF_CHECKED = 0x00000008;
- var MF_STRING = 0x00000000;
- var MF_POPUP = 0x00000010;
- var MK_SHIFT = 0x0004;
- var FOCUSFLAG;
- var CursorFollowMode = {
- OnlyStopped: 2,
- Always: 3
- }
- // globals
- var ww = 0;
- var wh = 0;
- var Properties = new GetProperties();
- var MetaDB;
- //margins
- var lm = 5;
- var rm = 5;
- var tm = 5;
- var bm = 0;
- // text vars
- FontStyles = {
- Regular: 0,
- Bold: 1,
- Italic: 2,
- BoldItalic: 3,
- Underline: 4,
- Strikeout: 8
- }
- var font_label = gdi.Font("Segoe UI", 12, FontStyles.Bold);
- var font_num = gdi.Font("Segoe UI", 11, FontStyles.Bold);
- var font_normal = gdi.Font("Segoe UI", 13, FontStyles.Regular);
- var font_header = gdi.Font("Segoe UI", 15, FontStyles.Bold);
- var font_gui = gdi.Font("Web Symbols", 13, FontStyles.Regular);
- var normal_color = RGB(180, 180, 180);
- var hover_color = RGB(200, 200, 200);
- var LineStrFmt = StringFormat(StringAlignment.Near, StringAlignment.Near, StringTrimming.None, StringFormatFlags.LineLimit);
- var settings_dir = fb.ProfilePath + "Damask\\settings\\";
- //img vars
- var images_path = fb.FoobarPath + "skins\\Damask\\images\\lastfm\\";
- var img_lastfm_logo_red = gdi.Image(images_path + "lastfm_logo_red.jpg");
- var img_lastfm_flip = gdi.Image(images_path + "scrobbleflip.png");
- var img_avatar = gdi.Image(settings_dir + "avatar.jpg");
- var img_asterisk = gdi.Image(images_path + "asterisk_small.png");
- var img_heart = gdi.Image(images_path + "t2.png");
- var max_avatar_height = Properties.Avatar.MaxHeight;
- var ava_height = img_avatar.height > max_avatar_height ? max_avatar_height : img_avatar.height;
- var ava_width = img_avatar.height > max_avatar_height ? max_avatar_height * img_avatar.width / img_avatar.height : img_avatar.width;
- var avatar_need_refresh = true;
- var imgPath = fb.FoobarPath + "skins\\Damask\\images\\";
- var img_main_wallpaper = gdi.Image(imgPath + "DamaskBG.png").CreateRawBitmap();
- var opt_username = read_option("lastfm_username", "");
- var username = "";
- var opt_api_key = read_option("lastfm_api_key", "");
- var WshShell = new ActiveXObject("WScript.Shell");
- var lastfm_data = new Array();
- var lastfm_xmlhttp = new Array();
- var lastfm_xmlDoc = new Array();
- var wait = 1;
- var lastfm_status = 0;
- var error_count = 0;
- var loved_track = false;
- var Y_OFFSET = 0;
- var sum_height = 0;
- var text_H = 0;
- var text_W = 0;
- var mouse_x = 0;
- var mouse_y = 0;
- var regdate_error = false;
- // scrollbar colors
- var vs_normal_color = RGB(50, 50, 50);
- var vs_hover_color = RGB(70, 70, 70);
- var vs_down_color = RGB(60, 60, 60);
- var vs_bg_color = RGB(33, 33, 33);
- var vs_bg_color_hover = RGB(35, 35, 35);
- var text_Hs = new Array();
- var text_Ws = new Array();
- var TL_ys = new Array();
- var TL_xs = new Array();
- var np = [fb.TitleFormat("%artist%").Eval(true), fb.TitleFormat("%album%").Eval(true), fb.TitleFormat("%title%").Eval(true)];
- var spcounter = 0;
- var charcounter = 0;
- var longeststr = "";
- var linecounter = 1;
- var WaitTimerID;
- var StopTimerID;
- var CorrectedData = []; //artist - album - track
- // text buttons array [artist, album, track, tag1, tag2, tag3, tag4, tag5, similar1, similar2, similar3, similar4, similar5]
- var TLs = new Array(
- TL1 = new TextLink(0, 0, 0, 0, function () {}, "", ""),
- TL2 = new TextLink(0, 0, 0, 0, function () {}, "", ""),
- TL3 = new TextLink(0, 0, 0, 0, function () {}, "", ""),
- TLtag1 = new TextLink(0, 0, 0, 0, function () {}, "", ""),
- TLtag2 = new TextLink(0, 0, 0, 0, function () {}, "", ""),
- TLtag3 = new TextLink(0, 0, 0, 0, function () {}, "", ""),
- TLtag4 = new TextLink(0, 0, 0, 0, function () {}, "", ""),
- TLtag5 = new TextLink(0, 0, 0, 0, function () {}, "", ""),
- TLsimilar1 = new TextLink(0, 0, 0, 0, function () {}, "", ""),
- TLsimilar2 = new TextLink(0, 0, 0, 0, function () {}, "", ""),
- TLsimilar3 = new TextLink(0, 0, 0, 0, function () {}, "", ""),
- TLsimilar4 = new TextLink(0, 0, 0, 0, function () {}, "", ""),
- TLsimilar5 = new TextLink(0, 0, 0, 0, function () {}, "", ""),
- TLheart = new TextLink(0, 0, 25, 25, function () {}, "N", "Loved Track"));
- var Tooltip = window.CreateTooltip();
- var TLAnimationTimerID;
- var TLAnimationTimer;
- var EnableTooltip = true;
- var MaxRange;
- var h_link, d_link;
- var StreamFlag = false;
- // Variables}}
- //===========================================================================================================
- //===========================================================================================================
- // foo_silk-lastfm engine
- // http://code.google.com/p/foobar-silk/
- // (C) 2010 by Matthijs Brobbel
- /*
- /////////////////////////////////////////////////////////////////////////
- //### | lastfm_data arrays #########################################
- /////////////////////////////////////////////////////////////////////////
- // | 0 | 1 | 2 | 3 |
- // -----------------------------------------------------------------
- // id: | userinfo | artistinfo | albuminfo | trackinfo |
- // -----------------------------------------------------------------
- // 0: | playcount | playcount | playcount | playcount |
- // 1: | avg_day | userplaycount | userplaycount | userplaycount |
- // 2: | avg_week | listeners | listeners | listeners |
- // 3: | avg_month | tags | 0 | userloved |
- // 4: | joindate | similar | 0 | 0 |
- // 5: | avatar | 0 | 0 | 0 |
- // -----------------------------------------------------------------
- /////////////////////////////////////////////////////////////////////////
- */
- function reset_lastfm_data() {
- for (id = 0; id <= 4; id++) {
- lastfm_data[id] = new Array(4);
- }
- for (id = 0; id <= 3; id++) {
- for (n = 0; n <= 5; n++) {
- lastfm_data[id][n] = 0;
- }
- }
- lastfm_data[1][3] = new Array();
- lastfm_data[1][4] = new Array();
- for (i = 0; i < 5; i++) {
- lastfm_data[1][3][i] = "0";
- lastfm_data[1][4][i] = "0";
- }
- }
- function get_lastfm_data() {
- if (opt_username.length == 0 || opt_api_key.length != 32) {
- window.Repaint();
- } else { //lastfm_status counts here
- contact_lastfm("user.getinfo", 0);
- contact_lastfm("artist.getinfo&artist=" + encodeURIComponent(np[0]) + "&autocorrect=1", 1);
- contact_lastfm("album.getinfo&artist=" + encodeURIComponent(np[0]) + "&album=" + encodeURIComponent(np[1]), 2);
- contact_lastfm("track.getinfo&artist=" + encodeURIComponent(np[0]) + "&track=" + encodeURIComponent(np[2]) + "&autocorrect=1", 3);
- }
- }
- function contact_lastfm(method, id) {
- lastfm_xmlhttp[id] = new ActiveXObject("Msxml2.XMLHTTP.6.0"); //Microsoft.XMLHTTP
- lastfm_xmlhttp[id].open("GET", "http://ws.audioscrobbler.com/2.0?api_key=" + opt_api_key + "&username=" + opt_username + "&user=" + opt_username + "&method=" + method + "&s=" + Math.random(), true);
- lastfm_xmlhttp[id].setRequestHeader('User-Agent', "foo_silk_mod");
- lastfm_xmlhttp[id].send();
- lastfm_xmlhttp[id].onreadystatechange = function () {
- if (lastfm_xmlhttp[id].readyState == 4) { // 'DONE' state
- if (lastfm_xmlhttp[id].status == 200) { //success
- lastfm_status++;
- wait_lastfm_data();
- }
- if (lastfm_xmlhttp[id].status >= 400) { //error statuses
- error_count++;
- lastfm_status++;
- wait_lastfm_data();
- }
- }
- }
- }
- function wait_lastfm_data() {
- if (lastfm_status == 4 && error_count < 4) {
- process_lastfm_data();
- lastfm_status = wait = 0;
- Y_OFFSET = 0;
- error_count = 0;
- return;
- } else if (lastfm_status < 4) {
- wait = 1;
- } else if (error_count == 4) {
- wait = -1;
- error_count = 0;
- window.Repaint();
- }
- }
- function process_lastfm_data() {
- for (id = 0; id < 4; id++) {
- lastfm_xmlDoc[id] = lastfm_xmlhttp[id].responseXML;
- try {
- error = "last.fm API error: " + lastfm_xmlDoc[id].getElementsByTagName("error")[0].childNodes[0].nodeValue;
- } catch (e) {
- error = null;
- }
- }
- // Userinfo
- try {
- lastfm_data[0][0] = lastfm_xmlDoc[0].getElementsByTagName("playcount")[0].childNodes[0].nodeValue;
- username = lastfm_xmlDoc[0].getElementsByTagName("name")[0].childNodes[0].nodeValue;
- } catch (e) {
- lastfm_data[0][0] = "0";
- }
- try {
- lastfm_data[0][4] = lastfm_xmlDoc[0].getElementsByTagName("registered")[0].childNodes[0].nodeValue;
- regdate_error = false;
- } catch (e) {
- regdate_error = true;
- lastfm_data[0][4] = "";
- }
- try {
- lastfm_data[0][5] = lastfm_xmlDoc[0].getElementsByTagName("image")[2].childNodes[0].nodeValue;
- if (avatar_need_refresh) {
- fso = new ActiveXObject("Scripting.FileSystemObject");
- img_avatar.Dispose();
- img_avatar = gdi.Image(images_path + "default_avatar.png");
- WshShell.Run("\"" + fb.FoobarPath + "skins\\Damask\\scripts\\" + "url2disk.exe\"" + " -i " + lastfm_data[0][5] + " -o " + "\"" + settings_dir + "\avatar.jpg\"", 0, true);
- img_avatar = gdi.Image(settings_dir + "avatar.jpg");
- ava_height = img_avatar.height > max_avatar_height ? max_avatar_height : img_avatar.height;
- ava_width = img_avatar.height > max_avatar_height ? max_avatar_height * img_avatar.width / img_avatar.height : img_avatar.width;
- avatar_need_refresh = false;
- }
- } catch (e) {
- lastfm_data[0][5] = "";
- if (avatar_need_refresh) {
- img_avatar.Dispose();
- img_avatar = gdi.Image(images_path + "default_avatar.png");
- ava_height = img_avatar.height > max_avatar_height ? max_avatar_height : img_avatar.height;
- ava_width = img_avatar.height > max_avatar_height ? max_avatar_height * img_avatar.width / img_avatar.height : img_avatar.width;
- avatar_need_refresh = false;
- }
- }
- date = new Date().getTime() / 1;
- if (!regdate_error) {
- try {
- utc = Date.UTC(lastfm_data[0][4].substring(0, 4), (lastfm_data[0][4].substring(5, 7) - 1), lastfm_data[0][4].substring(8, 10), 0, 0, 0);
- } catch (e) {
- utc = 0;
- }
- try {
- lastfm_data[0][1] = "" + Math.round((lastfm_data[0][0] / ((date - utc) / 86400000)) * 100) / 100;
- lastfm_data[0][1] = lastfm_data[0][1].replace(/(\d)(?=(\d\d\d)+([^\d]|$))/g, '$1 ');
- } catch (e) {
- lastfm_data[0][1] = "0";
- };
- try {
- lastfm_data[0][2] = "" + Math.round((lastfm_data[0][0] / ((date - utc) / 604800000)) * 10) / 10;
- lastfm_data[0][2] = lastfm_data[0][2].replace(/(\d)(?=(\d\d\d)+([^\d]|$))/g, '$1 ');
- } catch (e) {
- lastfm_data[0][2] = "0";
- };
- try {
- lastfm_data[0][3] = "" + Math.round((lastfm_data[0][0] / ((date - utc) / 2629743000)) * 1) / 1;
- lastfm_data[0][3] = lastfm_data[0][3].replace(/(\d)(?=(\d\d\d)+([^\d]|$))/g, '$1 ');
- } catch (e) {
- lastfm_data[0][3] = "0";
- };
- } else {
- lastfm_data[0][1] = "0";
- lastfm_data[0][2] = "0";
- lastfm_data[0][3] = "0";
- }
- try {
- lastfm_data[0][0] = lastfm_data[0][0].replace(/(\d)(?=(\d\d\d)+([^\d]|$))/g, '$1 ');
- } catch (e) {
- lastfm_data[0][0] = "0";
- }
- // Artistinfo - Albuminfo - Trackinfo
- for (id = 1; id <= 3; id++) {
- try {
- lastfm_data[id][0] = lastfm_xmlDoc[id].getElementsByTagName("playcount")[0].childNodes[0].nodeValue;
- lastfm_data[id][0] = lastfm_data[id][0].replace(/(\d)(?=(\d\d\d)+([^\d]|$))/g, '$1 ');
- } catch (e) {
- lastfm_data[id][0] = "0";
- }
- try {
- lastfm_data[id][1] = lastfm_xmlDoc[id].getElementsByTagName("userplaycount")[0].childNodes[0].nodeValue;
- lastfm_data[id][1] = lastfm_data[id][1].replace(/(\d)(?=(\d\d\d)+([^\d]|$))/g, '$1 ');
- } catch (e) {
- lastfm_data[id][1] = "0";
- }
- try {
- lastfm_data[id][2] = lastfm_xmlDoc[id].getElementsByTagName("listeners")[0].childNodes[0].nodeValue;
- lastfm_data[id][2] = lastfm_data[id][2].replace(/(\d)(?=(\d\d\d)+([^\d]|$))/g, '$1 ');
- } catch (e) {
- lastfm_data[id][2] = "0";
- }
- switch (id) {
- case 1:
- try {
- CorrectedData[id] = lastfm_xmlDoc[id].getElementsByTagName("name")[0].childNodes[0].nodeValue;
- for (i = 0; i < 5; i++) {
- try {
- lastfm_data[id][3][i] = lastfm_xmlDoc[id].getElementsByTagName("tag")[i].childNodes[0].childNodes[0].nodeValue; //artist tags
- } catch (e) {
- lastfm_data[id][3][i] = "";
- }
- try {
- lastfm_data[id][4][i] = lastfm_xmlDoc[id].getElementsByTagName("artist")[i + 1].childNodes[0].childNodes[0].nodeValue; //similar artists
- } catch (e) {
- lastfm_data[id][4][i] = "no data";
- }
- }
- } catch (e) {
- CorrectedData[id] = "~no data";
- }
- break;
- case 2:
- try {
- CorrectedData[id] = lastfm_xmlDoc[id].getElementsByTagName("name")[0].childNodes[0].nodeValue;
- } catch (e) {
- CorrectedData[id] = "~no data";
- }
- break;
- case 3:
- try {
- CorrectedData[id] = lastfm_xmlDoc[id].getElementsByTagName("name")[0].childNodes[0].nodeValue;
- } catch (e) {
- CorrectedData[id] = "~no data";
- }
- try {
- lastfm_data[id][3] = lastfm_xmlDoc[id].getElementsByTagName("userloved")[0].childNodes[0].nodeValue;
- } catch (e) {
- lastfm_data[id][3] = "0";
- }
- break;
- }
- }
- for (i = 0; i < TLs.length; i++) {
- TLs[i].NeedReset = true;
- }
- window.Repaint();
- }
- //lfm end
- //===========================================================================================================
- //===========================================================================================================
- // Tools {{
- function StringFormat(h_align, v_align, trim, flag) {
- return ((h_align << 28) | (v_align << 24) | (trim << 20) | flag);
- }
- 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));
- }
- //Properties
- function GetProperties() {
- this.Avatar = {
- MaxHeight: window.GetProperty("A01.Avatar.MaxHeight", 100)
- }
- this.Avatar.MaxHeight = Math.min(Math.max(this.Avatar.MaxHeight, 30), 252);
- this.Panel = {
- CursorFollowMode: window.GetProperty("B01.Panel.CursorFollowMode", CursorFollowMode.OnlyStopped),
- }
- this.Panel.CursorFollowMode = Math.max(this.Panel.CursorFollowMode, CursorFollowMode.OnlyStopped);
- this.Panel.CursorFollowMode = Math.min(this.Panel.CursorFollowMode, CursorFollowMode.Always);
- window.SetProperty("B01.Panel.CursorFollowMode", this.Panel.CursorFollowMode);
- }
- // Generate background image.
- function GenerateBG() {
- var img_bg = gdi.CreateImage(ww, wh);
- var g = img_bg.GetGraphics();
- // wallpaper
- g.GdiDrawBitmap(img_main_wallpaper, 0, 0, img_bg.width, img_bg.height, 0, 0, img_bg.width, img_bg.height);
- img_bg_bmp = img_bg.CreateRawBitmap();
- img_bg.ReleaseGraphics(g);
- }
- // Tools }}
- //===================================================================================================================================================
- //timers
- function c_WaitTimer() {
- this.Stop = function () {
- if (WaitTimerID) {
- window.ClearTimeout(WaitTimerID);
- WaitTimerID = null;
- //window.Repaint();
- }
- }
- this.Start = function () {
- WaitTimerID = window.SetTimeout(function () {
- WaitTimerID = null;
- lastfm_status = 0;
- wait = 1;
- MetaDB = fb.GetFocusItem();
- FOCUSFLAG = true;
- if (fb.IsPlaying && fb.PlaybackLength == -1 && fb.GetFocusItem().Path == fb.GetNowPlaying().Path) {
- FOCUSFLAG = false;
- np = [fb.TitleFormat("%artist%").Eval(), fb.TitleFormat("%album%").Eval(), fb.TitleFormat("%title%").Eval()]
- if (np[0] == "?" && np[1] == "?") {
- wait = -2;
- window.Repaint();
- return;
- }
- lastfm_status = 0;
- wait = 1;
- window.Repaint();
- get_lastfm_data();
- } else if (MetaDB) {
- np = [fb.TitleFormat("%artist%").EvalWithMetadb(MetaDB), fb.TitleFormat("%album%").EvalWithMetadb(MetaDB), fb.TitleFormat("%title%").EvalWithMetadb(MetaDB)]
- if (np[0] == "?" && np[1] == "?") {
- wait = -2;
- window.Repaint();
- return;
- }
- lastfm_status = 0;
- wait = 1;
- window.Repaint();
- get_lastfm_data();
- } else {
- wait = -2;
- window.Repaint();
- }
- }, 250);
- }
- }
- function c_ButtonAnimationTimer() {
- this.Stop = function () {
- if (TLAnimationTimerID) {
- window.ClearInterval(TLAnimationTimerID);
- TLAnimationTimerID = null;
- }
- }
- this.Start = function () {
- TLAnimationTimerID = window.SetInterval(function () {
- var NeedRepaint = 0;
- for (var i = 0; i < TLs.length; i++) {
- if (TLs[i].NeedRefresh) {
- TLs[i].RefreshOpacity();
- NeedRepaint += 1;
- Onlybtn = TLs[i]; // If only one button need to be repainted.
- }
- }
- if (NeedRepaint) {
- if (NeedRepaint == 1) window.RepaintRect(Onlybtn.x, Onlybtn.y + Y_OFFSET, Onlybtn.width, Onlybtn.height);
- else window.RepaintRect(MaxRange.x, MaxRange.y, MaxRange.width, MaxRange.height); // This is range of buttons.
- } else {
- TLAnimationTimer.Stop();
- }
- }, 50)
- }
- }
- // VB wrapper {{
- var vb = {};
- vb.Function = function (func) {
- return function () {
- return vb.Function.eval.call(this, func, arguments);
- }
- };
- vb.Function.eval = function (func) {
- var args = Array.prototype.slice.call(arguments[1]);
- for (var i = 0; i < args.length; i++) {
- if (typeof args[i] != 'string') continue;
- args[i] = '"' + args[i].replace(/"/g, '" + Chr(34) + "') + '"';
- }
- var vbe;
- vbe = new ActiveXObject('ScriptControl');
- vbe.Language = 'VBScript';
- return vbe.eval(func + '(' + args.join(', ') + ')');
- };
- var InputBox = vb.Function('InputBox');
- var MsgBox = vb.Function('MsgBox');
- // VB wrapper}}
- //===================================================================================================================================================
- // Options engine {{
- function update_option(optname, optvalue) {
- var fso, f1, ts, s;
- var ForReading = 1;
- var ForWriting = 2;
- fso = new ActiveXObject("Scripting.FileSystemObject");
- // Read the contents of the txt file
- ts = fso.OpenTextFile(settings_dir + optname + ".txt", ForReading);
- s = ts.ReadLine();
- ts.Close();
- // renaming the empty file used after in the PSS with the new value
- f1 = fso.MoveFile(settings_dir + optname + "_" + s, settings_dir + optname + "_" + optvalue);
- // updating the txt file with the new value
- ts = fso.OpenTextFile(settings_dir + optname + ".txt", ForWriting);
- ts.WriteLine(optvalue);
- ts.Close();
- return optvalue;
- }
- function read_option(optname, initvalue) {
- var fso, ts, ts2, s;
- var ForReading = 1;
- var ForWriting = 2;
- fso = new ActiveXObject("Scripting.FileSystemObject");
- if (file_exists(settings_dir + optname + ".txt")) {
- ts = fso.OpenTextFile(settings_dir + optname + ".txt", ForReading);
- s = ts.ReadLine();
- ts.Close();
- return s;
- } else {
- ts = fso.CreateTextFile(settings_dir + optname + ".txt", ForWriting);
- ts.WriteLine(initvalue);
- ts.Close();
- ts2 = fso.CreateTextFile(settings_dir + optname + "_" + initvalue, ForWriting);
- ts2.Close();
- return initvalue;
- }
- }
- function folder_exists(chemin) {
- var fso, bool;
- fso = new ActiveXObject("Scripting.FileSystemObject");
- bool = fso.FolderExists(chemin);
- return bool;
- }
- function file_exists(chemin) {
- var fso, bool;
- fso = new ActiveXObject("Scripting.FileSystemObject");
- bool = fso.Fileexists(chemin);
- return bool;
- }
- // Options engine }}
- // Cursor follow tools {{
- function SetCursorFollowMode(FollowMode) {
- if (FollowMode != Properties.Panel.CursorFollowMode) {
- Properties.Panel.CursorFollowMode = FollowMode;
- window.SetProperty("B01.Panel.CursorFollowMode", FollowMode);
- CursorFollow(FollowMode);
- }
- }
- function CursorFollow(FollowMode) {
- switch (FollowMode) {
- case CursorFollowMode.OnlyStopped:
- if (fb.IsPlaying) on_playback_new_track();
- else on_item_focus_change();
- break;
- case CursorFollowMode.Always:
- on_item_focus_change();
- break;
- }
- }
- // Cursor follow tools }}
- //context menu
- function show_context_menu(x, y) {
- var _menu = window.CreatePopupMenu();
- var _avatar = window.CreatePopupMenu();
- var _followMode = window.CreatePopupMenu();
- var ret;
- if (opt_username.length == 0 || opt_api_key.length != 32) {
- _menu.AppendMenuItem(MF_STRING, 10, "Set your Last.fm username...");
- //_menu.AppendMenuItem(MF_STRING, 11, "Set your API KEY...");
- } else {
- _menu.AppendMenuItem(opt_username.length > 0 && opt_api_key.length == 32 ? MF_STRING : MF_GRAYED, 1, "Update Last.fm Data");
- _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
- _followMode.AppendMenuItem(MF_STRING, 2, "Only Stopped");
- _followMode.AppendMenuItem(MF_STRING, 3, "Always");
- _followMode.CheckMenuRadioItem(2, 3, Properties.Panel.CursorFollowMode);
- _followMode.AppendTo(_menu, MF_STRING, "Cursor follow mode");
- _avatar.AppendMenuItem(MF_STRING, 4, "Download avatar");
- _avatar.AppendMenuItem(MF_STRING, 5, "Restore default avatar");
- _avatar.AppendTo(_menu, MF_STRING, "Avatar");
- _menu.AppendMenuItem(MF_STRING, 6, "Change username");
- //_menu.AppendMenuItem(MF_STRING, 7, "Change API Key");
- _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
- _menu.AppendMenuItem(MF_STRING, 8, "Properties");
- }
- ret = _menu.TrackPopupMenu(x, y);
- switch (ret) {
- case 1:
- lastfm_status = 0;
- wait = 1;
- window.Repaint();
- CursorFollow(Properties.Panel.CursorFollowMode);
- break;
- case 2:
- SetCursorFollowMode(CursorFollowMode.OnlyStopped);
- break;
- case 3:
- SetCursorFollowMode(CursorFollowMode.Always);
- break;
- case 4:
- fso = new ActiveXObject("Scripting.FileSystemObject");
- img_avatar.Dispose();
- img_avatar = gdi.Image(images_path + "default_avatar.png")
- window.Repaint();
- WshShell.Run("\"" + fb.FoobarPath + "skins\\Damask\\scripts\\" + "url2disk.exe\"" + " -i " + lastfm_data[0][5] + " -o " + "\"" + settings_dir + "\avatar.jpg\"", 0, true);
- img_avatar = gdi.Image(settings_dir + "avatar.jpg");
- ava_height = img_avatar.height > max_avatar_height ? max_avatar_height : img_avatar.height;
- ava_width = img_avatar.height > max_avatar_height ? max_avatar_height * img_avatar.width / img_avatar.height : img_avatar.width;
- window.Repaint();
- break;
- case 5:
- img_avatar.Dispose();
- img_avatar = gdi.Image(images_path + "default_avatar.png");
- ava_height = img_avatar.height > max_avatar_height ? max_avatar_height : img_avatar.height;
- ava_width = img_avatar.height > max_avatar_height ? max_avatar_height * img_avatar.width / img_avatar.height : img_avatar.width;
- window.Repaint();
- break;
- case 6:
- opt_username = InputBox("Please enter your Last.fm username", "Last.fm panel", opt_username);
- if (!opt_username) opt_username = "";
- update_option("lastfm_username", opt_username);
- avatar_need_refresh = true;
- CursorFollow(Properties.Panel.CursorFollowMode);
- break;
- case 7:
- opt_api_key = InputBox("Please enter your Last.fm API KEY (http://www.last.fm/api/account)", "Last.fm panel", opt_api_key);
- if (!opt_api_key) opt_api_key = "";
- update_option("lastfm_api_key", opt_api_key);
- CursorFollow(Properties.Panel.CursorFollowMode);
- break;
- case 8:
- window.ShowProperties();
- break;
- case 10:
- opt_username = InputBox("Please enter your Last.fm username", "Last.fm panel", opt_username);
- if (!opt_username) opt_username = "";
- update_option("lastfm_username", opt_username);
- avatar_need_refresh = true;
- CursorFollow(Properties.Panel.CursorFollowMode);
- break;
- case 11:
- opt_api_key = InputBox("Please enter your Last.fm API KEY (http://www.last.fm/api/account)", "Last.fm panel", opt_api_key);
- if (!opt_api_key) opt_api_key = "";
- update_option("lastfm_api_key", opt_api_key);
- CursorFollow(Properties.Panel.CursorFollowMode);
- break;
- }
- _menu.Dispose();
- _avatar.Dispose();
- _followMode.Dispose();
- return true;
- }
- // button class
- function TextLink(x, y, width, height, fn_onclick, label, tiptext) {
- this.x = x;
- this.y = y;
- this.width = width;
- this.height = height;
- this.label = label;
- this.tiptext = tiptext;
- this.TestProp = "";
- this.NeedRefresh = 0;
- this.oldstate = 0; // 0=normal, 1=hover, 2=down.
- this.state = 0;
- this.opacity = 0; // Opacity of new state image.
- this.step = 0;
- this.show = true;
- this.NeedReset = false;
- this.OnClick = fn_onclick;
- this.ChangeState = function (s) {
- this.oldstate = this.state;
- this.state = s;
- this.opacity = 0;
- this.NeedRefresh = 1;
- switch (s) {
- case 0:
- this.step = 40; // Step of changing to normal state.
- Tooltip.Deactivate();
- Tooltip.Text = "";
- break;
- case 1:
- this.step = 75; // hover state.
- if (EnableTooltip) {
- Tooltip.Text = this.tiptext;
- Tooltip.Activate();
- }
- break;
- case 2:
- this.step = 85; // down state.
- Tooltip.Deactivate();
- Tooltip.Text = "";
- break;
- }
- if (!TLAnimationTimerID) // start animation
- TLAnimationTimer.Start();
- }
- this.isXYok = function (x2, y2) {
- return (x2 >= this.x && y2 >= this.y + Y_OFFSET && x2 <= this.x + this.width && y2 <= this.y + Y_OFFSET + this.height) ? true : false;
- }
- this.Draw = function (x2, y2, gr) {
- x2 = this.x; //disabled
- y2 = this.y; //disabled
- if (this.opacity < 255) {
- switch (this.oldstate) {
- case 0:
- gr.FillSolidRect(this.x, this.y + Y_OFFSET, this.width, this.height, RGBA(20, 20, 20, 255));
- gr.DrawString(this.label, font_normal, normal_color, this.x + 4, this.y + Y_OFFSET, this.width - 4, this.height, LineStrFmt);
- break;
- case 1:
- gr.FillSolidRect(this.x, this.y + Y_OFFSET, this.width, this.height, RGBA(30, 30, 30, 255));
- gr.DrawString(this.label, font_normal, hover_color, this.x + 4, this.y + Y_OFFSET, this.width - 4, this.height, LineStrFmt);
- break;
- case 2:
- gr.FillSolidRect(this.x, this.y + Y_OFFSET, this.width, this.height, RGBA(36, 36, 36, 255));
- gr.DrawString(this.label, font_normal, hover_color, this.x + 4, this.y + Y_OFFSET, this.width - 4, this.height, LineStrFmt);
- break;
- default:
- break;
- }
- }
- if (this.opacity) {
- switch (this.state) {
- case 0:
- gr.FillSolidRect(this.x, this.y + Y_OFFSET, this.width, this.height, RGBA(20, 20, 20, this.opacity));
- gr.DrawString(this.label, font_normal, normal_color, this.x + 4, this.y + Y_OFFSET, this.width, this.height, LineStrFmt);
- break;
- case 1:
- gr.FillSolidRect(this.x, this.y + Y_OFFSET, this.width, this.height, RGBA(30, 30, 30, this.opacity));
- gr.DrawString(this.label, font_normal, hover_color, this.x + 4, this.y + Y_OFFSET, this.width, this.height, LineStrFmt);
- break;
- case 2:
- gr.FillSolidRect(this.x, this.y + Y_OFFSET, this.width, this.height, RGBA(36, 36, 36, this.opacity));
- gr.DrawString(this.label, font_normal, hover_color, this.x + 4, this.y + Y_OFFSET, this.width, this.height, LineStrFmt);
- break;
- }
- }
- }
- this.RefreshOpacity = function (fn) {
- if (this.opacity < 255) this.opacity = Math.min(this.opacity + this.step, 255);
- else {
- this.oldstate = this.state;
- this.opacity = 0;
- this.NeedRefresh = 0;
- }
- }
- }
- function GetCoordinates() {
- // Calculate the max range of buttons, for increasing refresh speed.
- MaxRange = {
- x: TLs[0].x,
- y: TLs[0].y + Y_OFFSET,
- width: TLs[0].width,
- height: TLs[0].height
- }
- for (var i = 1; i < TLs.length - 1; i++) {
- if (TLs[i].show) {
- MaxRange.x = Math.min(TLs[i].x, MaxRange.x);
- MaxRange.y = Math.min(TLs[i].y + Y_OFFSET, MaxRange.y);
- MaxRange.width = Math.max(TLs[i].x + TLs[i].width - MaxRange.x, MaxRange.width);
- MaxRange.height = Math.max(TLs[i].y + Y_OFFSET + TLs[i].height - MaxRange.y, MaxRange.height);
- }
- }
- }
- // Scrollbar tools {{
- var scrollpos;
- var scrollmax;
- var ratio;
- var NeedScrollbar;
- var slider_hover;
- var slider_y_rel;
- var slider_drag;
- function SetSlider() {
- if (sum_height < wh) {
- if (Y_OFFSET != 0) {
- Y_OFFSET = 0;
- }
- NeedScrollbar = false;
- return;
- } else {
- NeedScrollbar = true;
- scrollmax = sum_height + tm - wh;
- scrollpos = -1 * Y_OFFSET;
- ratio = wh / (sum_height + tm); // какая часть = страница от всего док.
- if (ratio > 1) ratio = 1;
- Scrollbar.step = 1 / ratio;
- Scrollbar.slider.height = Math.round(ratio * wh);
- if (Scrollbar.slider.height < Scrollbar.min_height) {
- Scrollbar.slider.height = Scrollbar.min_height;
- }
- Scrollbar.slider.y = Math.round((wh - Scrollbar.slider.height) * scrollpos / scrollmax);
- Scrollbar.slider.x = ww - 18;
- Scrollbar.slider.width = 16;
- if (Y_OFFSET < -1 * (sum_height - wh + tm)) {
- Y_OFFSET = -1 * (sum_height - wh + tm);
- }
- }
- }
- function V_SCROLLBAR(width, min_h) {
- this.width = width;
- this.step = 0;
- this.state = 0;
- this.slider = {
- x: 0,
- y: 0,
- width: 0,
- height: 0,
- min_height: min_h
- }
- this.isXYok = function (x, y) {
- return (x >= ww - 20 && y >= 0 && x <= ww && y <= wh) ? true : false;
- }
- this.slider_isXYok = function (x, y) {
- return (x >= this.slider.x && y >= this.slider.y && x <= this.slider.x + this.slider.width && y <= this.slider.y + this.slider.height) ? true : false;
- }
- this.Draw = function (gr) {
- if (NeedScrollbar) {
- //bg
- gr.DrawRect(ww - 20, 0, 19, wh - 1, 1, RGB(20, 20, 20));
- gr.FillSolidRect(ww - 19, 1, 18, wh - 2, vs_bg_color);
- //slider
- gr.FillSolidRect(this.slider.x, this.slider.y, this.slider.width, this.slider.height, (slider_drag) ? vs_down_color : (slider_hover ? vs_hover_color : vs_normal_color));
- gr.DrawRect(this.slider.x, this.slider.y, this.slider.width - 1, this.slider.height - 1, 1, RGB(25, 25, 25));
- }
- }
- }
- // Scrollbar tools }}
- //===================================================================================================================================================
- //===================================================================================================================================================
- function on_init() {
- Scrollbar = new V_SCROLLBAR(20, 45);
- WaitTimer = new c_WaitTimer();
- TLAnimationTimer = new c_ButtonAnimationTimer();
- update_option("lastfm_api_key", "179b25d95e633097ec682c58b4a993ec");
- reset_lastfm_data();
- //WaitTimer.Start();
- }
- on_init();
- function on_size() {
- if (!window.Width || !window.Height) return;
- ww = window.Width;
- wh = window.Height;
- SetSlider();
- GetCoordinates();
- CursorFollow(Properties.Panel.CursorFollowMode);
- GenerateBG();
- }
- function on_paint(gr) {
- //don't draw if panel sizes are less than min values
- if (window.Width < 185 || window.Height < 100) {
- if (img_bg_bmp) gr.GdiDrawBitmap(img_bg_bmp, 0, 0, ww, wh, 0, 0, img_bg_bmp.width, img_bg_bmp.height);
- return;
- }
- sum_height = 0;
- gr.SetTextRenderingHint(5);
- // Draw background image.
- if (img_bg_bmp) gr.GdiDrawBitmap(img_bg_bmp, 0, 0, ww, wh, 0, 0, img_bg_bmp.width, img_bg_bmp.height);
- if (opt_username.length == 0 || opt_api_key.length != 32) {
- gr.GdiDrawText("Last.fm panel \n Please enter your username with context menu", font_normal, normal_color, 0, 0, ww, wh, DT_CENTER | DT_VCENTER | DT_CALCRECT | DT_NOPREFIX);
- return;
- }
- if (wait == 0) {
- //draw last.fm logo
- gr.FillSolidRect(0, tm + Y_OFFSET, ww, 30, RGBA(210, 19, 9, 255));
- gr.DrawImage(img_lastfm_logo_red, (ww - 100) / 2, tm + Y_OFFSET, 100, 30, 0, 0, 900, 269);
- //draw user avatar
- gr.DrawImage(img_avatar, lm, tm + 30 + tm + Y_OFFSET, ava_width, ava_height, 0, 0, img_avatar.width, img_avatar.height);
- sum_height += ava_height < 100 ? tm + 30 + tm + 100 : tm + 30 + tm + ava_height;
- gr.DrawRect(lm, tm + 30 + tm + Y_OFFSET, ava_width, ava_height, 2, normal_color);
- //draw username
- if (ww >= 175 + ava_width) {
- gr.GdiDrawText(username != "" ? username : opt_username, font_header, normal_color, lm + ava_width + 15, 45 + Y_OFFSET, ww, wh);
- } else {
- gr.GdiDrawText(username != "" ? username : opt_username, font_header, normal_color, lm, sum_height + 5 + Y_OFFSET, ww, wh);
- sum_height += font_header.height + 9;
- }
- // plays ========================================================================================================================================================================================
- for (i = 0; i <= 3; i++) {
- charcounter = 0;
- spcounter = 0;
- switch (i) {
- case 0:
- txt_plays = " plays";
- break;
- case 1:
- txt_plays = " per day";
- break;
- case 2:
- txt_plays = " per week";
- break;
- case 3:
- txt_plays = " per month";
- break;
- }
- if (longeststr.length < lastfm_data[0][i].length) longeststr = lastfm_data[0][i];
- if (ww >= 175 + ava_width) {
- for (j = 0; j < lastfm_data[0][i].length; j++) {
- if (lastfm_data[0][i].substring((j), j + 1) != " ") {
- gr.DrawImage(img_lastfm_flip, lm + ava_width + 15 + charcounter * 11 + spcounter * 5, 70 + (i * 15) + Y_OFFSET, img_lastfm_flip.width, img_lastfm_flip.height, 0, 0, img_lastfm_flip.width, img_lastfm_flip.height);
- charcounter++;
- } else {
- spcounter++;
- }
- gr.GdiDrawText(lastfm_data[0][i].substring((j), j + 1), font_num, RGB(255, 255, 255), lm + ava_width + 17 + (charcounter - 1) * 11 + spcounter * 5, 69 + (i * 15) + Y_OFFSET, ww, wh, DT_TOP | DT_LEFT);
- }
- gr.GdiDrawText(txt_plays, font_num, normal_color, lm + ava_width + 15 + charcounter * 11 + spcounter * 5 + 3, 69 + (i * 15) + Y_OFFSET, ww, wh, DT_TOP | DT_LEFT);
- } else {
- for (j = 0; j < lastfm_data[0][i].length; j++) {
- if (lastfm_data[0][i].substring((j), j + 1) != " ") {
- gr.DrawImage(img_lastfm_flip, lm + charcounter * 11 + spcounter * 5, sum_height + Y_OFFSET, img_lastfm_flip.width, img_lastfm_flip.height, 0, 0, img_lastfm_flip.width, img_lastfm_flip.height);
- charcounter++;
- } else {
- spcounter++;
- }
- gr.GdiDrawText(lastfm_data[0][i].substring((j), j + 1), font_num, RGB(255, 255, 255), lm + 2 + (charcounter - 1) * 11 + spcounter * 5, sum_height - 1 + Y_OFFSET, ww, wh, DT_TOP | DT_LEFT);
- }
- gr.GdiDrawText(txt_plays, font_num, normal_color, lm + charcounter * 11 + spcounter * 5 + 3, sum_height - 1 + Y_OFFSET, ww, wh, DT_TOP | DT_LEFT);
- sum_height += img_lastfm_flip.height + 3;
- }
- }
- //========================================================================================================================================================================================
- gr.GdiDrawText("Current track", font_header, normal_color, lm, sum_height + 6 + Y_OFFSET, ww, wh);
- // artist - album - track ========================================================================================================================================================================================
- if (lastfm_data[3][3] == "1") { //userloved
- TLs[13].x = 105;
- TLs[13].y = sum_height + 6;
- TLs[13].Draw = function (gr) {
- gr.GdiDrawText(TLs[13].label, font_gui, normal_color, TLs[13].x, TLs[13].y + Y_OFFSET, TLs[13].width, TLs[13].height);
- }
- TLs[13].Draw(gr);
- } else {
- TLs[13].x = ww + 10;
- }
- sum_height += font_header.height + 17;
- for (i = 0; i < 3; i++) {
- TLs[i].y = sum_height;
- if (TLs[i].NeedReset) {
- if (CorrectedData[i + 1] != "~no data") {
- text_Ws[i] = Math.ceil(gr.MeasureString(CorrectedData[i + 1] == np[i] ? np[i] : CorrectedData[i + 1] + " [*]", font_normal, 0, 0, ww - 50 - lm - rm - 20, wh, LineStrFmt).Width);
- text_Hs[i] = Math.ceil(gr.MeasureString(CorrectedData[i + 1] == np[i] ? np[i] : CorrectedData[i + 1] + " [*]", font_normal, 0, 0, ww - 50 - lm - rm - 20, wh, LineStrFmt).Height);
- switch (i) {
- case 0:
- TLs[i].OnClick = function () {
- WshShell.run("http://www.last.fm/music/" + encodeURIComponent(CorrectedData[1]))
- };
- break;
- case 1:
- TLs[i].OnClick = function () {
- WshShell.run("http://www.last.fm/music/" + encodeURIComponent(CorrectedData[1]) + "/" + encodeURIComponent(CorrectedData[2]))
- };
- break;
- case 2:
- TLs[i].OnClick = function () {
- WshShell.run("http://www.last.fm/music/" + encodeURIComponent(CorrectedData[1]) + "/" + encodeURIComponent(CorrectedData[2]) + "/" + encodeURIComponent(CorrectedData[3]))
- };
- break;
- }
- TLs[i].x = 50 + lm;
- TLs[i].width = text_Ws[i] + 8;
- TLs[i].height = text_Hs[i];
- TLs[i].label = CorrectedData[i + 1] == np[i] ? np[i] : CorrectedData[i + 1] + " [*]";
- TLs[i].tiptext = CorrectedData[i + 1] == np[i] ? "" : "Auto-corrected from: " + "'" + np[i] + "'";
- TLs[i].NeedReset = false;
- } else {
- text_Ws[i] = Math.ceil(gr.MeasureString(np[i], font_normal, 0, 0, ww - 50 - lm - rm - 20, wh, LineStrFmt).Width);
- text_Hs[i] = Math.ceil(gr.MeasureString(np[i], font_normal, 0, 0, ww - 50 - lm - rm - 20, wh, LineStrFmt).Height);
- switch (i) {
- case 0:
- TLs[i].OnClick = function () {
- WshShell.run("http://www.last.fm/music/" + encodeURIComponent(np[0]))
- };
- break;
- case 1:
- TLs[i].OnClick = function () {
- WshShell.run("http://www.last.fm/music/" + encodeURIComponent(np[0]) + "/" + encodeURIComponent(np[1]))
- };
- break;
- case 2:
- TLs[i].OnClick = function () {
- WshShell.run("http://www.last.fm/music/" + encodeURIComponent(np[0]) + "/" + encodeURIComponent(np[1]) + "/" + encodeURIComponent(np[2]))
- };
- break;
- }
- TLs[i].x = 50 + lm;
- TLs[i].width = text_Ws[i] + 8;
- TLs[i].height = text_Hs[i];
- TLs[i].label = np[i];
- TLs[i].tiptext = "";
- TLs[i].NeedReset = false;
- }
- }
- if (TLs[i].label != "?") TLs[i].Draw(TLs[i].x, TLs[i].y, gr);
- else {
- TLs[i].show = false;
- gr.DrawString("No data", font_normal, normal_color, TLs[i].x + 4, TLs[i].y + Y_OFFSET, ww, TLs[i].height, LineStrFmt);
- }
- switch (i) {
- case 0:
- txt_t = "Artist:";
- break;
- case 1:
- txt_t = "Album:";
- break;
- case 2:
- txt_t = "Track:";
- break;
- }
- gr.GdiDrawText(txt_t, font_label, normal_color, lm, sum_height + 2 + Y_OFFSET, 50, wh);
- sum_height += text_Hs[i] + 3;
- }
- sum_height += 3;
- // tags ========================================================================================================================================================================================
- gr.GdiDrawText("Artist", font_label, normal_color, lm, sum_height + 2 + Y_OFFSET, 50, wh);
- gr.GdiDrawText("tags:", font_label, normal_color, lm, sum_height + 2 + font_label.height + Y_OFFSET, 50, wh);
- linecounter = 1;
- if (lastfm_data[1][3][0] != "no data") {
- for (i = 0; i < 5; i++) {
- text_Ws[i + 3] = Math.ceil(gr.MeasureString(lastfm_data[1][3][i], font_normal, 0, 0, ww - 50 - lm - rm - 20, wh, LineStrFmt).Width);
- text_Hs[i + 3] = Math.ceil(gr.MeasureString(lastfm_data[1][3][i], font_normal, 0, 0, ww - 50 - lm - rm - 20, wh, LineStrFmt).Height);
- TLs[i + 3].x = i == 0 ? 50 + lm : (TLs[i + 2].x + text_Ws[i + 2] + 8 + text_Ws[i + 3] + 8 + 1 < ww - rm - 20 ? TLs[i + 2].x + text_Ws[i + 2] + 11 : 50 + lm);
- TLs[i + 3].y = i == 0 ? sum_height : (TLs[i + 2].x + text_Ws[i + 2] + 8 + text_Ws[i + 3] + 8 + 1 < ww - rm - 20 ? TLs[i + 2].y : sum_height + font_normal.height + 3);
- linecounter += (TLs[i + 2].x + text_Ws[i + 2] + 8 + text_Ws[i + 3] + 8 + 1 < ww - rm - 20) || i == 0 ? 0 : 1;
- if (TLs[i + 3].NeedReset) {
- switch (i) {
- case 0:
- TLs[i + 3].OnClick = function () {
- WshShell.run("http://www.last.fm/tag/" + encodeURIComponent(lastfm_data[1][3][0]))
- };
- break;
- case 1:
- TLs[i + 3].OnClick = function () {
- WshShell.run("http://www.last.fm/tag/" + encodeURIComponent(lastfm_data[1][3][1]))
- };
- break;
- case 2:
- TLs[i + 3].OnClick = function () {
- WshShell.run("http://www.last.fm/tag/" + encodeURIComponent(lastfm_data[1][3][2]))
- };
- break;
- case 3:
- TLs[i + 3].OnClick = function () {
- WshShell.run("http://www.last.fm/tag/" + encodeURIComponent(lastfm_data[1][3][3]))
- };
- break;
- case 4:
- TLs[i + 3].OnClick = function () {
- WshShell.run("http://www.last.fm/tag/" + encodeURIComponent(lastfm_data[1][3][4]))
- };
- break;
- }
- TLs[i + 3].width = text_Ws[i + 3] + 8;
- TLs[i + 3].height = text_Hs[i + 3];
- TLs[i + 3].label = lastfm_data[1][3][i];
- TLs[i + 3].tiptext = "";
- TLs[i + 3].NeedReset = false;
- }
- TLs[i + 3].Draw(0, 0, gr);
- if (i == 0) sum_height += gr.MeasureString(lastfm_data[1][3][i], font_normal, 0, 0, ww - 50 - lm - rm - 20, wh, LineStrFmt).lines > 1 ? text_Hs[i + 3] - font_normal.height : 0;
- else sum_height += (TLs[i + 2].x + text_Ws[i + 2] + 8 + text_Ws[i + 3] + 8 + 1 < ww - rm - 20) ? 0 : text_Hs[i + 3] + 3;
- }
- } else {
- for (i = 0; i < 5; i++) {
- TLs[i + 3].show = false;
- }
- gr.GdiDrawText("Tags did not recieved", font_normal, normal_color, lm + 50, sum_height + 2 + Y_OFFSET, ww, wh);
- }
- sum_height += linecounter == 1 ? font_normal.height * 2 + 6 : font_normal.height + 6;
- // similar ========================================================================================================================================================================================
- gr.GdiDrawText("Similar", font_label, normal_color, lm, sum_height + 2 + Y_OFFSET, 50, wh);
- gr.GdiDrawText("artists:", font_label, normal_color, lm, sum_height + 2 + font_label.height + Y_OFFSET, 50, wh);
- linecounter = 1;
- if (lastfm_data[1][4][0] != "no data") {
- for (i = 0; i < 5; i++) {
- text_Ws[i + 8] = Math.ceil(gr.MeasureString(lastfm_data[1][4][i], font_normal, 0, 0, ww - 50 - lm - rm - 20, wh, LineStrFmt).Width);
- text_Hs[i + 8] = Math.ceil(gr.MeasureString(lastfm_data[1][4][i], font_normal, 0, 0, ww - 50 - lm - rm - 20, wh, LineStrFmt).Height);
- TLs[i + 8].x = i == 0 ? 50 + lm : (TLs[i + 7].x + text_Ws[i + 7] + 8 + text_Ws[i + 8] + 8 + 1 < ww - rm - 20 ? TLs[i + 7].x + text_Ws[i + 7] + 11 : 50 + lm);
- TLs[i + 8].y = i == 0 ? sum_height : (TLs[i + 7].x + text_Ws[i + 7] + 8 + text_Ws[i + 8] + 8 + 1 < ww - rm - 20 ? TLs[i + 7].y : sum_height + font_normal.height + 3);
- linecounter += (TLs[i + 7].x + text_Ws[i + 7] + 8 + text_Ws[i + 8] + 8 + 1 < ww - rm - 20) || i == 0 ? 0 : 1;
- if (TLs[i + 8].NeedReset) {
- switch (i) {
- case 0:
- TLs[i + 8].OnClick = function () {
- WshShell.run("http://www.last.fm/music/" + encodeURIComponent(lastfm_data[1][4][0]))
- };
- break;
- case 1:
- TLs[i + 8].OnClick = function () {
- WshShell.run("http://www.last.fm/music/" + encodeURIComponent(lastfm_data[1][4][1]))
- };
- break;
- case 2:
- TLs[i + 8].OnClick = function () {
- WshShell.run("http://www.last.fm/music/" + encodeURIComponent(lastfm_data[1][4][2]))
- };
- break;
- case 3:
- TLs[i + 8].OnClick = function () {
- WshShell.run("http://www.last.fm/music/" + encodeURIComponent(lastfm_data[1][4][3]))
- };
- break;
- case 4:
- TLs[i + 8].OnClick = function () {
- WshShell.run("http://www.last.fm/music/" + encodeURIComponent(lastfm_data[1][4][4]))
- };
- break;
- }
- TLs[i + 8].width = text_Ws[i + 8] + 8;
- TLs[i + 8].height = text_Hs[i + 8];
- TLs[i + 8].label = lastfm_data[1][4][i];
- TLs[i + 8].tiptext = "";
- TLs[i + 8].NeedReset = false;
- }
- TLs[i + 8].Draw(0, 0, gr);
- if (i == 0) sum_height += gr.MeasureString(lastfm_data[1][4][i], font_normal, 0, 0, ww - 50 - lm - rm - 20, wh, LineStrFmt).lines > 1 ? text_Hs[i + 8] - font_normal.height : 0;
- else sum_height += (TLs[i + 7].x + text_Ws[i + 7] + 8 + text_Ws[i + 8] + 8 + 1 < ww - rm - 20) ? 0 : text_Hs[i + 8] + 3;
- }
- } else {
- for (i = 0; i < 5; i++) {
- TLs[i + 8].show = false;
- }
- gr.GdiDrawText("Artists did not recieved", font_normal, normal_color, lm + 50, sum_height + 2 + Y_OFFSET, ww, wh);
- }
- sum_height += linecounter == 1 ? font_normal.height * 2 + 2 : font_normal.height + 2;
- GetCoordinates(); //run this when all buttons are resetted
- // listeners ========================================================================================================================================================================================
- gr.GdiDrawText("Listeners", font_header, normal_color, lm, sum_height + Y_OFFSET, ww, wh);
- sum_height += font_header.height + 5;
- for (id = 1; id <= 3; id++) {
- charcounter = 0;
- spcounter = 0;
- for (j = 0; j < lastfm_data[id][2].length; j++) {
- if (lastfm_data[id][2].substring((j), j + 1) != " ") {
- gr.DrawImage(img_lastfm_flip, lm + 50 + charcounter * 11 + spcounter * 5, sum_height + Y_OFFSET, img_lastfm_flip.width, img_lastfm_flip.height, 0, 0, img_lastfm_flip.width, img_lastfm_flip.height);
- charcounter++;
- } else {
- spcounter++;
- }
- gr.GdiDrawText(lastfm_data[id][2].substring((j), j + 1), font_num, RGB(255, 255, 255), lm + (charcounter - 1) * 11 + spcounter * 5 + 2 + 50, sum_height - 1 + Y_OFFSET, ww, wh);
- }
- switch (id) {
- case 1:
- txt_t = "Artist:";
- break;
- case 2:
- txt_t = "Album:";
- break;
- case 3:
- txt_t = "Track:";
- break;
- }
- gr.GdiDrawText(txt_t, font_label, normal_color, lm, sum_height - 1 + Y_OFFSET, ww, wh);
- sum_height += 18;
- }
- // plays ========================================================================================================================================================================================
- gr.GdiDrawText("Plays", font_header, normal_color, lm, sum_height + Y_OFFSET, ww, wh);
- sum_height += font_header.height + 5;
- for (id = 1; id <= 3; id++) {
- charcounter = 0;
- spcounter = 0;
- for (j = 0; j < lastfm_data[id][0].length; j++) {
- if (lastfm_data[id][0].substring((j), j + 1) != " ") {
- gr.DrawImage(img_lastfm_flip, lm + 50 + charcounter * 11 + spcounter * 5, sum_height + Y_OFFSET, img_lastfm_flip.width, img_lastfm_flip.height, 0, 0, img_lastfm_flip.width, img_lastfm_flip.height);
- charcounter++;
- } else {
- spcounter++;
- }
- gr.GdiDrawText(lastfm_data[id][0].substring((j), j + 1), font_num, RGB(255, 255, 255), lm + (charcounter - 1) * 11 + spcounter * 5 + 2 + 50, sum_height - 1 + Y_OFFSET, ww, wh);
- }
- switch (id) {
- case 1:
- txt_tt = "Artist:";
- break;
- case 2:
- txt_tt = "Album:";
- break;
- case 3:
- txt_tt = "Track:";
- break;
- }
- gr.GdiDrawText(txt_tt, font_label, normal_color, lm, sum_height - 1 + Y_OFFSET, ww, wh);
- sum_height += 18;
- }
- // by user ========================================================================================================================================================================================
- gr.GdiDrawText(username != "" ? "Plays by " + username : "Plays by " + opt_username, font_header, normal_color, lm, sum_height + Y_OFFSET, ww, wh);
- sum_height += font_header.height + 5;
- for (id = 1; id <= 3; id++) {
- charcounter = 0;
- spcounter = 0;
- for (j = 0; j < lastfm_data[id][1].length; j++) {
- if (lastfm_data[id][1].substring((j), j + 1) != " ") {
- gr.DrawImage(img_lastfm_flip, lm + 50 + charcounter * 11 + spcounter * 5, sum_height + Y_OFFSET, img_lastfm_flip.width, img_lastfm_flip.height, 0, 0, img_lastfm_flip.width, img_lastfm_flip.height);
- charcounter++;
- } else {
- spcounter++;
- }
- gr.GdiDrawText(lastfm_data[id][1].substring((j), j + 1), font_num, RGB(255, 255, 255), lm + (charcounter - 1) * 11 + spcounter * 5 + 2 + 50, sum_height - 1 + Y_OFFSET, ww, wh);
- }
- switch (id) {
- case 1:
- txt_tt = "Artist:";
- break;
- case 2:
- txt_tt = "Album:";
- break;
- case 3:
- txt_tt = "Track:";
- break;
- }
- gr.GdiDrawText(txt_tt, font_label, normal_color, lm, sum_height - 1 + Y_OFFSET, ww, wh);
- sum_height += 18;
- }
- } else if (wait == 1) {
- gr.GdiDrawText("Grabbing last.fm data.\n Hold on!", font_normal, normal_color, 0, 0, ww, wh, DT_CENTER | DT_VCENTER | DT_CALCRECT | DT_NOPREFIX);
- return;
- } else if (wait == -1) {
- gr.GdiDrawText("Artist: " + np[0] + "\n Album: " + np[1] + "\n Track: " + np[2] + "\n \n Something went wrong :( \n Data did not recieved.", font_normal, normal_color, 0, 0, ww, wh, DT_CENTER | DT_VCENTER | DT_CALCRECT | DT_NOPREFIX);
- } else if (wait == -2) {
- gr.GdiDrawText("No track specified", font_normal, normal_color, 0, 0, ww, wh, DT_CENTER | DT_VCENTER | DT_CALCRECT | DT_NOPREFIX);
- }
- //draw vscrollbar
- SetSlider();
- Scrollbar.Draw(gr);
- }
- function on_playback_new_track() {
- if (Properties.Panel.CursorFollowMode == CursorFollowMode.OnlyStopped) {
- if (fb.IsPlaying && fb.PlaybackLength == -1) {
- np = [fb.TitleFormat("%artist%").Eval(), fb.TitleFormat("%album%").Eval(), fb.TitleFormat("%title%").Eval()]
- } else {
- MetaDB = fb.GetNowPlaying();
- FOCUSFLAG = false;
- np = [fb.TitleFormat("%artist%").EvalWithMetadb(MetaDB), fb.TitleFormat("%album%").EvalWithMetadb(MetaDB), fb.TitleFormat("%title%").EvalWithMetadb(MetaDB)]
- }
- WaitTimer.Stop();
- if (np[0] == "?" && np[1] == "?") {
- wait = -2;
- window.Repaint();
- return;
- }
- lastfm_status = 0;
- wait = 1;
- window.Repaint();
- get_lastfm_data();
- }
- }
- function on_playback_dynamic_info_track() {
- if (fb.PlaybackLength == -1) {
- FOCUSFLAG = false;
- np = [fb.TitleFormat("%artist%").Eval(), fb.TitleFormat("%album%").Eval(), fb.TitleFormat("%title%").Eval()]
- if (np[0] == "?" && np[1] == "?") {
- wait = -2;
- window.Repaint();
- return;
- }
- lastfm_status = 0;
- wait = 1;
- window.Repaint();
- get_lastfm_data();
- }
- }
- function on_item_focus_change() {
- if (Properties.Panel.CursorFollowMode == CursorFollowMode.Always || (Properties.Panel.CursorFollowMode == CursorFollowMode.OnlyStopped && !fb.IsPlaying && !fb.IsPaused)) {
- WaitTimer.Stop();
- WaitTimer.Start();
- }
- }
- function on_playback_stop(reason) {
- if (!reason || reason == 1) {
- if (Properties.Panel.CursorFollowMode == CursorFollowMode.OnlyStopped && !FOCUSFLAG) {
- WaitTimer.Stop();
- WaitTimer.Start();
- }
- }
- }
- function on_mouse_move(x, y) {
- if (window.Width < 185 || window.Height < 100) return;
- if (wait != 0) return;
- if (slider_drag) {
- Scrollbar.slider.y = Math.min(Math.max(y - slider_y_rel, 0), wh - Scrollbar.slider.height);
- Y_OFFSET = Math.round(Math.min(Math.max(-1 * Scrollbar.step * Scrollbar.slider.y, -1 * scrollmax), 0));
- window.Repaint();
- } else {
- if (Scrollbar.slider_isXYok(x, y)) {
- if (!slider_hover && !d_link) slider_hover = true;
- window.RepaintRect(ww - 20, 0, ww, wh);
- } else if (slider_hover) {
- slider_hover = false;
- window.RepaintRect(ww - 20, 0, ww, wh);
- }
- }
- if (d_link) {
- if (d_link.isXYok(x, y)) {
- if (d_link.state != 2) d_link.ChangeState(2);
- } else if (d_link.state != 1) d_link.ChangeState(1);
- } else {
- for (var i = 0; i < TLs.length; i++)
- if (TLs[i].isXYok(x, y) && TLs[i].show) {
- if (h_link != TLs[i]) {
- if (h_link) h_link.ChangeState(0);
- h_link = TLs[i];
- if (h_link != TLs[13]) window.SetCursor(IDC_HAND);
- h_link.ChangeState(1);
- }
- break;
- }
- if (i == TLs.length) {
- if (h_link) {
- if (h_link) h_link.ChangeState(0);
- h_link = undefined;
- window.SetCursor(IDC_ARROW);
- }
- }
- }
- }
- function on_mouse_lbtn_down(x, y) {
- if (window.Width < 185 || window.Height < 100) return;
- if (h_link && !d_link) {
- d_link = h_link;
- d_link.ChangeState(2);
- }
- if (NeedScrollbar) {
- if (slider_hover && !slider_drag && !d_link) {
- slider_drag = true;
- slider_y_rel = y - Scrollbar.slider.y;
- } else if (!slider_hover && !slider_drag && !d_link && Scrollbar.isXYok(x, y)) {
- slider_drag = true;
- slider_y_rel = Scrollbar.slider.height / 2;
- on_mouse_move(x, y);
- }
- }
- }
- function on_mouse_lbtn_up(x, y) {
- if (window.Width < 185 || window.Height < 100) return;
- if (d_link) {
- if (d_link.state == 2) {
- d_link.OnClick();
- }
- d_link = undefined;
- on_mouse_move(x, y);
- }
- if (slider_drag) {
- slider_drag = false;
- }
- }
- function on_mouse_leave() {
- if (window.Width < 185 || window.Height < 100) return;
- if (h_link) {
- h_link.ChangeState(0);
- h_link = undefined;
- window.SetCursor(IDC_ARROW);
- }
- Tooltip.Text = "";
- if (slider_hover) {
- slider_hover = false;
- window.RepaintRect(ww - 20, 0, ww, wh);
- }
- }
- function on_mouse_wheel(delta) {
- if (window.Width < 185 || window.Height < 100) return;
- if (NeedScrollbar && !d_link && !slider_drag) {
- Y_OFFSET = Math.min(Math.max(Y_OFFSET + delta * 35, -1 * scrollmax), 0);
- on_mouse_move();
- window.Repaint();
- }
- }
- function on_mouse_rbtn_down(x, y, vkey) {
- rbtnDown = true;
- }
- function on_mouse_rbtn_up(x, y, vkey) {
- if (window.Width < 185 || window.Height < 100) return false;
- if (rbtnDown) {
- rbtnDown = false;
- if (vkey == MK_SHIFT) {
- return false; // if shift button pressed, show default context menu.
- } else {
- show_context_menu(x, y);
- return true;
- }
- }
- }
- function on_playlist_items_removed(playlist, new_count) {
- on_playlists_changed();
- }
- function on_playlist_switch() {
- on_playlists_changed();
- }
- function on_playlists_changed() {
- on_item_focus_change();
- }
- //EOF
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement