Skip to content

Commit

Permalink
Merge pull request #21 from L3v3L/develop
Browse files Browse the repository at this point in the history
  • Loading branch information
L3v3L committed Mar 6, 2023
2 parents ca21707 + 05e5d28 commit f6e8ee2
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 19 deletions.
2 changes: 1 addition & 1 deletion package.json
@@ -1,5 +1,5 @@
{
"version": "1.1",
"version": "1.2",
"name": "foo-last-list-smp",
"author": "Ivo Barros",
"id": "{152DE6E6-A5D6-4434-88D8-E9FF00130BF9}",
Expand Down
19 changes: 6 additions & 13 deletions scripts/LastList.js
Expand Up @@ -2,10 +2,10 @@

include('InputError.js');
include('LastListHelpers.js');
include('LastListCache.js');

class LastList {
constructor({ url = '', pages = 1, playlistName = 'Last List', cacheTime = 86400000 } = {}) {
this.cachedUrls = [];
this.url = url;
this.pages = pages;
this.playlistName = playlistName;
Expand All @@ -16,9 +16,9 @@ class LastList {
try {
if (!this.url) {
try {
this.url = utils.InputBox(0, "Enter the URL:", "Download", this.cachedUrls.length ? this.cachedUrls[0] : '', true);
this.url = utils.InputBox(0, "Enter the URL:", "Download", '', true);
} catch (e) {
throw new InputError('Cancelled Input');
throw new InputError('Canceled Input');
}

if (!this.url) {
Expand All @@ -45,7 +45,7 @@ class LastList {
try {
this.pages = utils.InputBox(0, "Enter the number of pages:", "Download", '1', true);
} catch (e) {
throw new InputError('Cancelled Input');
throw new InputError('Canceled Input');
}

this.pages = parseInt(this.pages);
Expand All @@ -58,7 +58,7 @@ class LastList {
try {
this.playlistName = utils.InputBox(0, "Enter the playlist name:", "Download", 'Last List', true);
} catch (e) {
throw new InputError('Cancelled Input');
throw new InputError('Canceled Input');
}

if (!this.playlistName) {
Expand All @@ -67,13 +67,6 @@ class LastList {
}

this.scrapeUrl(this.url, startPage, this.pages, this.playlistName, this.cacheTime);

// removes url from cache if it exists and slices the cache to 9 items
this.cachedUrls = this.cachedUrls.filter((cachedUrl) => {
return cachedUrl !== this.url;
}).slice(0, 9);
// add url to the beginning of the cache
this.cachedUrls.unshift(this.url);
} catch (e) {
if (e instanceof InputError) {
// do nothing
Expand Down Expand Up @@ -182,8 +175,8 @@ class LastList {

xmlhttp.open("GET", urlToUse, true);
xmlhttp.onreadystatechange = () => {
this.log(`Cached Not Used`);
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
this.log(`Cached Not Used`);
this.log(`searching page ${i}...`);
let content = xmlhttp.responseText;
// check if content is json
Expand Down
10 changes: 5 additions & 5 deletions scripts/LastListMenu.js
Expand Up @@ -70,8 +70,7 @@ class LastListMenu {
{
menuName: playingSubMenu,
entryText: config.entryText,
func: () => { config.lastList.run() },
flags: MF_STRING
func: () => { config.lastList.run() }
}
);

Expand All @@ -93,8 +92,7 @@ class LastListMenu {
{
menuName: selectedSubMenu,
entryText: config.entryText,
func: () => { config.lastList.run() },
flags: MF_STRING
func: () => { config.lastList.run() }
}
);

Expand All @@ -119,7 +117,9 @@ class LastListMenu {
menu = this.createQuestionButton(menu, customArtistSubMenu, 'Similar Artists', ['Enter Artist'], 'ARTIST_SIMILAR');
menu = this.createQuestionButton(menu, customArtistSubMenu, 'Album', ['Enter Artist', 'Enter Album'], 'ALBUM_TRACKS');

menu = this.createQuestionButton(menu, 'main', 'Custom Tag', ['Enter Last.fm Tag'], 'TAG_TRACKS');
let customTagSubMenu = menu.newMenu('Custom Tag');
menu = this.createQuestionButton(menu, customTagSubMenu, 'Top Tracks', ['Enter Last.fm Tag'], 'TAG_TRACKS');
menu = this.createQuestionButton(menu, customTagSubMenu, 'Random Tracks', ['Enter Last.fm Tag'], 'TAG_RADIO');

menu.newEntry({ entryText: 'sep' });
let lastFMGlobalSubMenu = menu.newMenu('Last.fm Global');
Expand Down

1 comment on commit f6e8ee2

@regorxxx
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My point about URL array caching not doing anything on code has been fixed here, but now (and on previous update) there is zero URL caching XD

lastlist

i.e. if you click multiple times on 'Custom URL', the previous value is never saved. Because well... you have changed the logic to set arguments on the constructor.
And you can't revert back URL caching unless you also revert back arguments usage on .run method instead of doing it at the constructor stage.
Or you may add caching via an external variable outside the constructor, which is pretty bad coding.

Please sign in to comment.