✨ Weight picked shows near top of list. Also show ghosted show on click.
This commit is contained in:
parent
ed63fc1206
commit
057e728111
1 changed files with 20 additions and 2 deletions
|
|
@ -2,7 +2,7 @@
|
||||||
// ==UserScript==
|
// ==UserScript==
|
||||||
// @name Trakt Show Picker
|
// @name Trakt Show Picker
|
||||||
// @namespace danielrayjones
|
// @namespace danielrayjones
|
||||||
// @version 0.0.5
|
// @version 0.0.6
|
||||||
// @description Pick a show from progress page
|
// @description Pick a show from progress page
|
||||||
// @author Dan Jones
|
// @author Dan Jones
|
||||||
// @match https://trakt.tv/users/*/progress*
|
// @match https://trakt.tv/users/*/progress*
|
||||||
|
|
@ -21,8 +21,26 @@
|
||||||
cheat: pickShow
|
cheat: pickShow
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$('div[data-type="show"]').on('click', function () {
|
||||||
|
$(this).removeClass('sortable-ghost');
|
||||||
|
});
|
||||||
|
|
||||||
let watched_shows;
|
let watched_shows;
|
||||||
|
|
||||||
|
function getWeightedIndex(total) {
|
||||||
|
const opts = [];
|
||||||
|
for ( let idx = 0; idx < total; idx++) {
|
||||||
|
for (let idxInst = 0; idxInst < total - idx; idxInst++) {
|
||||||
|
opts.push(idx);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const totalWeights = opts.length;
|
||||||
|
const which = Math.floor(Math.random() * totalWeights);
|
||||||
|
|
||||||
|
return opts[which];
|
||||||
|
}
|
||||||
|
|
||||||
function pickShow() {
|
function pickShow() {
|
||||||
|
|
||||||
if ('compressedCache' in window) {
|
if ('compressedCache' in window) {
|
||||||
|
|
@ -35,7 +53,7 @@
|
||||||
$shows.removeClass('sortable-ghost');
|
$shows.removeClass('sortable-ghost');
|
||||||
$shows = filterShows($shows);
|
$shows = filterShows($shows);
|
||||||
|
|
||||||
let picked = Math.floor(Math.random() * $shows.length);
|
let picked = getWeightedIndex($shows.length);
|
||||||
let $picked = $shows.eq(picked);
|
let $picked = $shows.eq(picked);
|
||||||
|
|
||||||
$shows.addClass('sortable-ghost');
|
$shows.addClass('sortable-ghost');
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue