Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Main page
Recent changes
Random page
freem
Search
Search
Appearance
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
Openai/688406d1-62a4-8012-949f-ac50d0247df3
(section)
Add languages
Page
Discussion
English
Read
Edit
Edit source
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
Edit source
View history
General
What links here
Related changes
Special pages
Page information
Appearance
move to sidebar
hide
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==== | | | | ==== | --- | --- | --- | | | | | | | | | | | | | | | | | | | | | | | | | | | | | ==== <syntaxhighlight lang="javascript">/** ==== * ========= CONFIG ========= */ const PUBLISHED_URL = '<PUBLISHED_SHEET_WIDGET_URL>'; // e.g. https://docs.google.com/… const FOLDER_ID = '<TARGET_DRIVE_FOLDER_ID>'; // folder where PNG lives const PNG_NAME = 'sheet_widget.png'; // keep constant for a stable link const PROP_KEY = 'PNG_FILE_ID'; // ScriptProperty key const SCREENSHOT_API = 'https://image.thum.io/get/'; // swap for ScreenshotAPI if preferred const SCREENSHOT_API_KEY = '<YOUR_SCREENSHOT_SERVICE_KEY>'; // leave blank if not required /** * Add a cache‑buster so the service re‑captures every call. * Modify width/crop params to suit your Cozyla display. */ function buildScreenshotUrl(url) { // Thum.io example: …/width/1024/crop/700/noanimate/<ENCODED_URL>?auth=<KEY> const width = 1024; // px const cropH = 700; // px const encoded = encodeURIComponent(url); const auth = SCREENSHOT_API_KEY ? <code>?auth=${SCREENSHOT_API_KEY}</code> : ''; const cb = auth ? '&' : '?'; // chain correctly return <code>${SCREENSHOT_API}width/${width}/crop/${cropH}/full/${encoded}${auth}${cb}cb=${Date.now()}</code>; } /** * Main entry point – grabs fresh screenshot & stores/updates PNG in Drive. */ function snapshotSheetToPng() { // 1) Build screenshot URL const shotUrl = buildScreenshotUrl(PUBLISHED_URL); // 2) Fetch the PNG blob const response = UrlFetchApp.fetch(shotUrl, { muteHttpExceptions: true, followRedirects: true }); if (response.getResponseCode() !== 200) { throw new Error(<code>Screenshot capture failed ‑‑ HTTP ${response.getResponseCode()}</code>); } const pngBlob = response.getBlob().setName(PNG_NAME); // 3) Ensure target Drive folder exists const folder = DriveApp.getFolderById(FOLDER_ID); // 4) Check if we’ve already saved a file for this widget const storedId = PropertiesService.getScriptProperties().getProperty(PROP_KEY); let file; if (storedId) { try { file = DriveApp.getFileById(storedId); file.setContent(pngBlob.getBytes()); // overwrite existing bytes } catch (e) { // File was deleted; fall through to create‑new } } if (!file) { file = folder.createFile(pngBlob); PropertiesService.getScriptProperties().setProperty(PROP_KEY, file.getId()); file.setSharing(DriveApp.Access.ANYONE_WITH_LINK, DriveApp.Permission.VIEW); } Logger.log(<code>Updated PNG → ${file.getUrl()}</code>); } </syntaxhighlight> ===== | | | ===== | --- | --- | | | | | | | | | | | | |
Summary:
Please note that all contributions to freem are considered to be released under the Creative Commons Attribution-ShareAlike 4.0 (see
Freem:Copyrights
for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource.
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)