hi all i'm using google sheets
for my song requests
but at the moment i have a pop up box
stating Requested: Artist: | Song: then whatever song is in my playlist
but i would the popup box to have a dedication box within in and the persons name
with the words succesfully requested?
here's the script
could anyone please help me
for my song requests
but at the moment i have a pop up box
stating Requested: Artist: | Song: then whatever song is in my playlist
but i would the popup box to have a dedication box within in and the persons name
with the words succesfully requested?
here's the script
Code:
<!DOCTYPE html>
<html>
<head>
<!--Import Google Icon Font-->
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<!--Import materialize.css-->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/css/materialize.min.css">
<!--Let browser know website is optimized for mobile-->
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
</head>
<body>
<div class="container">
<div class="row">
<div class="col s12 m6">
<div class="card blue-grey darken-1">
<div class="card-content white-text">
<span class="card-title" id="title"></span>
<p id="song"></p>
</div>
<div class="card-action">
<button class="btn waves-effect waves-light" type="button" value="run" id="btn" onClick="requestSong()">Request
<i class="material-icons right">music_note</i>
</button>
<p id="check"></p>
</div>
</div>
</div>
</div>
</div>
<!--JavaScript at end of body for optimized loading-->
<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/js/materialize.min.js"></script>
<script>
window.setInterval(function() {
google.script.run.withSuccessHandler(getCrrentRowData).getCrrentRowData();
}, 700);
var artist = document.getElementById("title")
var song = document.getElementById("song")
var artistValue;
var songValue;
function requestSong(){
console.log('Pressed button')
const data = {
artist: artistValue,
song: songValue
}
google.script.run.sendEmail(data)
}
function getCrrentRowData() {
google.script.run
.withSuccessHandler(function (result) {
artist.innerText = result.artist;
song.innerText = result.song;
artistValue = result.artist;
songValue = result.song;
}).getCrrentRowData();
}
</script>
</body>
</html>
JavaScript:
const playlistSheet = 'playlist'
const email = '[email protected]'
function showSidebar(){
const ui = SpreadsheetApp.getUi()
const html = HtmlService.createHtmlOutputFromFile("index.html")
html.setTitle("Request song")
ui.showSidebar(html)
}
function onOpen(e) {
SpreadsheetApp.getUi().createMenu('Sidebar')
.addItem('Open', 'showSidebar')
.addToUi();
}
function sendEmail(obj){
const {artist, song} = obj
console.log(obj)
const time = Utilities.formatDate(new Date(), Session.getScriptTimeZone(), "HH:MM:SS")
const body = `New request:\n\nArtist: ${artist}\nSong: ${song}`
GmailApp.sendEmail(email, `New request: ${time}`, body)
SpreadsheetApp.getUi().alert(`Requested: Artist: ${artist} | Song: ${song}`)
}
function getCrrentRowData(){
const ss = SpreadsheetApp.getActiveSpreadsheet()
const activeSheet = ss.getActiveSheet()
if(activeSheet.getName() != playlistSheet) { return }
const row = activeSheet.getActiveRange().getRow()
const [ artist, song ] = activeSheet.getRange(row,1,1,2).getValues().flat()
return {artist, song}
}
function sleep(){
Utilities.sleep(1500)
return;
}
could anyone please help me