Created
May 14, 2025 14:48
-
-
Save htlin222/9861e4747313657598535f76ef4cb09b to your computer and use it in GitHub Desktop.
Google Slides Custom Progress Bar Generator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function onOpen() { | |
const ui = SlidesApp.getUi(); | |
ui.createMenu('自定功能') | |
.addItem('⏳ Reload ProgressBars', 'updateProgressBars') | |
.addToUi(); | |
} | |
function updateProgressBars() { | |
const presentation = SlidesApp.getActivePresentation(); | |
const slides = presentation.getSlides(); | |
const totalSlides = slides.length; | |
const maxWidth = 720; | |
const yPosition = 402; | |
const height = 3; | |
for (let i = 1; i < totalSlides; i++) { // Start from 2nd slide | |
const slide = slides[i]; | |
// 1. Remove old progress bar if exists | |
const shapes = slide.getShapes(); | |
for (let shape of shapes) { | |
if (shape.getTitle && shape.getTitle() === 'PROGRESS') { | |
shape.remove(); | |
} | |
} | |
// 2. Calculate new width | |
const progressRatio = i / ( totalSlides - 1); | |
const barWidth = maxWidth * progressRatio; | |
// 3. Insert new progress bar | |
const bar = slide.insertShape(SlidesApp.ShapeType.RECTANGLE, 0, yPosition, barWidth, height); | |
bar.getFill().setSolidFill('#000000'); | |
bar.getBorder().setTransparent(); | |
// 4. Tag the shape for future identification | |
bar.setTitle('PROGRESS'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Brilliant work! This is a fantastic addition to the already excellent "NEJM模版2020新版" — thank you so much for sharing it.
I’ve put together a modified version that omits skipped slides in the progress bar and adds a slide number feature as well.
P.S. The Apps Script is almost entirely "vibe-coded," so the style might not be the cleanest 😄