|
7 | 7 | // @license GPL-3.0 License |
8 | 8 | // @tag kevingrillet |
9 | 9 | // @tag steamhunters.com |
10 | | -// @version 1.0.3 |
| 10 | +// @version 1.0.4 |
11 | 11 |
|
12 | 12 | // @homepageURL https://github.com/kevingrillet/Userscripts/ |
13 | 13 | // @supportURL https://github.com/kevingrillet/Userscripts/issues |
14 | 14 | // @downloadURL https://raw.githubusercontent.com/kevingrillet/Userscripts/main/user.js/[SteamHunters]%20Tweaks.user.js |
15 | 15 | // @updateURL https://raw.githubusercontent.com/kevingrillet/Userscripts/main/user.js/[SteamHunters]%20Tweaks.user.js |
16 | 16 |
|
| 17 | +// @match https://steamhunters.com/id/*/games* |
17 | 18 | // @match https://steamhunters.com/id/*/apps/*/achievements |
18 | 19 | // @icon https://www.google.com/s2/favicons?sz=64&domain=steamhunters.com |
19 | 20 | // @grant GM_getValue |
|
77 | 78 | } |
78 | 79 | } |
79 | 80 |
|
| 81 | + function addDateInfo() { |
| 82 | + const breadcrumb = document.querySelector('.breadcrumb'); |
| 83 | + if (breadcrumb && !document.getElementById('date-info')) { |
| 84 | + const date = new Date(); |
| 85 | + const year = date.getFullYear(); |
| 86 | + const week = getWeekNumber(date); |
| 87 | + |
| 88 | + const dateInfoTemplate = ` |
| 89 | + <li id="date-info" class="pull-right" style="margin-left: auto;"> |
| 90 | + <span class="text-muted">${year} - W${week}</span> |
| 91 | + </li> |
| 92 | + `.trim(); |
| 93 | + |
| 94 | + breadcrumb.insertAdjacentHTML('beforeend', dateInfoTemplate); |
| 95 | + } |
| 96 | + } |
| 97 | + |
| 98 | + function getWeekNumber(date) { |
| 99 | + const firstDayOfYear = new Date(date.getFullYear(), 0, 1); |
| 100 | + const daysSinceFirstDay = Math.floor((date - firstDayOfYear) / (24 * 60 * 60 * 1000)); |
| 101 | + return Math.ceil((daysSinceFirstDay + firstDayOfYear.getDay() + 1) / 7); |
| 102 | + } |
| 103 | + |
| 104 | + function isAchievementsPage() { |
| 105 | + return window.location.pathname.includes('/apps/') && window.location.pathname.includes('/achievements'); |
| 106 | + } |
| 107 | + |
80 | 108 | // Observer for dynamic content |
81 | 109 | const observer = new MutationObserver((mutations) => { |
82 | 110 | for (const mutation of mutations) { |
83 | 111 | if (mutation.type === 'childList' && mutation.addedNodes.length > 0) { |
84 | | - initButton(); |
85 | | - applyFilter(); |
| 112 | + if (isAchievementsPage()) { |
| 113 | + initButton(); |
| 114 | + applyFilter(); |
| 115 | + } |
| 116 | + addDateInfo(); |
86 | 117 | } |
87 | 118 | } |
88 | 119 | }); |
89 | 120 |
|
90 | 121 | // Start observing |
91 | | - const targetNode = document.querySelector('.achievements'); |
| 122 | + const targetNode = document.querySelector('.achievements') || document.querySelector('.breadcrumb'); |
92 | 123 | if (targetNode) { |
93 | 124 | observer.observe(targetNode, { childList: true, subtree: true }); |
94 | 125 | } |
95 | 126 |
|
96 | 127 | // Initial setup |
97 | | - initButton(); |
98 | | - applyFilter(); |
| 128 | + if (isAchievementsPage()) { |
| 129 | + initButton(); |
| 130 | + applyFilter(); |
| 131 | + } |
| 132 | + addDateInfo(); |
99 | 133 | })(); |
0 commit comments