|
1 | 1 | // ==UserScript== |
2 | 2 | // @name Trakt.tv | Partial VIP Unlock |
3 | | -// @description Unlocks some vip features: advanced filters, filter-by-terms, "more" buttons on dashboard, rewatching, bulk list management, Turbo page nav and more. |
4 | | -// @version 1.1.1 |
| 3 | +// @description Unlocks some vip features: advanced filters, filter-by-terms, "more" buttons on dashboard, rewatching, bulk list management, faster page navigation and more. Also hides some vip buttons/banners. |
| 4 | +// @version 1.1.2 |
5 | 5 | // @namespace x70tru7b |
6 | 6 | // @icon data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiPz4KPHN2ZyBpZD0iTGF5ZXJfMiIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiB4bWxuczp4bGluaz0iaHR0cDovL3d3dy53My5vcmcvMTk5OS94bGluayIgdmlld0JveD0iMCAwIDQ4IDQ4Ij4KICA8ZGVmcz4KICAgIDxzdHlsZT4KICAgICAgLmNscy0xIHsKICAgICAgICBmaWxsOiB1cmwoI3JhZGlhbC1ncmFkaWVudCk7CiAgICAgIH0KCiAgICAgIC5jbHMtMiB7CiAgICAgICAgZmlsbDogI2ZmZjsKICAgICAgfQogICAgPC9zdHlsZT4KICAgIDxyYWRpYWxHcmFkaWVudCBpZD0icmFkaWFsLWdyYWRpZW50IiBjeD0iNDguNDYiIGN5PSItLjk1IiBmeD0iNDguNDYiIGZ5PSItLjk1IiByPSI2NC44NCIgZ3JhZGllbnRVbml0cz0idXNlclNwYWNlT25Vc2UiPgogICAgICA8c3RvcCBvZmZzZXQ9IjAiIHN0b3AtY29sb3I9IiM5ZjQyYzYiLz4KICAgICAgPHN0b3Agb2Zmc2V0PSIuMjciIHN0b3AtY29sb3I9IiNhMDQxYzMiLz4KICAgICAgPHN0b3Agb2Zmc2V0PSIuNDIiIHN0b3AtY29sb3I9IiNhNDNlYmIiLz4KICAgICAgPHN0b3Agb2Zmc2V0PSIuNTMiIHN0b3AtY29sb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jguMDEsMzIuMzdsMS40Ny0xLjQ2LTIuMTYtMi4xNiwyMC4zMi0yMC4zMmMtLjE5LS43NS0uNDYtMS40Ni0uNzktMi4xNGwtMjIuNDYsMjIuNDYsMy42MiwzLjYyWk0xMi45MiwxOC42N2wtMS40NiwxLjQ2LDE0LjQsMTQuNCwxLjQ2LTEuNDctNC4zMi00LjMxTDQ2LjM1LDUuNGMtLjM2LS42LS43OC0xLjE2LTEuMjUtMS42OGwtMjMuNTYsMjMuNTYtOC42Mi04LjYxWk00Ny44Nyw5LjU4bC0xOS4xNywxOS4xNywxLjQ3LDEuNDYsMTcuODMtMTcuODN2LTEuMTJjMC0uNTctLjA0LTEuMTQtLjEzLTEuNjhaTTI1LjE2LDIyLjI3bC03LjkyLTcuOTItMS40NywxLjQ3LDcuOTIsNy45MiwxLjQ3LTEuNDdaTTQxLjMyLDM1LjEyYzAsMy40Mi0yLjc4LDYuMi02LjIsNi4ySDEyLjg4Yy0zLjQyLDAtNi4yLTIuNzgtNi4yLTYuMlYxMi44OGMwLTMuNDIsMi43OC02LjIxLDYuMi02LjIxaDIwLjc4di0yLjA3SDEyLjg4Yy00LjU2LDAtOC4yOCwzLjcxLTguMjgsOC4yOHYyMi4yNGMwLDQuNTYsMy43MSw4LjI4LDguMjgsOC4yOGgyMi4yNGM0LjU2LDAsOC4yOC0zLjcxLDguMjgtOC4yOHYtMy41MWgtMi4wN3YzLjUxWiIvPjwhLS0gNDVkMjM4NWQzYWFjYmI1OTMyNmEzODYxNDljNWE4NzggLS0+CiAgICAgIDwvZz4KICAgIDwvZz4KICA8L2c+Cjwvc3ZnPg== |
7 | 7 | // @match https://trakt.tv/* |
8 | | -// @run-at document-body |
| 8 | +// @run-at document-start |
9 | 9 | // @grant unsafeWindow |
10 | 10 | // @grant GM_info |
| 11 | +// @grant GM_addStyle |
11 | 12 | // ==/UserScript== |
12 | 13 |
|
13 | 14 | /* README |
|
18 | 19 | - watch-now modal country selection |
19 | 20 | - bulk list copy and move *(note: item selection is filter based)* |
20 | 21 | - all vip settings from /settings page (calendar autoscroll + limit dashboard "up next" episodes to watch-now favorites + only show watch-now icon if title is available on favorites + rewatching settings) |
21 | | -- faster page navigation with Hotwire's Turbo (allows for partial page updates instead of full page reloads when navigating) *(note: might break userscripts from other devs that didn't account for this)* |
| 22 | +- ~2x faster page navigation with Hotwire's Turbo (allows for partial page updates instead of full page reloads when navigating, might break userscripts from other devs who didn't account for this) |
22 | 23 |
|
23 | 24 | ### Partial Unlock |
24 | 25 | - custom calendars (get generated and work, but are not listed in sidebar (can't be deleted either), so you have to save the url of the custom calendar or "regenerate" it via /lists) |
25 | 26 | - advanced filters (no saved filters) |
26 | | -- ical/atom feeds + csv exports (still don't work for a few endpoints e.g. liked comments) |
| 27 | +- ~~ical/atom feeds + csv exports~~ [How anyone can create data exports of arbitrary private user accounts](https://github.com/trakt/trakt-api/issues/636) |
27 | 28 | */ |
28 | 29 |
|
29 | 30 |
|
30 | 31 | 'use strict'; |
31 | 32 |
|
32 | | -const $ = unsafeWindow.jQuery, |
33 | | - compressedCache = unsafeWindow.compressedCache, |
34 | | - token = atob(GM_info.script.icon.split(',')[1]).match(/<!-- (.*?) -->/)[1]; |
35 | | -if (!$ || !compressedCache || !token) return; |
| 33 | +let $, compressedCache; |
| 34 | +// const token = atob(GM_info.script.icon.split(',')[1]).match(/<!-- (.*?) -->/)[1]; |
36 | 35 |
|
37 | 36 |
|
38 | | -const patchUserSettings = () => { |
39 | | - const userSettings = compressedCache.get('settings'); |
40 | | - if (userSettings && (!userSettings.user.vip || userSettings.account.token !== token)) { |
41 | | - userSettings.user.vip = true; |
42 | | - userSettings.account.token = token; |
43 | | - compressedCache.set('settings', userSettings); |
44 | | - if (unsafeWindow.userSettings) unsafeWindow.userSettings = userSettings; |
45 | | - } |
46 | | -}; |
47 | | -patchUserSettings(); |
| 37 | +addStyles(); |
48 | 38 |
|
49 | | -$(document).on('ajaxSuccess', (_evt, _xhr, opt) => { |
50 | | - if (opt.url.endsWith('/settings.json')) patchUserSettings(); |
51 | | -}); |
| 39 | +document.addEventListener('turbo:load', () => { |
| 40 | + $ ??= unsafeWindow.jQuery; |
| 41 | + compressedCache ??= unsafeWindow.compressedCache; |
| 42 | + if (!$ || !compressedCache) return; // || !token) return; |
52 | 43 |
|
| 44 | + patchUserSettings(); |
53 | 45 |
|
54 | | -document.addEventListener('turbo:load', () => { |
55 | | - $('body').removeAttr('data-turbo'); |
| 46 | + $(document).off('ajaxSuccess.userscript38793').on('ajaxSuccess.userscript38793', (_evt, _xhr, opt) => { |
| 47 | + if (opt.url.endsWith('/settings.json')) patchUserSettings(); |
| 48 | + |
| 49 | + // if (/\/dashboard\/(on_deck|recently_watched)$/.test(opt.url)) { |
| 50 | + // $('.feed-icon.csv[href="/vip/csv"]').attr('href', function() { |
| 51 | + // return $(this).prev().attr('data-path') + '.csv?' + ['slurm=' + token, $(this).prev().attr('data-query')].join('&'); |
| 52 | + // }); |
| 53 | + // } |
| 54 | + }); |
56 | 55 |
|
57 | | - $('.feed-icon.csv').attr('href', location.origin + location.pathname + '.csv?slurm=' + token + location.search.replace('?', '&')); |
| 56 | + // $('body:not(.dashboard) .feed-icon.csv').attr('href', location.pathname + '.csv?slurm=' + token + location.search.replace('?', '&')); |
| 57 | + |
| 58 | + $('body').removeAttr('data-turbo'); |
58 | 59 |
|
59 | 60 | $('.frame-wrapper .sidenav.advanced-filters .buttons') |
60 | 61 | .addClass('vip') |
61 | 62 | .find('.btn.vip') |
62 | | - .text('').removeClass('vip').removeAttr('href') |
63 | | - .addClass('disabled disabled-init').attr('id', 'filter-apply').attr('data-apply-text', 'Apply Filters') |
64 | | - .before('<a class="btn btn-close-2024" id="filter-close" style="display: inline-block !important; visibility: visible !important;">Close</a>') |
65 | | - .append('<span class="text">Configure Filters</span><span class="icon fa-solid fa-check"></span>'); |
| 63 | + .text('').removeClass('vip').removeAttr('href') |
| 64 | + .addClass('disabled disabled-init').attr('id', 'filter-apply').attr('data-apply-text', 'Apply Filters') |
| 65 | + .before('<a class="btn btn-close-2024" id="filter-close" style="display: inline-block !important; visibility: visible !important;">Close</a>') |
| 66 | + .append('<span class="text">Configure Filters</span><span class="icon fa-solid fa-check"></span>'); |
66 | 67 | }, { capture: true }); |
| 68 | + |
| 69 | + |
| 70 | +function patchUserSettings() { |
| 71 | + const userSettings = compressedCache.get('settings'); |
| 72 | + |
| 73 | + if (userSettings && (!userSettings.user.vip)) { // || userSettings.account.token !== token)) { |
| 74 | + userSettings.user.vip = true; |
| 75 | + // userSettings.account.token = token; |
| 76 | + compressedCache.set('settings', userSettings); |
| 77 | + if (unsafeWindow.userSettings) unsafeWindow.userSettings = userSettings; |
| 78 | + } |
| 79 | +} |
| 80 | + |
| 81 | + |
| 82 | +function addStyles() { |
| 83 | + GM_addStyle(` |
| 84 | + #top-nav .btn-vip, |
| 85 | + .dropdown-menu.for-sortable > li > a.vip-only, |
| 86 | + .alert-vip-required { |
| 87 | + display: none !important; |
| 88 | + } |
| 89 | + `); |
| 90 | +} |
0 commit comments