Code Snippet Formatter

Code Snippet Formatter

Easily format your code for the snippet widget - no HTML escaping headaches!

Step 1: Enter Your Details

How to Use:

  1. Enter your title and description above
  2. Paste your code exactly as-is (no formatting needed)
  3. Click "Generate Widget Code"
  4. Copy the generated HTML and paste it into your website
  5. That's it! Your code snippet widget is ready
Code Snippet Widget

THIS IS A TEST

DESCRIPTION

function doGet() {
  try {
    var sheet = SpreadsheetApp.openById('1OmL4RVv493CkcHzhVGjvBtF-rDVMUFYEUYSxe_znzV8').getSheetByName('Sheet1');
    var data = sheet.getDataRange().getValues();

    var headers = data[0];
    var rows = data.slice(1);
    var notifications = [];

    for (var i = 0; i < rows.length; i++) {
      // Check if entire row is empty
      var isEmpty = rows[i].every(cell => cell === '' || cell === null);
      if (isEmpty) continue;

      var obj = {};
      for (var j = 0; j < headers.length; j++) {
        obj[headers[j]] = rows[i][j];
      }

      notifications.push(obj);
    }

    // Shuffle
    for (var i = notifications.length - 1; i > 0; i--) {
      var j = Math.floor(Math.random() * (i + 1));
      [notifications[i], notifications[j]] = [notifications[j], notifications[i]];
    }

    return ContentService
      .createTextOutput(JSON.stringify({
        notifications: notifications,
        count: notifications.length,
        status: 'success',
        timestamp: new Date().toISOString()
      }))
      .setMimeType(ContentService.MimeType.JSON);
      
  } catch (err) {
    return ContentService
      .createTextOutput(JSON.stringify({
        notifications: [],
        count: 0,
        error: err.toString(),
        status: 'error'
      }))
      .setMimeType(ContentService.MimeType.JSON);
  }
}