Last active
August 20, 2024 10:50
-
-
Save ahbanavi/7f32831b94362ce4151991503db1e310 to your computer and use it in GitHub Desktop.
This script updates Google Slides footers to display slide numbers and non-skipped slide counts in Persian numerals.
This file contains 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 updateSlideFootersWithNotSkippedCount() { | |
// Get the active presentation | |
var presentation = SlidesApp.getActivePresentation(); | |
// Get all the slides in the presentation | |
var slides = presentation.getSlides(); | |
// Initialize a counter for not skipped slides | |
var notSkippedCount = 0; | |
// First pass: Count the non-skipped slides | |
for (var i = 0; i < slides.length; i++) { | |
var slide = slides[i]; | |
if (!slide.isSkipped()) { | |
notSkippedCount++; | |
} | |
} | |
// Second pass: Update each slide's footer with the non-skipped count | |
for (var i = 0; i < slides.length; i++) { | |
var slide = slides[i]; | |
// Assuming there is a placeholder for the footer | |
var placeholders = slide.getPlaceholder(SlidesApp.PlaceholderType.SLIDE_NUMBER); | |
// Convert numbers to Persian | |
var persianSlideNumber = toPersianNumber(i + 1); | |
var persianNotSkippedCount = toPersianNumber(notSkippedCount); | |
if (placeholders) { | |
var textRange = placeholders.asShape().getText(); | |
textRange.setText(`${persianSlideNumber}/${persianNotSkippedCount}`).getParagraphStyle().setTextDirection(SlidesApp.TextDirection.RIGHT_TO_LEFT);; | |
} | |
} | |
} | |
function onOpen() { | |
// Add a custom menu to the Google Slides UI | |
SlidesApp.getUi() | |
.createMenu('Custom Tools') | |
.addItem('Update Footers with Not Skipped Count', 'updateSlideFootersWithNotSkippedCount') | |
.addToUi(); | |
} | |
function toPersianNumber(number) { | |
var persianDigits = ['۰', '۱', '۲', '۳', '۴', '۵', '۶', '۷', '۸', '۹']; | |
return number.toString().replace(/\d/g, function(digit) { | |
return persianDigits[parseInt(digit)]; | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment