mirror of
				https://github.com/go-gitea/gitea.git
				synced 2025-10-31 21:28:11 +09:00 
			
		
		
		
	Remove jQuery .text() (#30506)
				
					
				
			Remove and forbid [.text()](https://api.jquery.com/text/). Tested some, but not all functionality, but I think these are pretty safe replacements. --------- Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
		| @@ -47,17 +47,13 @@ async function receiveUpdateCount(event) { | ||||
| } | ||||
|  | ||||
| export function initNotificationCount() { | ||||
|   const $notificationCount = $('.notification_count'); | ||||
|  | ||||
|   if (!$notificationCount.length) { | ||||
|     return; | ||||
|   } | ||||
|   if (!document.querySelector('.notification_count')) return; | ||||
|  | ||||
|   let usingPeriodicPoller = false; | ||||
|   const startPeriodicPoller = (timeout, lastCount) => { | ||||
|     if (timeout <= 0 || !Number.isFinite(timeout)) return; | ||||
|     usingPeriodicPoller = true; | ||||
|     lastCount = lastCount ?? $notificationCount.text(); | ||||
|     lastCount = lastCount ?? getCurrentCount(); | ||||
|     setTimeout(async () => { | ||||
|       await updateNotificationCountWithCallback(startPeriodicPoller, timeout, lastCount); | ||||
|     }, timeout); | ||||
| @@ -121,8 +117,12 @@ export function initNotificationCount() { | ||||
|   startPeriodicPoller(notificationSettings.MinTimeout); | ||||
| } | ||||
|  | ||||
| function getCurrentCount() { | ||||
|   return document.querySelector('.notification_count').textContent; | ||||
| } | ||||
|  | ||||
| async function updateNotificationCountWithCallback(callback, timeout, lastCount) { | ||||
|   const currentCount = $('.notification_count').text(); | ||||
|   const currentCount = getCurrentCount(); | ||||
|   if (lastCount !== currentCount) { | ||||
|     callback(notificationSettings.MinTimeout, currentCount); | ||||
|     return; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user