|
7 | 7 | // @license GPL-3.0 License |
8 | 8 | // @tag kevingrillet |
9 | 9 | // @tag steamhunters.com |
10 | | -// @version 1.0.1 |
| 10 | +// @version 1.0.2 |
11 | 11 |
|
12 | 12 | // @homepageURL https://github.com/kevingrillet/Userscripts/ |
13 | 13 | // @supportURL https://github.com/kevingrillet/Userscripts/issues |
|
23 | 23 | (function () { |
24 | 24 | 'use strict'; |
25 | 25 |
|
| 26 | + let isFiltered = false; |
| 27 | + |
| 28 | + function toggleVisibility() { |
| 29 | + isFiltered = !isFiltered; |
| 30 | + const button = document.getElementById('toggle-visibility-btn'); |
| 31 | + const icon = button.querySelector('i'); |
| 32 | + |
| 33 | + // Update button appearance |
| 34 | + icon.className = isFiltered ? 'fa fa-eye-slash' : 'fa fa-filter'; |
| 35 | + button.querySelector('span').textContent = isFiltered ? ' Show Completed' : ' Hide Completed'; |
| 36 | + |
| 37 | + // Toggle visibility of completed updates (100%) |
| 38 | + const updates = document.querySelectorAll('li[data-flash^="updates/"]'); |
| 39 | + updates.forEach((update) => { |
| 40 | + const contentDiv = update.querySelector('a.media.group.collapse-rotate.rotate-90 > div.media-body.media-middle > div'); |
| 41 | + if (contentDiv) { |
| 42 | + const text = contentDiv.textContent || ''; |
| 43 | + const isCompleted = text.includes('(100 %)'); |
| 44 | + if (isCompleted) { |
| 45 | + update.style.display = isFiltered ? 'none' : ''; |
| 46 | + } |
| 47 | + } |
| 48 | + }); |
| 49 | + |
| 50 | + // Toggle visibility of unlocked achievements |
| 51 | + const unlockedItems = document.querySelectorAll('li.unlocked.check-item'); |
| 52 | + unlockedItems.forEach((item) => { |
| 53 | + item.style.display = isFiltered ? 'none' : ''; |
| 54 | + }); |
| 55 | + } |
| 56 | + |
26 | 57 | const buttonTemplate = ` |
27 | | - <button type="button" class="btn btn-default btn-xs"> |
28 | | - <i class="fa fa-filter"></i> Toggle Visibility |
| 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> |
29 | 60 | </button> |
30 | 61 | `.trim(); |
31 | 62 |
|
32 | 63 | const spanContainer = document.querySelector('span.pull-right'); |
33 | 64 | if (spanContainer) { |
34 | 65 | spanContainer.insertAdjacentHTML('beforeend', buttonTemplate); |
35 | | - |
36 | | - // Get the button reference and add event listener |
37 | | - const toggleButton = spanContainer.querySelector('button:last-child'); |
38 | | - toggleButton.addEventListener('click', () => { |
39 | | - // Toggle visibility of completed updates (100%) |
40 | | - const updates = document.querySelectorAll('li[data-flash^="updates/"]'); |
41 | | - updates.forEach((update) => { |
42 | | - const contentDiv = update.querySelector('a.media.group.collapse-rotate.rotate-90 > div.media-body.media-middle > div'); |
43 | | - if (contentDiv) { |
44 | | - const text = contentDiv.textContent || ''; |
45 | | - const isCompleted = text.includes('(100 %)'); |
46 | | - if (isCompleted) { |
47 | | - update.style.display = update.style.display === 'none' ? '' : 'none'; |
48 | | - } |
49 | | - } |
50 | | - }); |
51 | | - |
52 | | - // Toggle visibility of unlocked achievements |
53 | | - const unlockedItems = document.querySelectorAll('li.unlocked.check-item'); |
54 | | - unlockedItems.forEach((item) => { |
55 | | - item.style.display = item.style.display === 'none' ? '' : 'none'; |
56 | | - }); |
57 | | - }); |
| 66 | + document.getElementById('toggle-visibility-btn').addEventListener('click', toggleVisibility); |
58 | 67 | } else { |
59 | 68 | console.error('Unable to find <span class="pull-right">'); |
60 | 69 | } |
|
0 commit comments