|
7 | 7 | // @license GPL-3.0 License |
8 | 8 | // @tag kevingrillet |
9 | 9 | // @tag steamhunters.com |
10 | | -// @version 1.0.2 |
| 10 | +// @version 1.0.3 |
11 | 11 |
|
12 | 12 | // @homepageURL https://github.com/kevingrillet/Userscripts/ |
13 | 13 | // @supportURL https://github.com/kevingrillet/Userscripts/issues |
|
16 | 16 |
|
17 | 17 | // @match https://steamhunters.com/id/*/apps/*/achievements |
18 | 18 | // @icon https://www.google.com/s2/favicons?sz=64&domain=steamhunters.com |
19 | | -// @grant none |
| 19 | +// @grant GM_getValue |
| 20 | +// @grant GM_setValue |
20 | 21 | // @run-at document-end |
21 | 22 | // ==/UserScript== |
22 | 23 |
|
23 | 24 | (function () { |
24 | 25 | 'use strict'; |
25 | 26 |
|
26 | | - let isFiltered = false; |
| 27 | + let isFiltered = GM_getValue('isFiltered', false); |
27 | 28 |
|
28 | | - function toggleVisibility() { |
29 | | - isFiltered = !isFiltered; |
| 29 | + function applyFilter() { |
30 | 30 | const button = document.getElementById('toggle-visibility-btn'); |
| 31 | + if (!button) return; |
| 32 | + |
31 | 33 | const icon = button.querySelector('i'); |
32 | 34 |
|
33 | 35 | // Update button appearance |
|
54 | 56 | }); |
55 | 57 | } |
56 | 58 |
|
57 | | - const buttonTemplate = ` |
58 | | - <button id="toggle-visibility-btn" type="button" class="btn btn-default btn-xs"> |
59 | | - <i class="fa fa-filter"></i><span> Hide Completed</span> |
60 | | - </button> |
61 | | - `.trim(); |
| 59 | + function toggleVisibility() { |
| 60 | + isFiltered = !isFiltered; |
| 61 | + GM_setValue('isFiltered', isFiltered); |
| 62 | + applyFilter(); |
| 63 | + } |
| 64 | + |
| 65 | + function initButton() { |
| 66 | + const buttonTemplate = ` |
| 67 | + <button id="toggle-visibility-btn" type="button" class="btn btn-default btn-xs"> |
| 68 | + <i class="fa fa-filter"></i><span> Hide Completed</span> |
| 69 | + </button> |
| 70 | + `.trim(); |
| 71 | + |
| 72 | + const spanContainer = document.querySelector('span.pull-right'); |
| 73 | + if (spanContainer && !document.getElementById('toggle-visibility-btn')) { |
| 74 | + spanContainer.insertAdjacentHTML('beforeend', buttonTemplate); |
| 75 | + document.getElementById('toggle-visibility-btn').addEventListener('click', toggleVisibility); |
| 76 | + applyFilter(); |
| 77 | + } |
| 78 | + } |
| 79 | + |
| 80 | + // Observer for dynamic content |
| 81 | + const observer = new MutationObserver((mutations) => { |
| 82 | + for (const mutation of mutations) { |
| 83 | + if (mutation.type === 'childList' && mutation.addedNodes.length > 0) { |
| 84 | + initButton(); |
| 85 | + applyFilter(); |
| 86 | + } |
| 87 | + } |
| 88 | + }); |
62 | 89 |
|
63 | | - const spanContainer = document.querySelector('span.pull-right'); |
64 | | - if (spanContainer) { |
65 | | - spanContainer.insertAdjacentHTML('beforeend', buttonTemplate); |
66 | | - document.getElementById('toggle-visibility-btn').addEventListener('click', toggleVisibility); |
67 | | - } else { |
68 | | - console.error('Unable to find <span class="pull-right">'); |
| 90 | + // Start observing |
| 91 | + const targetNode = document.querySelector('.achievements'); |
| 92 | + if (targetNode) { |
| 93 | + observer.observe(targetNode, { childList: true, subtree: true }); |
69 | 94 | } |
| 95 | + |
| 96 | + // Initial setup |
| 97 | + initButton(); |
| 98 | + applyFilter(); |
70 | 99 | })(); |
0 commit comments