2023-05-15 19:05:38 +00:00
|
|
|
/**
|
|
|
|
* @param {HTMLElement} watchIcon
|
|
|
|
* @param {boolean} isWatched
|
|
|
|
* @param {string} expiry
|
|
|
|
*/
|
|
|
|
const updateWatchIcon = ( watchIcon, isWatched, expiry ) => {
|
|
|
|
watchIcon.classList.remove(
|
|
|
|
// Vector attaches two icon classes to the element.
|
|
|
|
// Remove the mw-ui-icon one rather than managing both.
|
|
|
|
'mw-ui-icon-star',
|
|
|
|
'mw-ui-icon-unStar',
|
|
|
|
'mw-ui-icon-wikimedia-unStar',
|
|
|
|
'mw-ui-icon-wikimedia-star',
|
|
|
|
'mw-ui-icon-wikimedia-halfStar'
|
|
|
|
);
|
|
|
|
|
|
|
|
if ( isWatched ) {
|
2024-02-02 11:10:31 +00:00
|
|
|
if ( mw.util.isInfinity( expiry ) ) {
|
2023-05-15 19:05:38 +00:00
|
|
|
watchIcon.classList.add( 'mw-ui-icon-wikimedia-unStar' );
|
|
|
|
} else {
|
|
|
|
watchIcon.classList.add( 'mw-ui-icon-wikimedia-halfStar' );
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
watchIcon.classList.add( 'mw-ui-icon-wikimedia-star' );
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
const init = () => {
|
2022-09-02 14:57:31 +00:00
|
|
|
mw.hook( 'wikipage.watchlistChange' ).add(
|
2024-06-06 15:22:05 +00:00
|
|
|
( /** @type {boolean} */ isWatched, /** @type {string} */ expiry ) => {
|
2023-06-12 22:22:33 +00:00
|
|
|
const watchIcons = document.querySelectorAll( '.mw-watchlink .vector-icon' );
|
2023-05-15 19:05:38 +00:00
|
|
|
if ( !watchIcons ) {
|
2022-09-02 14:57:31 +00:00
|
|
|
return;
|
|
|
|
}
|
2023-05-15 19:05:38 +00:00
|
|
|
Array.from( watchIcons ).forEach( ( watchIcon ) => {
|
|
|
|
updateWatchIcon( /** @type {HTMLElement} */ ( watchIcon ), isWatched, expiry );
|
|
|
|
} );
|
2022-09-02 14:57:31 +00:00
|
|
|
}
|
|
|
|
);
|
|
|
|
};
|
2023-05-15 19:05:38 +00:00
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
updateWatchIcon,
|
|
|
|
init
|
|
|
|
};
|