WebApp to follow people on 9gag, sorted via last visited
https://luna-development.net/9follow/
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
69 lines
2.2 KiB
69 lines
2.2 KiB
let app = new Vue({ |
|
el: '#app', |
|
data: { |
|
userNameToAdd: '', |
|
nameForList: '', |
|
followedAccounts: [] |
|
}, |
|
methods: { |
|
followAccount() { |
|
let userName = this.userNameToAdd; |
|
|
|
if (userName.length <= 0) { |
|
this.showToast('Username is needed.', 'red'); |
|
return false; |
|
} |
|
|
|
this.followedAccounts.push({ |
|
name: (this.nameForList.length > 0) ? this.nameForList : this.userNameToAdd, |
|
url: 'https://9gag.com/u/' + userName + '/', |
|
lastVisited: null |
|
}); |
|
|
|
|
|
this.showToast("You're now following " + this.getDisplayName(), 'darkgreen'); |
|
|
|
this.userNameToAdd = ''; |
|
this.nameForList = ''; |
|
this.updateStorage(); |
|
}, |
|
visitAccount(account) { |
|
account.lastVisited = moment().format(); |
|
window.open(account.url,'_blank'); |
|
|
|
this.updateStorage(); |
|
return true; |
|
}, |
|
showToast(message, color = '') { |
|
iziToast.show({ |
|
theme: 'dark', |
|
color: color, |
|
message: message, |
|
position: 'topCenter', |
|
}); |
|
}, |
|
getDiffForView(time) { |
|
return time ? 'last visited ' + moment(time).fromNow() : 'not yet visited'; |
|
}, |
|
updateStorage() { |
|
localStorage.setItem('followedAccounts', JSON.stringify(this.followedAccounts)); |
|
}, |
|
loadStorage() { |
|
let savedFollowedAccounts = JSON.parse(localStorage.getItem('followedAccounts')); |
|
this.followedAccounts = savedFollowedAccounts ? savedFollowedAccounts : []; |
|
}, |
|
getDisplayName(nameForToast = this.nameForList, userNameToAdd = this.userNameToAdd) { |
|
return nameForToast = nameForList ? userNameToAdd + ' (' + userNameToAdd + ')' : userNameToAdd; |
|
}, |
|
refreshAccountsAndOrder() { |
|
this.loadStorage(); |
|
|
|
this.followedAccounts = this.followedAccounts.sort(function (a, b) { |
|
return new Date(b.lastVisited) - new Date(a.lastVisited) |
|
}); |
|
} |
|
}, |
|
mounted() { |
|
this.refreshAccountsAndOrder() |
|
} |
|
}) |