From 057e728111658cabfeb23bd6ac583b365e120fab Mon Sep 17 00:00:00 2001 From: Dan Jones Date: Wed, 22 Jul 2020 13:49:36 -0500 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Weight=20picked=20shows=20near=20to?= =?UTF-8?q?p=20of=20list.=20Also=20show=20ghosted=20show=20on=20click.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- trakt.pick-show.user.js | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/trakt.pick-show.user.js b/trakt.pick-show.user.js index e3fe44b..2a8ae13 100644 --- a/trakt.pick-show.user.js +++ b/trakt.pick-show.user.js @@ -2,7 +2,7 @@ // ==UserScript== // @name Trakt Show Picker // @namespace danielrayjones -// @version 0.0.5 +// @version 0.0.6 // @description Pick a show from progress page // @author Dan Jones // @match https://trakt.tv/users/*/progress* @@ -21,8 +21,26 @@ cheat: pickShow }); + $('div[data-type="show"]').on('click', function () { + $(this).removeClass('sortable-ghost'); + }); + 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() { if ('compressedCache' in window) { @@ -35,7 +53,7 @@ $shows.removeClass('sortable-ghost'); $shows = filterShows($shows); - let picked = Math.floor(Math.random() * $shows.length); + let picked = getWeightedIndex($shows.length); let $picked = $shows.eq(picked); $shows.addClass('sortable-ghost');