Advertisement
Guest User

Last fm script

a guest
May 23rd, 2014
854
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 62.30 KB | None | 0 0
  1. // ==PREPROCESSOR==
  2. // @name "WSH Last.fm panel"
  3. // @import "%fb2k_path%\skins\\strigUI\\lib\\common.js"
  4. // ==/PREPROCESSOR==
  5.  
  6. // reworked version of LastFM panel by so_kindly
  7.  
  8. // Variables {{
  9.  
  10. var FontStyle = {
  11. Regular: 0,
  12. Bold: 1,
  13. Italic: 2,
  14. BoldItalic: 3,
  15. Underline: 4,
  16. Strikeout: 8
  17. };
  18.  
  19. var StringAlignment = {
  20. Near: 0,
  21. Center: 1,
  22. Far: 2
  23. };
  24.  
  25. var StringTrimming = {
  26. None: 0,
  27. Character: 1,
  28. Word: 2,
  29. EllipsisCharacter: 3,
  30. EllipsisWord: 4,
  31. EllipsisPath: 5
  32. };
  33.  
  34. var StringFormatFlags = {
  35. DirectionRightToLeft: 0x00000001,
  36. DirectionVertical: 0x00000002,
  37. NoFitBlackBox: 0x00000004,
  38. DisplayFormatControl: 0x00000020,
  39. NoFontFallback: 0x00000400,
  40. MeasureTrailingSpaces: 0x00000800,
  41. NoWrap: 0x00001000,
  42. LineLimit: 0x00002000,
  43. NoClip: 0x00004000,
  44. BypassGDI: 0x80000000
  45. }
  46.  
  47. var FOCUSFLAG;
  48.  
  49. var CursorFollowMode = {
  50. OnlyStopped: 2,
  51. Always: 3
  52. }
  53.  
  54. // globals
  55. var ww = 0;
  56. var wh = 0;
  57. var Properties = new GetProperties();
  58. var MetaDB;
  59.  
  60. //margins
  61. var lm = 5;
  62. var rm = 5;
  63. var tm = 5;
  64. var bm = 0;
  65.  
  66. var font_label = gdi.Font("Segoe UI", 12, FontStyles.Bold);
  67. var font_num = gdi.Font("Segoe UI", 11, FontStyles.Bold);
  68. var font_normal = gdi.Font("Segoe UI", 13, FontStyles.Regular);
  69. var font_header = gdi.Font("Segoe UI", 15, FontStyles.Bold);
  70. var font_gui = gdi.Font("Web Symbols", 13, FontStyles.Regular);
  71.  
  72. var normal_color = RGB(80, 80, 80);
  73. var hover_color = RGB(0, 120, 255);
  74. var LineStrFmt = StringFormat(StringAlignment.Near,StringAlignment.Near,StringTrimming.None,StringFormatFlags.LineLimit);
  75.  
  76. var settings_dir = fb.ProfilePath + "u_settings\\";
  77.  
  78. //img vars
  79. var images_path = fb.FoobarPath + "skins\\strigUI\\WSH LastFM\\";
  80. var img_lastfm_logo_red = gdi.Image(images_path + "lastfm_logo_red.jpg");
  81. var img_lastfm_flip = gdi.Image(images_path + "scrobbleflip.png");
  82. var ava_width = 100;
  83.  
  84. // Register here: http://www.last.fm/api/account
  85. var api_key = '';
  86. var username = '';
  87. var opt_api_key = read_option("lastfm_api_key", "");
  88. var opt_username = read_option("lastfm_username", "");
  89.  
  90. //var opt_api_key = api_key
  91. //var opt_username = username
  92. //var CurrentMode = parseInt( utils.ReadINI(fb.FoobarPath + '_cfg.ini', 'love', 'fav_track_mode', 1) );
  93. //update_option("lastfm_username", opt_username);
  94. //update_option("lastfm_username", opt_username);
  95.  
  96. var WshShell = new ActiveXObject("WScript.Shell");
  97.  
  98. var lastfm_data = new Array();
  99. var lastfm_xmlhttp = new Array();
  100. var lastfm_xmlDoc = new Array();
  101.  
  102. var wait = 1;
  103. var lastfm_status = 0;
  104. var error_count = 0;
  105. var loved_track = false;
  106.  
  107. var Y_OFFSET = 0;
  108. var sum_height = 0;
  109. var text_H = 0;
  110. var text_W = 0;
  111.  
  112. var mouse_x = 0;
  113. var mouse_y = 0;
  114.  
  115. var regdate_error = false;
  116.  
  117. var text_Hs = new Array();
  118. var text_Ws = new Array();
  119. var TL_ys = new Array();
  120. var TL_xs = new Array();
  121.  
  122. var np = [fb.TitleFormat("%artist%").Eval(true), fb.TitleFormat("%album%").Eval(true), fb.TitleFormat("%title%").Eval(true)];
  123.  
  124. var spcounter = 0;
  125. var charcounter = 0;
  126. var longeststr = "";
  127. var linecounter = 1;
  128.  
  129. var WaitTimerID;
  130. var StopTimerID;
  131.  
  132. var CorrectedData = []; //artist - album - track
  133.  
  134. // text buttons array [artist, album, track, tag1, tag2, tag3, tag4, tag5, similar1, similar2, similar3, similar4, similar5]
  135. var TLs = new Array(
  136. TL1 = new TextLink(0, 0, 0, 0, function () {}, "", ""),
  137. TL2 = new TextLink(0, 0, 0, 0, function () {}, "", ""),
  138. TL3 = new TextLink(0, 0, 0, 0, function () {}, "", ""),
  139. TLtag1 = new TextLink(0, 0, 0, 0, function () {}, "", ""),
  140. TLtag2 = new TextLink(0, 0, 0, 0, function () {}, "", ""),
  141. TLtag3 = new TextLink(0, 0, 0, 0, function () {}, "", ""),
  142. TLtag4 = new TextLink(0, 0, 0, 0, function () {}, "", ""),
  143. TLtag5 = new TextLink(0, 0, 0, 0, function () {}, "", ""),
  144. TLsimilar1 = new TextLink(0, 0, 0, 0, function () {}, "", ""),
  145. TLsimilar2 = new TextLink(0, 0, 0, 0, function () {}, "", ""),
  146. TLsimilar3 = new TextLink(0, 0, 0, 0, function () {}, "", ""),
  147. TLsimilar4 = new TextLink(0, 0, 0, 0, function () {}, "", ""),
  148. TLsimilar5 = new TextLink(0, 0, 0, 0, function () {}, "", ""),
  149. TLheart = new TextLink(0, 0, 25, 25, function () {}, "♥", "Loved Track"));
  150.  
  151. var Tooltip = window.CreateTooltip();
  152. var TLAnimationTimerID;
  153. var TLAnimationTimer;
  154. var EnableTooltip = true;
  155. var MaxRange;
  156. var h_link, d_link;
  157.  
  158. // Variables}}
  159. function reset_lastfm_data() {
  160. for (id = 0; id <= 4; id++) {
  161. lastfm_data[id] = new Array(4);
  162. }
  163.  
  164. for (id = 0; id <= 3; id++) {
  165. for (n = 0; n <= 5; n++) {
  166. lastfm_data[id][n] = 0;
  167. }
  168. }
  169.  
  170. lastfm_data[1][3] = new Array();
  171. lastfm_data[1][4] = new Array();
  172.  
  173. for (i = 0; i < 5; i++) {
  174. lastfm_data[1][3][i] = "0";
  175. lastfm_data[1][4][i] = "0";
  176. }
  177. }
  178.  
  179. function get_lastfm_data() {
  180. if (opt_username.length == 0 || opt_api_key.length != 32) {
  181. window.Repaint();
  182. } else { //lastfm_status counts here
  183. contact_lastfm("user.getinfo", 0);
  184. contact_lastfm("artist.getinfo&artist=" + encodeURIComponent(np[0]) + "&autocorrect=1", 1);
  185. contact_lastfm("album.getinfo&artist=" + encodeURIComponent(np[0]) + "&album=" + encodeURIComponent(np[1]), 2);
  186. contact_lastfm("track.getinfo&artist=" + encodeURIComponent(np[0]) + "&track=" + encodeURIComponent(np[2]) + "&autocorrect=1", 3);
  187.  
  188. }
  189. }
  190.  
  191. function contact_lastfm(method, id) {
  192. lastfm_xmlhttp[id] = new ActiveXObject("Microsoft.XMLHTTP");
  193. 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);
  194. lastfm_xmlhttp[id].setRequestHeader('User-Agent', "foo_silk_mod");
  195. lastfm_xmlhttp[id].send();
  196. lastfm_xmlhttp[id].onreadystatechange = function () {
  197. if (lastfm_xmlhttp[id].readyState == 4) { // 'DONE' state
  198. if (lastfm_xmlhttp[id].status == 200) { //success
  199. lastfm_status++;
  200. wait_lastfm_data();
  201. }
  202. if (lastfm_xmlhttp[id].status >= 400) { //error statuses
  203.  
  204. error_count++;
  205. lastfm_status++;
  206. wait_lastfm_data();
  207. }
  208. }
  209. }
  210. }
  211.  
  212. function wait_lastfm_data() {
  213. if (lastfm_status == 4 && error_count < 4) {
  214. process_lastfm_data();
  215. lastfm_status = wait = 0;
  216. Y_OFFSET = 0;
  217. error_count = 0;
  218. return;
  219. } else if (lastfm_status < 4) {
  220. wait = 1;
  221. } else if (error_count == 4) {
  222. wait = -1;
  223. error_count = 0;
  224. window.Repaint();
  225.  
  226. }
  227. }
  228.  
  229. function process_lastfm_data() {
  230. for (id = 0; id < 4; id++) {
  231. lastfm_xmlDoc[id] = lastfm_xmlhttp[id].responseXML;
  232. try {
  233. error = "last.fm API error: " + lastfm_xmlDoc[id].getElementsByTagName("error")[0].childNodes[0].nodeValue;
  234. } catch (e) {
  235. error = null;
  236. }
  237. }
  238.  
  239. // Userinfo
  240. try {
  241. lastfm_data[0][0] = lastfm_xmlDoc[0].getElementsByTagName("playcount")[0].childNodes[0].nodeValue;
  242. username = lastfm_xmlDoc[0].getElementsByTagName("name")[0].childNodes[0].nodeValue;
  243. } catch (e) {
  244. lastfm_data[0][0] = "0";
  245. }
  246. try {
  247. lastfm_data[0][4] = lastfm_xmlDoc[0].getElementsByTagName("registered")[0].childNodes[0].nodeValue;
  248. regdate_error = false;
  249. } catch (e) {
  250. regdate_error = true;
  251. lastfm_data[0][4] = "";
  252.  
  253. }
  254.  
  255. date = new Date().getTime() / 1;
  256.  
  257. if (!regdate_error) {
  258. try {
  259. 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);
  260. } catch (e) {
  261. utc = 0;
  262. }
  263. try {
  264. lastfm_data[0][1] = "" + Math.round((lastfm_data[0][0] / ((date - utc) / 86400000)) * 100) / 100;
  265. lastfm_data[0][1] = lastfm_data[0][1].replace(/(\d)(?=(\d\d\d)+([^\d]|$))/g, '$1 ');
  266. } catch (e) {
  267. lastfm_data[0][1] = "0";
  268. };
  269.  
  270. try {
  271. lastfm_data[0][2] = "" + Math.round((lastfm_data[0][0] / ((date - utc) / 604800000)) * 10) / 10;
  272. lastfm_data[0][2] = lastfm_data[0][2].replace(/(\d)(?=(\d\d\d)+([^\d]|$))/g, '$1 ');
  273. } catch (e) {
  274. lastfm_data[0][2] = "0";
  275. };
  276.  
  277. try {
  278. lastfm_data[0][3] = "" + Math.round((lastfm_data[0][0] / ((date - utc) / 2629743000)) * 1) / 1;
  279. lastfm_data[0][3] = lastfm_data[0][3].replace(/(\d)(?=(\d\d\d)+([^\d]|$))/g, '$1 ');
  280. } catch (e) {
  281. lastfm_data[0][3] = "0";
  282. };
  283.  
  284.  
  285. } else {
  286. lastfm_data[0][1] = "0";
  287. lastfm_data[0][2] = "0";
  288. lastfm_data[0][3] = "0";
  289. }
  290.  
  291.  
  292. try {
  293. lastfm_data[0][0] = lastfm_data[0][0].replace(/(\d)(?=(\d\d\d)+([^\d]|$))/g, '$1 ');
  294. } catch (e) {
  295. lastfm_data[0][0] = "0";
  296. }
  297.  
  298.  
  299. // Artistinfo - Albuminfo - Trackinfo
  300. for (id = 1; id <= 3; id++) {
  301. try {
  302. lastfm_data[id][0] = lastfm_xmlDoc[id].getElementsByTagName("playcount")[0].childNodes[0].nodeValue;
  303. lastfm_data[id][0] = lastfm_data[id][0].replace(/(\d)(?=(\d\d\d)+([^\d]|$))/g, '$1 ');
  304. } catch (e) {
  305. lastfm_data[id][0] = "0";
  306. }
  307.  
  308. try {
  309. lastfm_data[id][1] = lastfm_xmlDoc[id].getElementsByTagName("userplaycount")[0].childNodes[0].nodeValue;
  310. lastfm_data[id][1] = lastfm_data[id][1].replace(/(\d)(?=(\d\d\d)+([^\d]|$))/g, '$1 ');
  311. } catch (e) {
  312. lastfm_data[id][1] = "0";
  313. }
  314.  
  315. try {
  316. lastfm_data[id][2] = lastfm_xmlDoc[id].getElementsByTagName("listeners")[0].childNodes[0].nodeValue;
  317. lastfm_data[id][2] = lastfm_data[id][2].replace(/(\d)(?=(\d\d\d)+([^\d]|$))/g, '$1 ');
  318. } catch (e) {
  319. lastfm_data[id][2] = "0";
  320. }
  321.  
  322.  
  323. switch (id) {
  324. case 1:
  325. try {
  326. CorrectedData[id] = lastfm_xmlDoc[id].getElementsByTagName("name")[0].childNodes[0].nodeValue;
  327. for (i = 0; i < 5; i++) {
  328. try {
  329. lastfm_data[id][3][i] = lastfm_xmlDoc[id].getElementsByTagName("tag")[i].childNodes[0].childNodes[0].nodeValue; //artist tags
  330. } catch (e) {
  331. lastfm_data[id][3][i] = "";
  332. }
  333.  
  334. try {
  335. lastfm_data[id][4][i] = lastfm_xmlDoc[id].getElementsByTagName("artist")[i + 1].childNodes[0].childNodes[0].nodeValue; //similar artists
  336. } catch (e) {
  337. lastfm_data[id][4][i] = "no data";
  338. }
  339. }
  340. } catch (e) {
  341. CorrectedData[id] = "~no data";
  342. }
  343. break;
  344. case 2:
  345. try {
  346. CorrectedData[id] = lastfm_xmlDoc[id].getElementsByTagName("name")[0].childNodes[0].nodeValue;
  347. } catch (e) {
  348. CorrectedData[id] = "~no data";
  349. }
  350. break;
  351. case 3:
  352. try {
  353. CorrectedData[id] = lastfm_xmlDoc[id].getElementsByTagName("name")[0].childNodes[0].nodeValue;
  354. } catch (e) {
  355. CorrectedData[id] = "~no data";
  356. }
  357.  
  358. try {
  359. lastfm_data[id][3] = lastfm_xmlDoc[id].getElementsByTagName("userloved")[0].childNodes[0].nodeValue;
  360. } catch (e) {
  361. lastfm_data[id][3] = "0";
  362. }
  363. break;
  364. }
  365.  
  366. }
  367.  
  368. for (i = 0; i < TLs.length; i++) {
  369. TLs[i].NeedReset = true;
  370. }
  371.  
  372. window.Repaint();
  373. }
  374.  
  375. //lfm end
  376. //============================================================================================================
  377. //Properties
  378. function GetProperties() {
  379. this.Panel = {
  380. CursorFollowMode: window.GetProperty("B01.Panel.CursorFollowMode", CursorFollowMode.OnlyStopped),
  381. }
  382.  
  383. this.Panel.CursorFollowMode = Math.max(this.Panel.CursorFollowMode, CursorFollowMode.OnlyStopped);
  384. this.Panel.CursorFollowMode = Math.min(this.Panel.CursorFollowMode, CursorFollowMode.Always);
  385. window.SetProperty("B01.Panel.CursorFollowMode", this.Panel.CursorFollowMode);
  386. }
  387.  
  388. //============================================================================================================
  389.  
  390. //timers
  391. function c_WaitTimer() {
  392. this.Stop = function () {
  393. if (WaitTimerID) {
  394. window.ClearTimeout(WaitTimerID);
  395. WaitTimerID = null;
  396. //window.Repaint();
  397. }
  398. }
  399.  
  400. this.Start = function () {
  401. WaitTimerID = window.SetTimeout(function () {
  402. WaitTimerID = null;
  403. lastfm_status = 0;
  404. wait = 1;
  405.  
  406. MetaDB = fb.GetFocusItem();
  407. FOCUSFLAG = true;
  408. if (MetaDB){
  409. np = [fb.TitleFormat("%artist%").EvalWithMetadb(MetaDB), fb.TitleFormat("%album%").EvalWithMetadb(MetaDB), fb.TitleFormat("%title%").EvalWithMetadb(MetaDB)]
  410. if (np[0] == "?" && np[1] == "?") {
  411. wait = -2;
  412. window.Repaint();
  413. return;
  414. }
  415. lastfm_status = 0;
  416. wait = 1;
  417. window.Repaint();
  418. get_lastfm_data();
  419. } else {
  420. wait = -2;
  421. window.Repaint();
  422. }
  423. }, 400);
  424. }
  425. }
  426.  
  427.  
  428. function c_ButtonAnimationTimer() {
  429. this.Stop = function () {
  430. if (TLAnimationTimerID) {
  431. window.ClearInterval(TLAnimationTimerID);
  432. TLAnimationTimerID = null;
  433. }
  434. }
  435.  
  436. this.Start = function () {
  437. TLAnimationTimerID = window.SetInterval(function () {
  438. var NeedRepaint = 0;
  439. for (var i = 0; i < TLs.length; i++) {
  440. if (TLs[i].NeedRefresh) {
  441. TLs[i].RefreshOpacity();
  442. NeedRepaint += 1;
  443. Onlybtn = TLs[i]; // If only one button need to be repainted.
  444. }
  445. }
  446.  
  447. if (NeedRepaint) {
  448. if (NeedRepaint == 1) window.RepaintRect(Onlybtn.x, Onlybtn.y + Y_OFFSET, Onlybtn.width, Onlybtn.height);
  449. else window.RepaintRect(MaxRange.x, MaxRange.y, MaxRange.width, MaxRange.height); // This is range of buttons.
  450. } else {
  451. TLAnimationTimer.Stop();
  452. }
  453. }, 50)
  454. }
  455. }
  456.  
  457. // VB wrapper {{
  458. var vb = {};
  459. vb.Function = function (func) {
  460. return function () {
  461. return vb.Function.eval.call(this, func, arguments);
  462. }
  463. };
  464. vb.Function.eval = function (func) {
  465. var args = Array.prototype.slice.call(arguments[1]);
  466. for (var i = 0; i < args.length; i++) {
  467. if (typeof args[i] != 'string') continue;
  468. args[i] = '"' + args[i].replace(/"/g, '" + Chr(34) + "') + '"';
  469. }
  470. var vbe;
  471. vbe = new ActiveXObject('ScriptControl');
  472. vbe.Language = 'VBScript';
  473. return vbe.eval(func + '(' + args.join(', ') + ')');
  474. };
  475. var InputBox = vb.Function('InputBox');
  476. var MsgBox = vb.Function('MsgBox');
  477. // VB wrapper}}
  478.  
  479. //============================================================================================================
  480. // Options engine {{
  481. function update_option(optname, optvalue) {
  482. var ini_ = utils.ReadINI(fb.FoobarPath + '_cfg.ini', 'LFMPanel', optname);
  483.  
  484. if ( optname ) utils.WriteINI( fb.FoobarPath + '_cfg.ini', 'LFMPanel', optname, optvalue);
  485. else if ( !optname && ini_ ) optname = ini_;
  486. //else if ( !optname && !ini_) optname = optvalue;
  487. else optname = optvalue;
  488. }
  489.  
  490. function read_option(optname, initvalue) {
  491. var ini_ = utils.ReadINI(fb.FoobarPath + '_cfg.ini', 'LFMPanel', optname);
  492. return ini_
  493. }
  494.  
  495. // Options engine }}
  496.  
  497. // Cursor follow tools {{
  498. function SetCursorFollowMode(FollowMode) {
  499. if (FollowMode != Properties.Panel.CursorFollowMode) {
  500. Properties.Panel.CursorFollowMode = FollowMode;
  501. window.SetProperty("B01.Panel.CursorFollowMode", FollowMode);
  502. CursorFollow(FollowMode);
  503. }
  504. }
  505.  
  506. function CursorFollow(FollowMode) {
  507. switch (FollowMode) {
  508. case CursorFollowMode.OnlyStopped:
  509. if (fb.IsPlaying) on_playback_new_track();
  510. else on_item_focus_change();
  511. break;
  512. case CursorFollowMode.Always:
  513. on_item_focus_change();
  514. break;
  515. }
  516. }
  517.  
  518. // Cursor follow tools }}
  519.  
  520.  
  521. //context menu
  522. function show_context_menu(x, y) {
  523. var _menu = window.CreatePopupMenu();
  524. //var _avatar = window.CreatePopupMenu();
  525. var _followMode = window.CreatePopupMenu();
  526. var ret;
  527.  
  528. if (opt_username.length == 0 || opt_api_key.length != 32) {
  529. _menu.AppendMenuItem(MF_STRING, 10, "Set your Last.fm username...");
  530. _menu.AppendMenuItem(MF_STRING, 11, "Set your API KEY...");
  531. } else {
  532. _menu.AppendMenuItem(opt_username.length > 0 && opt_api_key.length == 32 ? MF_STRING : MF_GRAYED, 1, "Update Last.fm Data");
  533. _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
  534.  
  535. _followMode.AppendMenuItem(MF_STRING, 2, "Only Stopped");
  536. _followMode.AppendMenuItem(MF_STRING, 3, "Always");
  537. _followMode.CheckMenuRadioItem(2, 3, Properties.Panel.CursorFollowMode);
  538. _followMode.AppendTo(_menu, MF_STRING, "Cursor follow mode");
  539.  
  540. _menu.AppendMenuItem(MF_STRING, 6, "Change username");
  541. _menu.AppendMenuItem(MF_STRING, 7, "Change API Key");
  542. _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
  543. _menu.AppendMenuItem(MF_STRING, 8, "Properties");
  544. }
  545.  
  546. ret = _menu.TrackPopupMenu(x, y);
  547. switch (ret) {
  548. case 1:
  549. lastfm_status = 0;
  550. wait = 1;
  551. window.Repaint();
  552. CursorFollow(Properties.Panel.CursorFollowMode);
  553. break;
  554. case 2:
  555. SetCursorFollowMode(CursorFollowMode.OnlyStopped);
  556. break;
  557. case 3:
  558. SetCursorFollowMode(CursorFollowMode.Always);
  559. break;
  560.  
  561. case 6:
  562. opt_username = InputBox("Please enter your Last.fm username", "Last.fm panel", opt_username);
  563. if (!opt_username) opt_username = "";
  564. update_option("lastfm_username", opt_username);
  565.  
  566. //avatar_need_refresh = true;
  567.  
  568. CursorFollow(Properties.Panel.CursorFollowMode);
  569. break;
  570. case 7:
  571. opt_api_key = InputBox("Please enter your Last.fm API KEY (http://www.last.fm/api/account)", "Last.fm panel", opt_api_key);
  572. if (!opt_api_key) opt_api_key = "";
  573. update_option("lastfm_api_key", opt_api_key);
  574. CursorFollow(Properties.Panel.CursorFollowMode);
  575. break;
  576. case 8:
  577. window.ShowProperties();
  578. break;
  579. case 10:
  580. opt_username = InputBox("Please enter your Last.fm username", "Last.fm panel", opt_username);
  581. if (!opt_username) opt_username = "";
  582. update_option("lastfm_username", opt_username);
  583.  
  584. //avatar_need_refresh = true;
  585.  
  586. CursorFollow(Properties.Panel.CursorFollowMode);
  587. break;
  588. case 11:
  589. opt_api_key = InputBox("Please enter your Last.fm API KEY (http://www.last.fm/api/account)", "Last.fm panel", opt_api_key);
  590. if (!opt_api_key) opt_api_key = "";
  591. update_option("lastfm_api_key", opt_api_key);
  592. CursorFollow(Properties.Panel.CursorFollowMode);
  593. break;
  594. }
  595. _menu.Dispose();
  596. //_avatar.Dispose();
  597. _followMode.Dispose();
  598. return true;
  599. }
  600.  
  601. // button class
  602. function TextLink(x, y, width, height, fn_onclick, label, tiptext) {
  603. this.x = x;
  604. this.y = y;
  605. this.width = width;
  606. this.height = height;
  607. this.label = label;
  608. this.tiptext = tiptext;
  609. this.TestProp = "";
  610. this.NeedRefresh = 0;
  611. this.oldstate = 0; // 0=normal, 1=hover, 2=down.
  612. this.state = 0;
  613. this.opacity = 0; // Opacity of new state image.
  614. this.step = 0;
  615. this.show = true;
  616. this.NeedReset = false;
  617.  
  618. this.OnClick = fn_onclick;
  619.  
  620. this.ChangeState = function (s) {
  621. this.oldstate = this.state;
  622. this.state = s;
  623. this.opacity = 0;
  624. this.NeedRefresh = 1;
  625. switch (s) {
  626. case 0:
  627. this.step = 40; // Step of changing to normal state.
  628. Tooltip.Deactivate();
  629. Tooltip.Text = "";
  630. break;
  631. case 1:
  632. this.step = 75; // hover state.
  633. if (EnableTooltip) {
  634. Tooltip.Text = this.tiptext;
  635. Tooltip.Activate();
  636. }
  637. break;
  638. case 2:
  639. this.step = 85; // down state.
  640. Tooltip.Deactivate();
  641. Tooltip.Text = "";
  642. break;
  643. }
  644.  
  645. if (!TLAnimationTimerID) // start animation
  646. TLAnimationTimer.Start();
  647. }
  648.  
  649. this.isXYok = function (x2, y2) {
  650. return (x2 >= this.x && y2 >= this.y + Y_OFFSET && x2 <= this.x + this.width && y2 <= this.y + Y_OFFSET + this.height) ? true : false;
  651. }
  652.  
  653. this.Draw = function (x2, y2, gr) {
  654. x2 = this.x; //disabled
  655. y2 = this.y; //disabled
  656. if (this.opacity < 100) {
  657. switch (this.oldstate) {
  658. case 0:
  659. //gr.FillSolidRect(this.x, this.y + Y_OFFSET, this.width, this.height, RGBA(0, 120, 220, 100));
  660. gr.DrawString(this.label, font_normal, normal_color, this.x + 4, this.y + Y_OFFSET, this.width - 4, this.height, LineStrFmt);
  661. break;
  662. case 1:
  663. //gr.FillSolidRect(this.x, this.y + Y_OFFSET, this.width, this.height, RGBA(0, 130, 230, 100));
  664. gr.DrawString(this.label, font_normal, hover_color, this.x + 4, this.y + Y_OFFSET, this.width - 4, this.height, LineStrFmt);
  665. break;
  666. case 2:
  667. //gr.FillSolidRect(this.x, this.y + Y_OFFSET, this.width, this.height, RGBA(0, 136, 236, 100));
  668. gr.DrawString(this.label, font_normal, hover_color, this.x + 4, this.y + Y_OFFSET, this.width - 4, this.height, LineStrFmt);
  669. break;
  670. default:
  671. break;
  672. }
  673. }
  674.  
  675. if (this.opacity) {
  676. switch (this.state) {
  677. case 0:
  678. //gr.FillSolidRect(this.x, this.y + Y_OFFSET, this.width, this.height, RGBA(0, 120, 220, this.opacity));
  679. gr.DrawString(this.label, font_normal, normal_color, this.x + 4, this.y + Y_OFFSET, this.width, this.height, LineStrFmt);
  680. break;
  681. case 1:
  682. //gr.FillSolidRect(this.x, this.y + Y_OFFSET, this.width, this.height, RGBA(0, 130, 230, this.opacity));
  683. gr.DrawString(this.label, font_normal, hover_color, this.x + 4, this.y + Y_OFFSET, this.width, this.height, LineStrFmt);
  684. break;
  685. case 2:
  686. //gr.FillSolidRect(this.x, this.y + Y_OFFSET, this.width, this.height, RGBA(0, 136, 236, this.opacity));
  687. gr.DrawString(this.label, font_normal, hover_color, this.x + 4, this.y + Y_OFFSET, this.width, this.height, LineStrFmt);
  688. break;
  689. }
  690. }
  691. }
  692.  
  693. this.RefreshOpacity = function (fn) {
  694. if (this.opacity < 100) this.opacity = Math.min(this.opacity + this.step, 100);
  695. else {
  696. this.oldstate = this.state;
  697. this.opacity = 0;
  698. this.NeedRefresh = 0;
  699. }
  700. }
  701. }
  702.  
  703. function GetCoordinates() {
  704.  
  705. // Calculate the max range of buttons, for increasing refresh speed.
  706. MaxRange = {
  707. x: TLs[0].x,
  708. y: TLs[0].y + Y_OFFSET,
  709. width: TLs[0].width,
  710. height: TLs[0].height
  711. }
  712.  
  713. for (var i = 1; i < TLs.length - 1; i++) {
  714. if (TLs[i].show) {
  715. MaxRange.x = Math.min(TLs[i].x, MaxRange.x);
  716. MaxRange.y = Math.min(TLs[i].y + Y_OFFSET, MaxRange.y);
  717. MaxRange.width = Math.max(TLs[i].x + TLs[i].width - MaxRange.x, MaxRange.width);
  718. MaxRange.height = Math.max(TLs[i].y + Y_OFFSET + TLs[i].height - MaxRange.y, MaxRange.height);
  719. }
  720. }
  721.  
  722. }
  723.  
  724. //===================================================================================================================================================
  725. //===================================================================================================================================================
  726.  
  727.  
  728. function on_init() {
  729. //Scrollbar = new V_SCROLLBAR(20, 45);
  730. WaitTimer = new c_WaitTimer();
  731. TLAnimationTimer = new c_ButtonAnimationTimer();
  732. //update_option("lastfm_api_key", "179b25d95e633097ec682c58b4a993ec");
  733. reset_lastfm_data();
  734. //WaitTimer.Start();
  735. }
  736. on_init();
  737.  
  738.  
  739. function on_size() {
  740. if (!window.Width || !window.Height) return;
  741. ww = window.Width;
  742. wh = window.Height;
  743.  
  744. GetCoordinates();
  745. CursorFollow(Properties.Panel.CursorFollowMode);
  746. }
  747.  
  748. function on_paint(gr) {
  749. sum_height = 0;
  750. gr.SetTextRenderingHint(5);
  751.  
  752. if (opt_username.length == 0 || opt_api_key.length != 32) {
  753. gr.GdiDrawText("Last.fm panel \n Please enter your username \n and API key with context menu", font_normal, normal_color, 0, 0, ww, wh, DT_CENTER | DT_VCENTER | DT_CALCRECT | DT_NOPREFIX);
  754. return;
  755. }
  756. if (wait == 0) {
  757. //draw last.fm logo
  758. gr.FillSolidRect(ww/2, tm + Y_OFFSET, ww, 30, RGBA(210, 19, 9, 255));
  759. gr.DrawImage(img_lastfm_logo_red, (ww - 110), tm + Y_OFFSET, 100, 30, 0, 0, 900, 269);
  760. //draw user avatar
  761. /* gr.DrawImage(img_avatar, lm, tm + 30 + tm + Y_OFFSET, ava_width, ava_height, 0, 0, img_avatar.width, img_avatar.height);
  762. sum_height += ava_height < 100 ? tm + 30 + tm + 100 : tm + 30 + tm + ava_height;
  763. gr.DrawRect(lm, tm + 30 + tm + Y_OFFSET, ava_width, ava_height, 2, normal_color); */
  764. sum_height += 5;
  765. //draw username
  766. /*if (ww >= 175 + ava_width) {
  767. gr.GdiDrawText(username != "" ? username : opt_username, font_header, normal_color, lm + ava_width + 15, 45 + Y_OFFSET, ww, wh);
  768. } else {
  769. gr.GdiDrawText(username != "" ? username : opt_username, font_header, normal_color, lm, sum_height + 5 + Y_OFFSET, ww, wh);
  770. sum_height += font_header.height + 9;
  771. }*/
  772.  
  773.  
  774. // plays ========================================================================================================================================================================================
  775.  
  776. for (i = 0; i <= 3; i++) {
  777. charcounter = 0;
  778. spcounter = 0;
  779.  
  780. switch (i) {
  781. case 0:
  782. txt_plays = " plays";
  783. break;
  784. case 1:
  785. txt_plays = " per day";
  786. break;
  787. case 2:
  788. txt_plays = " per week";
  789. break;
  790. case 3:
  791. txt_plays = " per month";
  792. break;
  793. }
  794.  
  795. if (longeststr.length < lastfm_data[0][i].length) longeststr = lastfm_data[0][i];
  796.  
  797. if (ww >= 175 + ava_width) {
  798. for (j = 0; j < lastfm_data[0][i].length; j++) {
  799. if (lastfm_data[0][i].substring((j), j + 1) != " ") {
  800. 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);
  801. charcounter++;
  802. } else {
  803. spcounter++;
  804. }
  805. 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);
  806. }
  807. 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);
  808. } else {
  809. for (j = 0; j < lastfm_data[0][i].length; j++) {
  810. if (lastfm_data[0][i].substring((j), j + 1) != " ") {
  811. 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);
  812. charcounter++;
  813. } else {
  814. spcounter++;
  815. }
  816. 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);
  817. }
  818. 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);
  819. sum_height += img_lastfm_flip.height + 3;
  820. }
  821.  
  822. }
  823.  
  824.  
  825. //========================================================================================================================================================================================
  826. gr.GdiDrawText("Current track", font_header, normal_color, lm, sum_height + 6 + Y_OFFSET, ww, wh);
  827. // artist - album - track ========================================================================================================================================================================================
  828.  
  829. if (lastfm_data[3][3] == "1") { //userloved
  830. TLs[13].x = 105;
  831. TLs[13].y = sum_height + 6;
  832.  
  833. TLs[13].Draw = function (gr) {
  834. gr.GdiDrawText(TLs[13].label, font_gui, normal_color, TLs[13].x, TLs[13].y + Y_OFFSET, TLs[13].width, TLs[13].height);
  835. }
  836. TLs[13].Draw(gr);
  837. } else {
  838. TLs[13].x = ww + 10;
  839. }
  840.  
  841. sum_height += font_header.height + 17;
  842.  
  843.  
  844. for (i = 0; i < 3; i++) {
  845. TLs[i].y = sum_height;
  846.  
  847. if (TLs[i].NeedReset) {
  848. if (CorrectedData[i + 1] != "~no data") {
  849. 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);
  850. 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);
  851.  
  852. switch (i) {
  853. case 0:
  854. TLs[i].OnClick = function () {
  855. WshShell.run("http://www.last.fm/music/" + encodeURIComponent(CorrectedData[1]))
  856. };
  857. break;
  858. case 1:
  859. TLs[i].OnClick = function () {
  860. WshShell.run("http://www.last.fm/music/" + encodeURIComponent(CorrectedData[1]) + "/" + encodeURIComponent(CorrectedData[2]))
  861. };
  862. break;
  863. case 2:
  864. TLs[i].OnClick = function () {
  865. WshShell.run("http://www.last.fm/music/" + encodeURIComponent(CorrectedData[1]) + "/" + encodeURIComponent(CorrectedData[2]) + "/" + encodeURIComponent(CorrectedData[3]))
  866. };
  867. break;
  868. }
  869.  
  870. TLs[i].x = 50 + lm;
  871. TLs[i].width = text_Ws[i] + 8;
  872. TLs[i].height = text_Hs[i];
  873. TLs[i].label = CorrectedData[i + 1] == np[i] ? np[i] : CorrectedData[i + 1] + " [*]";
  874. TLs[i].tiptext = CorrectedData[i + 1] == np[i] ? "" : "Auto-corrected from: " + "'" + np[i] + "'";
  875. TLs[i].NeedReset = false;
  876. } else {
  877. text_Ws[i] = Math.ceil(gr.MeasureString(np[i], font_normal, 0, 0, ww - 50 - lm - rm - 20, wh, LineStrFmt).Width);
  878. text_Hs[i] = Math.ceil(gr.MeasureString(np[i], font_normal, 0, 0, ww - 50 - lm - rm - 20, wh, LineStrFmt).Height);
  879.  
  880. switch (i) {
  881. case 0:
  882. TLs[i].OnClick = function () {
  883. WshShell.run("http://www.last.fm/music/" + encodeURIComponent(np[0]))
  884. };
  885. break;
  886. case 1:
  887. TLs[i].OnClick = function () {
  888. WshShell.run("http://www.last.fm/music/" + encodeURIComponent(np[0]) + "/" + encodeURIComponent(np[1]))
  889. };
  890. break;
  891. case 2:
  892. TLs[i].OnClick = function () {
  893. WshShell.run("http://www.last.fm/music/" + encodeURIComponent(np[0]) + "/" + encodeURIComponent(np[1]) + "/" + encodeURIComponent(np[2]))
  894. };
  895. break;
  896. }
  897.  
  898. TLs[i].x = 50 + lm;
  899. TLs[i].width = text_Ws[i] + 8;
  900. TLs[i].height = text_Hs[i];
  901. TLs[i].label = np[i];
  902. TLs[i].tiptext = "";
  903. TLs[i].NeedReset = false;
  904. }
  905.  
  906.  
  907. }
  908. TLs[i].Draw(this.x, this.y, gr);
  909.  
  910.  
  911. switch (i) {
  912. case 0:
  913. txt_t = "Artist:";
  914. break;
  915. case 1:
  916. txt_t = "Album:";
  917. break;
  918. case 2:
  919. txt_t = "Track:";
  920. break;
  921. }
  922. gr.GdiDrawText(txt_t, font_label, normal_color, lm, sum_height + 2 + Y_OFFSET, 50, wh);
  923. sum_height += text_Hs[i] + 3;
  924. }
  925.  
  926. sum_height += 3;
  927.  
  928. // tags ========================================================================================================================================================================================
  929.  
  930. gr.GdiDrawText("Artist", font_label, normal_color, lm, sum_height + 2 + Y_OFFSET, 50, wh);
  931. gr.GdiDrawText("tags:", font_label, normal_color, lm, sum_height + 2 + font_label.height + Y_OFFSET, 50, wh);
  932. linecounter = 1;
  933.  
  934. if (lastfm_data[1][3][0] != "no data") {
  935. for (i = 0; i < 5; i++) {
  936. 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);
  937. 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);
  938.  
  939.  
  940. 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);
  941. 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);
  942. linecounter += (TLs[i + 2].x + text_Ws[i + 2] + 8 + text_Ws[i + 3] + 8 + 1 < ww - rm - 20) || i == 0 ? 0 : 1;
  943.  
  944.  
  945. if (TLs[i + 3].NeedReset) {
  946. switch (i) {
  947. case 0:
  948. TLs[i + 3].OnClick = function () {
  949. WshShell.run("http://www.last.fm/tag/" + encodeURIComponent(lastfm_data[1][3][0]))
  950. };
  951. break;
  952. case 1:
  953. TLs[i + 3].OnClick = function () {
  954. WshShell.run("http://www.last.fm/tag/" + encodeURIComponent(lastfm_data[1][3][1]))
  955. };
  956. break;
  957. case 2:
  958. TLs[i + 3].OnClick = function () {
  959. WshShell.run("http://www.last.fm/tag/" + encodeURIComponent(lastfm_data[1][3][2]))
  960. };
  961. break;
  962. case 3:
  963. TLs[i + 3].OnClick = function () {
  964. WshShell.run("http://www.last.fm/tag/" + encodeURIComponent(lastfm_data[1][3][3]))
  965. };
  966. break;
  967. case 4:
  968. TLs[i + 3].OnClick = function () {
  969. WshShell.run("http://www.last.fm/tag/" + encodeURIComponent(lastfm_data[1][3][4]))
  970. };
  971. break;
  972. }
  973.  
  974.  
  975. TLs[i + 3].width = text_Ws[i + 3] + 8;
  976. TLs[i + 3].height = text_Hs[i + 3];
  977. TLs[i + 3].label = lastfm_data[1][3][i];
  978. TLs[i + 3].tiptext = "";
  979. TLs[i + 3].NeedReset = false;
  980.  
  981. }
  982. TLs[i + 3].Draw(0, 0, gr);
  983.  
  984. 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;
  985. 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;
  986. }
  987. } else {
  988. for (i = 0; i < 5; i++) {
  989. TLs[i + 3].show = false;
  990. }
  991. gr.GdiDrawText("Tags did not recieved", font_normal, normal_color, lm + 50, sum_height + 2 + Y_OFFSET, ww, wh);
  992. }
  993.  
  994. sum_height += linecounter == 1 ? font_normal.height * 2 + 6 : font_normal.height + 6;
  995. // similar ========================================================================================================================================================================================
  996.  
  997. gr.GdiDrawText("Similar", font_label, normal_color, lm, sum_height + 2 + Y_OFFSET, 50, wh);
  998. gr.GdiDrawText("artists:", font_label, normal_color, lm, sum_height + 2 + font_label.height + Y_OFFSET, 50, wh);
  999. linecounter = 1;
  1000.  
  1001. if (lastfm_data[1][4][0] != "no data") {
  1002. for (i = 0; i < 5; i++) {
  1003. 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);
  1004. 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);
  1005.  
  1006.  
  1007. 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);
  1008. 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);
  1009. linecounter += (TLs[i + 7].x + text_Ws[i + 7] + 8 + text_Ws[i + 8] + 8 + 1 < ww - rm - 20) || i == 0 ? 0 : 1;
  1010.  
  1011. if (TLs[i + 8].NeedReset) {
  1012. switch (i) {
  1013. case 0:
  1014. TLs[i + 8].OnClick = function () {
  1015. WshShell.run("http://www.last.fm/music/" + encodeURIComponent(lastfm_data[1][4][0]))
  1016. };
  1017. break;
  1018. case 1:
  1019. TLs[i + 8].OnClick = function () {
  1020. WshShell.run("http://www.last.fm/music/" + encodeURIComponent(lastfm_data[1][4][1]))
  1021. };
  1022. break;
  1023. case 2:
  1024. TLs[i + 8].OnClick = function () {
  1025. WshShell.run("http://www.last.fm/music/" + encodeURIComponent(lastfm_data[1][4][2]))
  1026. };
  1027. break;
  1028. case 3:
  1029. TLs[i + 8].OnClick = function () {
  1030. WshShell.run("http://www.last.fm/music/" + encodeURIComponent(lastfm_data[1][4][3]))
  1031. };
  1032. break;
  1033. case 4:
  1034. TLs[i + 8].OnClick = function () {
  1035. WshShell.run("http://www.last.fm/music/" + encodeURIComponent(lastfm_data[1][4][4]))
  1036. };
  1037. break;
  1038. }
  1039.  
  1040.  
  1041. TLs[i + 8].width = text_Ws[i + 8] + 8;
  1042. TLs[i + 8].height = text_Hs[i + 8];
  1043. TLs[i + 8].label = lastfm_data[1][4][i];
  1044. TLs[i + 8].tiptext = "";
  1045. TLs[i + 8].NeedReset = false;
  1046.  
  1047. }
  1048. TLs[i + 8].Draw(0, 0, gr);
  1049.  
  1050. 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;
  1051. 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;
  1052. }
  1053. } else {
  1054. for (i = 0; i < 5; i++) {
  1055. TLs[i + 8].show = false;
  1056. }
  1057. gr.GdiDrawText("Artists did not recieved", font_normal, normal_color, lm + 50, sum_height + 2 + Y_OFFSET, ww, wh);
  1058. }
  1059.  
  1060. sum_height += linecounter == 1 ? font_normal.height * 2 + 2 : font_normal.height + 2;
  1061. GetCoordinates(); //run this when all buttons are resetted
  1062.  
  1063. // listeners ========================================================================================================================================================================================
  1064. /* gr.GdiDrawText("Listeners", font_header, normal_color, lm, sum_height + Y_OFFSET, ww, wh);
  1065. sum_height += font_header.height + 5;
  1066.  
  1067. for (id = 1; id <= 3; id++) {
  1068. charcounter = 0;
  1069. spcounter = 0;
  1070.  
  1071. for (j = 0; j < lastfm_data[id][2].length; j++) {
  1072. if (lastfm_data[id][2].substring((j), j + 1) != " ") {
  1073. 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);
  1074. charcounter++;
  1075. } else {
  1076. spcounter++;
  1077. }
  1078. 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);
  1079. }
  1080.  
  1081. switch (id) {
  1082. case 1:
  1083. txt_t = "Artist:";
  1084. break;
  1085. case 2:
  1086. txt_t = "Album:";
  1087. break;
  1088. case 3:
  1089. txt_t = "Track:";
  1090. break;
  1091. }
  1092. gr.GdiDrawText(txt_t, font_label, normal_color, lm, sum_height - 1 + Y_OFFSET, ww, wh);
  1093. sum_height += 18;
  1094. } */
  1095.  
  1096.  
  1097. // plays ========================================================================================================================================================================================
  1098. /* gr.GdiDrawText("Plays", font_header, normal_color, lm, sum_height + Y_OFFSET, ww, wh);
  1099. sum_height += font_header.height + 5;
  1100.  
  1101. for (id = 1; id <= 3; id++) {
  1102. charcounter = 0;
  1103. spcounter = 0;
  1104. for (j = 0; j < lastfm_data[id][0].length; j++) {
  1105. if (lastfm_data[id][0].substring((j), j + 1) != " ") {
  1106. 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);
  1107. charcounter++;
  1108. } else {
  1109. spcounter++;
  1110. }
  1111. 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);
  1112. }
  1113.  
  1114. switch (id) {
  1115. case 1:
  1116. txt_tt = "Artist:";
  1117. break;
  1118. case 2:
  1119. txt_tt = "Album:";
  1120. break;
  1121. case 3:
  1122. txt_tt = "Track:";
  1123. break;
  1124. }
  1125.  
  1126. gr.GdiDrawText(txt_tt, font_label, normal_color, lm, sum_height - 1 + Y_OFFSET, ww, wh);
  1127. sum_height += 18;
  1128. } */
  1129.  
  1130. // by user ========================================================================================================================================================================================
  1131. //gr.GdiDrawText(username != "" ? "Plays by " + username : "Plays by " + opt_username, font_header, normal_color, lm, sum_height + Y_OFFSET, ww, wh);
  1132. gr.GdiDrawText("Plays by user", font_header, normal_color, lm, sum_height + Y_OFFSET, ww, wh);
  1133.  
  1134. sum_height += font_header.height + 10;
  1135.  
  1136. for (id = 1; id <= 3; id++) {
  1137. charcounter = 0;
  1138. spcounter = 0;
  1139. for (j = 0; j < lastfm_data[id][1].length; j++) {
  1140. if (lastfm_data[id][1].substring((j), j + 1) != " ") {
  1141. 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);
  1142. charcounter++;
  1143. } else {
  1144. spcounter++;
  1145. }
  1146. 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);
  1147. }
  1148.  
  1149. switch (id) {
  1150. case 1:
  1151. txt_tt = "Artist:";
  1152. break;
  1153. case 2:
  1154. txt_tt = "Album:";
  1155. break;
  1156. case 3:
  1157. txt_tt = "Track:";
  1158. break;
  1159. }
  1160.  
  1161. gr.GdiDrawText(txt_tt, font_label, normal_color, lm, sum_height - 1 + Y_OFFSET, ww, wh);
  1162. sum_height += 18;
  1163. }
  1164.  
  1165. } else if (wait == 1) {
  1166. 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);
  1167. return;
  1168. } else if (wait == -1) {
  1169. 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);
  1170. } else if (wait == -2) {
  1171. gr.GdiDrawText("No track specified", font_normal, normal_color, 0, 0, ww, wh, DT_CENTER | DT_VCENTER | DT_CALCRECT | DT_NOPREFIX);
  1172. }
  1173. }
  1174.  
  1175. function on_playback_new_track() {
  1176. if(Properties.Panel.CursorFollowMode == CursorFollowMode.OnlyStopped){
  1177. WaitTimer.Stop();
  1178. MetaDB = fb.GetNowPlaying();
  1179. FOCUSFLAG = false;
  1180. np = [fb.TitleFormat("%artist%").EvalWithMetadb(MetaDB), fb.TitleFormat("%album%").EvalWithMetadb(MetaDB), fb.TitleFormat("%title%").EvalWithMetadb(MetaDB)]
  1181. if (np[0] == "?" && np[1] == "?") {
  1182. wait = -2;
  1183. window.Repaint();
  1184. return;
  1185. }
  1186. lastfm_status = 0;
  1187. wait = 1;
  1188. window.Repaint();
  1189. get_lastfm_data();
  1190. }
  1191. }
  1192.  
  1193.  
  1194. function on_item_focus_change() {
  1195. if(Properties.Panel.CursorFollowMode == CursorFollowMode.Always || (Properties.Panel.CursorFollowMode == CursorFollowMode.OnlyStopped && !fb.IsPlaying && !fb.IsPaused)){
  1196. WaitTimer.Stop();
  1197. WaitTimer.Start();
  1198. }
  1199. }
  1200.  
  1201. function on_playback_stop(reason) {
  1202. if (!reason || reason == 1) {
  1203. if(Properties.Panel.CursorFollowMode == CursorFollowMode.OnlyStopped && !FOCUSFLAG){
  1204. WaitTimer.Stop();
  1205. WaitTimer.Start();
  1206. }
  1207. }
  1208. }
  1209.  
  1210. function on_mouse_move(x, y) {
  1211. if (window.Width < 185 || window.Height < 100) return;
  1212. if (wait != 0) return;
  1213.  
  1214. if (d_link) {
  1215. if (d_link.isXYok(x, y)) {
  1216. if (d_link.state != 2) d_link.ChangeState(2);
  1217. } else if (d_link.state != 1) d_link.ChangeState(1);
  1218. } else {
  1219. for (var i = 0; i < TLs.length; i++)
  1220. if (TLs[i].isXYok(x, y) && TLs[i].show) {
  1221. if (h_link != TLs[i]) {
  1222. if (h_link) h_link.ChangeState(0);
  1223. h_link = TLs[i];
  1224. if (h_link != TLs[13]) window.SetCursor(IDC_HAND);
  1225. h_link.ChangeState(1);
  1226. }
  1227. break;
  1228. }
  1229. if (i == TLs.length) {
  1230.  
  1231. if (h_link) {
  1232. if (h_link) h_link.ChangeState(0);
  1233. h_link = undefined;
  1234. window.SetCursor(IDC_ARROW);
  1235. }
  1236. }
  1237. }
  1238.  
  1239. }
  1240.  
  1241. function on_mouse_lbtn_down(x, y) {
  1242. if (window.Width < 185 || window.Height < 100) return;
  1243. if (h_link && !d_link) {
  1244. d_link = h_link;
  1245. d_link.ChangeState(2);
  1246. }
  1247. }
  1248.  
  1249. function on_mouse_lbtn_up(x, y) {
  1250. if (window.Width < 185 || window.Height < 100) return;
  1251. if (d_link) {
  1252. if (d_link.state == 2) {
  1253. d_link.OnClick();
  1254. }
  1255. d_link = undefined;
  1256. on_mouse_move(x, y);
  1257. }
  1258. }
  1259.  
  1260. function on_mouse_leave() {
  1261. if (window.Width < 185 || window.Height < 100) return;
  1262. if (h_link) {
  1263. h_link.ChangeState(0);
  1264. h_link = undefined;
  1265. window.SetCursor(IDC_ARROW);
  1266. }
  1267. Tooltip.Text = "";
  1268.  
  1269. }
  1270.  
  1271. function on_mouse_rbtn_down(x, y, vkey) {
  1272. rbtnDown = true;
  1273. }
  1274.  
  1275. function on_mouse_rbtn_up(x, y, vkey) {
  1276. if (window.Width < 185 || window.Height < 100) return false;
  1277. if (rbtnDown) {
  1278. rbtnDown = false;
  1279. if (vkey == MK_SHIFT) {
  1280. return false; // if shift button pressed, show default context menu.
  1281. } else {
  1282. show_context_menu(x, y);
  1283. return true;
  1284. }
  1285. }
  1286. }
  1287.  
  1288. function on_playlist_items_removed(playlist, new_count) {
  1289. on_playlists_changed();
  1290. }
  1291.  
  1292. function on_playlist_switch() {
  1293. on_playlists_changed();
  1294. }
  1295.  
  1296. function on_playlists_changed() {
  1297. on_item_focus_change();
  1298. }
  1299.  
  1300. //EOF
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement