MCPcopy
hub / github.com/ChinaGodMan/UserScripts / updateGrid

Function updateGrid

youtube-dynamic-grid/youtube-dynamic-grid.user.js:449–478  ·  view source on GitHub ↗

* Updates the grid's elements-per-row attribute and CSS styles.

()

Source from the content-addressed store, hash-verified

447 * Updates the grid's elements-per-row attribute and CSS styles.
448 */
449 updateGrid() {
450 if (this.updateTimeout) clearTimeout(this.updateTimeout)
451 this.updateTimeout = setTimeout(() => {
452 try {
453 const grid = document.querySelector(
454 'ytd-rich-grid-renderer:not([hidden])'
455 )
456 if (!grid) {
457 logger('No visible grid found')
458 return
459 }
460 const itemsPerRow = this.calculateItemsPerRow()
461 const currentItems = getComputedStyle(grid)
462 .getPropertyValue('--ytd-rich-grid-items-per-row')
463 .trim()
464 const currentAttr =
465 grid.getAttribute('elements-per-row') || 'unknown'
466 if (
467 currentItems !== String(itemsPerRow) ||
468 currentAttr !== String(itemsPerRow)
469 ) {
470 grid.setAttribute('elements-per-row', itemsPerRow)
471 this.updateCSS(itemsPerRow)
472 logger(`Updated grid to ${itemsPerRow} items`)
473 }
474 } catch (error) {
475 logger(`Failed to update grid: ${error.message}`, 'error')
476 }
477 }, CONFIG.UPDATE_DELAY)
478 },
479
480 /**
481 * Injects or updates the CSS style element for the grid.

Callers

nothing calls this directly

Calls 1

loggerFunction · 0.85

Tested by

no test coverage detected